KADATH
domain_bispheric_chi_first_nbr_unknowns.cpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "headcpp.hpp"
21 
22 #include "bispheric.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
29 
30  int res = 0 ;
31  int basep = (*so.get_base().bases_1d[2]) (0) ;
32 
33  Index pos (nbr_coefs) ;
34  do {
35  bool indic = true ;
36  switch (basep) {
37  case COS :
38  // Last odd ones
39  if ((pos(2)%2==1) && (pos(1)==nbr_coefs(1)-1))
40  indic = false ;
41  // Regularity for even ones :
42  if ((pos(2)!=0) && (pos(2)%2==0) && (pos(1)==0))
43  indic = false ;
44  break ;
45  case SIN :
46  // sin(0)
47  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
48  indic = false ;
49  // Last odd ones :
50  if ((pos(2)%2==1) && (pos(1)==nbr_coefs(1)-1))
51  indic = false ;
52  // Regularity for even ones :
53  if ((pos(2)%2==0) && (pos(1)==0))
54  indic = false ;
55  break ;
56  default :
57  cerr << "Unknown phi basis in Domain_bispheric_chi_first::nbr_unknowns_val_domain" << endl ;
58  abort() ;
59  }
60  if (indic)
61  res ++ ;
62  }
63  while (pos.inc()) ;
64 
65  return res ;
66 }
67 
68 int Domain_bispheric_chi_first::nbr_unknowns (const Tensor& tt, int dom) const {
69 
70  // Check right domain
71  assert (tt.get_space().get_domain(dom)==this) ;
72 
73  int res = 0 ;
74  int val = tt.get_valence() ;
75  switch (val) {
76  case 0 :
77  res += nbr_unknowns_val_domain (tt()(dom)) ;
78  break ;
79  case 1 : {
80  bool found = false ;
81  // Cartesian basis
82  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
83  res += nbr_unknowns_val_domain (tt(1)(dom)) ;
84  res += nbr_unknowns_val_domain (tt(2)(dom)) ;
85  res += nbr_unknowns_val_domain (tt(3)(dom)) ;
86  found = true ;
87  }
88  if (!found) {
89  cerr << "Unknown type of vector Domain_bispheric_chi_first::nbr_unknowns" << endl ;
90  abort() ;
91  }
92  }
93  break ;
94  case 2 : {
95  bool found = false ;
96  // Cartesian basis and symetric
97  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
98  res += nbr_unknowns_val_domain (tt(1,1)(dom)) ;
99  res += nbr_unknowns_val_domain (tt(1,2)(dom)) ;
100  res += nbr_unknowns_val_domain (tt(1,3)(dom)) ;
101  res += nbr_unknowns_val_domain (tt(2,2)(dom)) ;
102  res += nbr_unknowns_val_domain (tt(2,3)(dom)) ;
103  res += nbr_unknowns_val_domain (tt(3,3)(dom)) ;
104  found = true ;
105  }
106  // Cartesian basis and not symetric
107  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
108  for (int i=1 ; i<=3 ; i++)
109  for (int j=1 ; j<=3 ; j++)
110  res += nbr_unknowns_val_domain (tt(i,j)(dom)) ;
111  found = true ;
112  }
113  if (!found) {
114  cerr << "Unknown type of 2-tensor Domain_bispheric_chi_first::nbr_unknowns" << endl ;
115  abort() ;
116  }
117  }
118  break ;
119  default :
120  cerr << "Valence " << val << " not implemented in Domain_bispheric_chi_first::nbr_unknowns" << endl ;
121  break ;
122  }
123  return res ;
124 }
125 }
Bases_container bases_1d
Arrays containing the various basis of decomposition.
int get_basis(int nd) const
Read only the basis in a given domain.
Definition: base_tensor.hpp:93
int nbr_unknowns_val_domain(const Val_domain &so) const
Computes the number of true unknowns of a Val_domain.
virtual int nbr_unknowns(const Tensor &, int) const
Computes the number of true unknowns of a Tensor, in a given domain.
Dim_array nbr_coefs
Number of coefficients.
Definition: space.hpp:66
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
Tensor handling.
Definition: tensor.hpp:149
const Base_tensor & get_basis() const
Returns the vectorial basis (triad) on which the components are defined.
Definition: tensor.hpp:504
int get_n_comp() const
Returns the number of stored components.
Definition: tensor.hpp:514
int get_valence() const
Returns the valence.
Definition: tensor.hpp:509
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122