KADATH
domain_shell_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 #include "spheric.hpp"
22 #include "scalar.hpp"
23 #include "tensor_impl.hpp"
24 #include "tensor.hpp"
25 
26 namespace Kadath {
27 
28 int Domain_shell::nbr_unknowns_val_domain_mquant (const Val_domain& so, int mquant) const {
29  int res = 0 ;
30 
31  Index pos (nbr_coefs) ;
32  do {
33  bool indic = true ;
34  // Get base in theta :
35  int baset = (*so.get_base().bases_1d[1]) (0) ;
36  switch (baset) {
37  case COS_EVEN:
38  if ((pos(1)==0) && (mquant!=0))
39  indic = false ;
40  break ;
41  case COS_ODD:
42  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (mquant!=0)))
43  indic = false ;
44  break ;
45  case SIN_EVEN:
46  if (((pos(1)==1) && (mquant>1)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
47  indic = false ;
48  break ;
49  case SIN_ODD:
50  if (((pos(1)==0) && (mquant>1)) || (pos(1)==nbr_coefs(1)-1))
51  indic = false ;
52  break ;
53  default:
54  cerr << "Unknow theta basis in Domain_shell::nbr_unknowns_val_domain_mquant" << endl ;
55  abort() ;
56  }
57  if (indic)
58  res ++ ;
59  pos.inc() ;
60  }
61  while (pos(2)==0) ;
62 
63  return res ;
64 }
65 
66 int Domain_shell::nbr_unknowns_val_domain (const Val_domain& so, int mlim) const {
67 
68  int res = 0 ;
69  int kmin = 2*mlim + 2 ;
70 
71  Index pos (nbr_coefs) ;
72  do {
73  bool indic = true ;
74  // True coef in phi ?
75  if ((pos(2)==1) || (pos(2)==nbr_coefs(2)-1))
76  indic = false ;
77  // Get base in theta :
78  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
79  switch (baset) {
80  case COS_EVEN:
81  if ((pos(1)==0) && (pos(2)>=kmin))
82  indic = false ;
83  break ;
84  case COS_ODD:
85  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (pos(2)>=kmin)))
86  indic = false ;
87  break ;
88  case SIN_EVEN:
89  if (((pos(1)==1)&&(pos(2)>=kmin+2)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
90  indic = false ;
91  break ;
92  case SIN_ODD:
93  if (((pos(1)==0)&&(pos(2)>=kmin+2)) || (pos(1)==nbr_coefs(1)-1))
94  indic = false ;
95  break ;
96  default:
97  cerr << "Unknow theta basis in Domain_shell::nbr_unknowns_val_domain" << endl ;
98  abort() ;
99  }
100  if (indic)
101  res ++ ;
102  }
103  while (pos.inc()) ;
104 
105  return res ;
106 }
107 
108 int Domain_shell::nbr_unknowns (const Tensor& tt, int dom) const {
109 
110  // Check right domain
111  assert (tt.get_space().get_domain(dom)==this) ;
112 
113  int res = 0 ;
114  int val = tt.get_valence() ;
115  switch (val) {
116  case 0 :
117  if (tt.is_m_quant_affected()) {
118  // Special case for boson field
119  res += nbr_unknowns_val_domain_mquant (tt()(dom), tt.get_parameters().get_m_quant()) ;
120  }
121  else
122  res += nbr_unknowns_val_domain (tt()(dom), 0) ;
123  break ;
124  case 1 : {
125  bool found = false ;
126  // Cartesian basis
127  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
128  res += nbr_unknowns_val_domain (tt(1)(dom), 0) ;
129  res += nbr_unknowns_val_domain (tt(2)(dom), 0) ;
130  res += nbr_unknowns_val_domain (tt(3)(dom), 0) ;
131  found = true ;
132  }
133  // Spherical coordinates
134  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
135  res += nbr_unknowns_val_domain (tt(1)(dom), 0) ;
136  res += nbr_unknowns_val_domain (tt(2)(dom), 1) ;
137  res += nbr_unknowns_val_domain (tt(3)(dom), 1) ;
138  found = true ;
139  }
140  // MTZ coordinates
141  if (tt.get_basis().get_basis(dom)==MTZ_BASIS) {
142  res += nbr_unknowns_val_domain (tt(1)(dom), 0) ;
143  res += nbr_unknowns_val_domain (tt(2)(dom), 1) ;
144  res += nbr_unknowns_val_domain (tt(3)(dom), 1) ;
145  found = true ;
146  }
147 #ifndef REMOVE_ALL_CHECKS
148  if (!found) {
149  cerr << "Unknown type of vector Domain_shell::nbr_unknowns" << endl ;
150  abort() ;
151  }
152 #endif
153  }
154  break ;
155  case 2 : {
156  bool found = false ;
157  // Cartesian basis and symetric
158  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
159  res += nbr_unknowns_val_domain (tt(1,1)(dom), 0) ;
160  res += nbr_unknowns_val_domain (tt(1,2)(dom), 0) ;
161  res += nbr_unknowns_val_domain (tt(1,3)(dom), 0) ;
162  res += nbr_unknowns_val_domain (tt(2,2)(dom), 0) ;
163  res += nbr_unknowns_val_domain (tt(2,3)(dom), 0) ;
164  res += nbr_unknowns_val_domain (tt(3,3)(dom), 0) ;
165  found = true ;
166  }
167  // Cartesian basis and not symetric
168  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
169  for (int i=1 ; i<=3 ; i++)
170  for (int j=1 ; j<=3 ; j++)
171  res += nbr_unknowns_val_domain (tt(i,j)(dom), 0) ;
172  found = true ;
173  }
174  // Spherical coordinates and symetric
175  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
176  res += nbr_unknowns_val_domain (tt(1,1)(dom), 0) ;
177  res += nbr_unknowns_val_domain (tt(1,2)(dom), 1) ;
178  res += nbr_unknowns_val_domain (tt(1,3)(dom), 1) ;
179  res += nbr_unknowns_val_domain (tt(2,2)(dom), 2) ;
180  res += nbr_unknowns_val_domain (tt(2,3)(dom), 2) ;
181  res += nbr_unknowns_val_domain (tt(3,3)(dom), 2) ;
182  found = true ;
183  }
184  // Spherical coordinates and not symetric
185  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
186  res += nbr_unknowns_val_domain (tt(1,1)(dom), 0) ;
187  res += nbr_unknowns_val_domain (tt(1,2)(dom), 1) ;
188  res += nbr_unknowns_val_domain (tt(1,3)(dom), 1) ;
189  res += nbr_unknowns_val_domain (tt(2,1)(dom), 1) ;
190  res += nbr_unknowns_val_domain (tt(2,2)(dom), 2) ;
191  res += nbr_unknowns_val_domain (tt(2,3)(dom), 2) ;
192  res += nbr_unknowns_val_domain (tt(3,1)(dom), 1) ;
193  res += nbr_unknowns_val_domain (tt(3,2)(dom), 2) ;
194  res += nbr_unknowns_val_domain (tt(3,3)(dom), 2) ;
195  found = true ;
196  }
197  // MTZ coordinates and symetric
198  if ((tt.get_basis().get_basis(dom)==MTZ_BASIS) && (tt.get_n_comp()==6)) {
199  res += nbr_unknowns_val_domain (tt(1,1)(dom), 0) ;
200  res += nbr_unknowns_val_domain (tt(1,2)(dom), 1) ;
201  res += nbr_unknowns_val_domain (tt(1,3)(dom), 1) ;
202  res += nbr_unknowns_val_domain (tt(2,2)(dom), 2) ;
203  res += nbr_unknowns_val_domain (tt(2,3)(dom), 2) ;
204  res += nbr_unknowns_val_domain (tt(3,3)(dom), 2) ;
205  found = true ;
206  }
207  // MTZ coordinates and not symetric
208  if ((tt.get_basis().get_basis(dom)==MTZ_BASIS) && (tt.get_n_comp()==9)) {
209  res += nbr_unknowns_val_domain (tt(1,1)(dom), 0) ;
210  res += nbr_unknowns_val_domain (tt(1,2)(dom), 1) ;
211  res += nbr_unknowns_val_domain (tt(1,3)(dom), 1) ;
212  res += nbr_unknowns_val_domain (tt(2,1)(dom), 1) ;
213  res += nbr_unknowns_val_domain (tt(2,2)(dom), 2) ;
214  res += nbr_unknowns_val_domain (tt(2,3)(dom), 2) ;
215  res += nbr_unknowns_val_domain (tt(3,1)(dom), 1) ;
216  res += nbr_unknowns_val_domain (tt(3,2)(dom), 2) ;
217  res += nbr_unknowns_val_domain (tt(3,3)(dom), 2) ;
218  found = true ;
219  }
220 #ifndef REMOVE_ALL_CHECKS
221  if (!found) {
222  cerr << "Unknown type of 2-tensor Domain_shell::nbr_unknowns" << endl ;
223  abort() ;
224  }
225 #endif
226  }
227  break ;
228  default :
229  cerr << "Valence " << val << " not implemented in Domain_shell::nbr_unknowns" << endl ;
230  break ;
231  }
232  return res ;
233 }}
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_mquant(const Val_domain &so, int mquant) const
Computes the number of true unknowns of a Val_domain.
int nbr_unknowns_val_domain(const Val_domain &so, int mlim) 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
int get_m_quant() const
Returns .
Definition: tensor.hpp:747
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
Tensor handling.
Definition: tensor.hpp:149
const Param_tensor & get_parameters() const
Returns a pointer on the possible additional parameter.
Definition: tensor.hpp:311
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
bool is_m_quant_affected() const
Checks whether the additional parameter is affected (used for boson stars for instance).
Definition: tensor.hpp:326
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