KADATH
domain_compact_nbr_conditions.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 "spheric.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
28 
29 
30 int Domain_compact::nbr_conditions_val_domain_mquant (const Val_domain& so, int mquant, int order) const {
31  int res = 0 ;
32 
33  Index pos (nbr_coefs) ;
34  do {
35  bool indic = true ;
36  // Get base in theta :
37  int baset = (*so.get_base().bases_1d[1]) (0) ;
38  switch (baset) {
39  case COS_EVEN:
40  if ((pos(1)==0) && (mquant!=0))
41  indic = false ;
42  break ;
43  case COS_ODD:
44  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (mquant!=0)))
45  indic = false ;
46  break ;
47  case SIN_EVEN:
48  if (((pos(1)==1) && (mquant>1)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
49  indic = false ;
50  break ;
51  case SIN_ODD:
52  if (((pos(1)==0) && (mquant>1)) || (pos(1)==nbr_coefs(1)-1))
53  indic = false ;
54  break ;
55  default:
56  cerr << "Unknow theta basis in Domain_compact::nbr_conditions_val_domain_mquant" << endl ;
57  abort() ;
58  }
59  // Order with respect to r :
60  if (pos(0)>nbr_coefs(0)-order-1)
61  indic = false ;
62 
63  if (indic)
64  res ++ ;
65  pos.inc() ;
66  }
67  while (pos(2)==0) ;
68 
69  return res ;
70 }
71 
72 
73 int Domain_compact::nbr_conditions_val_domain (const Val_domain& so, int mlim, int order) const {
74 
75  int res = 0 ;
76  int kmin = 2*mlim + 2 ;
77 
78  Index pos (nbr_coefs) ;
79  do {
80  bool indic = true ;
81  // True coef in phi ?
82  if ((pos(2)==1) || (pos(2)==nbr_coefs(2)-1))
83  indic = false ;
84  // Get base in theta :
85  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
86  switch (baset) {
87  case COS_EVEN:
88  if ((pos(1)==0) && (pos(2)>=kmin))
89  indic = false ;
90  break ;
91  case COS_ODD:
92  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (pos(2)>=kmin)))
93  indic = false ;
94  break ;
95  case SIN_EVEN:
96  if (((pos(1)==1)&&(pos(2)>=kmin+2)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
97  indic = false ;
98  break ;
99  case SIN_ODD:
100  if (((pos(1)==0)&&(pos(2)>=kmin+2)) || (pos(1)==nbr_coefs(1)-1))
101  indic = false ;
102  break ;
103  default:
104  cerr << "Unknow theta basis in Domain_compact::nbr_conditions_val_domain" << endl ;
105  abort() ;
106  }
107  // Order with respect to r :
108  if (pos(0)>nbr_coefs(0)-order-1)
109  indic = false ;
110 
111  if (indic)
112  res ++ ;
113  }
114  while (pos.inc()) ;
115 
116  return res ;
117 }
118 
119 Array<int> Domain_compact::nbr_conditions (const Tensor& tt, int dom, int order, int n_cmp, Array<int>** p_cmp) const {
120 
121  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
122  Array<int> res (size) ;
123  int val = tt.get_valence() ;
124  switch (val) {
125  case 0 :
126  if (tt.is_m_quant_affected()) {
127  // Special case for boson field
128  res.set(0) = nbr_conditions_val_domain_mquant (tt()(dom), tt.get_parameters().get_m_quant(), order) ;
129  }
130  else {
131  if (!tt.is_m_order_affected())
132  res.set(0) = nbr_conditions_val_domain (tt()(dom), 0, order) ;
133  else
134  res.set(0) = nbr_conditions_val_domain (tt()(dom), tt.get_parameters().get_m_order(), order) ;
135  }
136  break ;
137  case 1 : {
138  bool found = false ;
139  // Cartesian basis
140  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
141  if (n_cmp==-1) {
142  res.set(0) = nbr_conditions_val_domain (tt(1)(dom), 0, order) ;
143  res.set(1) = nbr_conditions_val_domain (tt(2)(dom), 0, order) ;
144  res.set(2) = nbr_conditions_val_domain (tt(3)(dom), 0, order) ;
145  }
146  else for (int i=0 ; i<n_cmp ; i++) {
147  if ((*p_cmp[i])(0)==1)
148  res.set(i) = nbr_conditions_val_domain (tt(1)(dom), 0, order) ;
149  if ((*p_cmp[i])(0)==2)
150  res.set(i) = nbr_conditions_val_domain (tt(2)(dom), 0, order) ;
151  if ((*p_cmp[i])(0)==3)
152  res.set(i) = nbr_conditions_val_domain (tt(3)(dom), 0, order) ;
153  }
154  found = true ;
155  }
156  // Spherical coordinates
157  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
158  if (n_cmp==-1) {
159  res.set(0) = nbr_conditions_val_domain (tt(1)(dom), 0, order) ;
160  res.set(1) = nbr_conditions_val_domain (tt(2)(dom), 1, order) ;
161  res.set(2) = nbr_conditions_val_domain (tt(3)(dom), 1, order) ;
162  }
163  else for (int i=0 ; i<n_cmp ; i++) {
164  if ((*p_cmp[i])(0)==1)
165  res.set(i) = nbr_conditions_val_domain (tt(1)(dom), 0, order) ;
166  if ((*p_cmp[i])(0)==2)
167  res.set(i) = nbr_conditions_val_domain (tt(2)(dom), 1, order) ;
168  if ((*p_cmp[i])(0)==3)
169  res.set(i) = nbr_conditions_val_domain (tt(3)(dom), 1, order) ;
170  }
171  found = true ;
172  }
173  if (!found) {
174  cerr << "Unknown type of vector Domain_compact::nbr_conditions" << endl ;
175  abort() ;
176  }
177  }
178  break ;
179  case 2 : {
180  bool found = false ;
181  // Cartesian basis and symetric
182  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
183  if (n_cmp==-1) {
184  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 0, order) ;
185  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 0, order) ;
186  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 0, order) ;
187  res.set(3) = nbr_conditions_val_domain (tt(2,2)(dom), 0, order) ;
188  res.set(4) = nbr_conditions_val_domain (tt(2,3)(dom), 0, order) ;
189  res.set(5) = nbr_conditions_val_domain (tt(3,3)(dom), 0, order) ;
190  }
191  else for (int i=0 ; i<n_cmp ; i++) {
192  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
193  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 0, order) ;
194  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
195  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 0, order) ;
196  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
197  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 0, order) ;
198  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
199  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 0, order) ;
200  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
201  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 0, order) ;
202  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
203  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 0, order) ;
204  }
205  found = true ;
206  }
207  // Cartesian basis and not symetric
208  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
209  if (n_cmp==-1) {
210  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 0, order) ;
211  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 0, order) ;
212  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 0, order) ;
213  res.set(3) = nbr_conditions_val_domain (tt(2,1)(dom), 0, order) ;
214  res.set(4) = nbr_conditions_val_domain (tt(2,2)(dom), 0, order) ;
215  res.set(5) = nbr_conditions_val_domain (tt(2,3)(dom), 0, order) ;
216  res.set(6) = nbr_conditions_val_domain (tt(3,1)(dom), 0, order) ;
217  res.set(7) = nbr_conditions_val_domain (tt(3,2)(dom), 0, order) ;
218  res.set(8) = nbr_conditions_val_domain (tt(3,3)(dom), 0, order) ;
219  }
220  else for (int i=0 ; i<n_cmp ; i++) {
221  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
222  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 0, order) ;
223  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
224  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 0, order) ;
225  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
226  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 0, order) ;
227  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
228  res.set(i) = nbr_conditions_val_domain (tt(2, 1)(dom), 0, order) ;
229  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
230  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 0, order) ;
231  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
232  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 0, order) ;
233  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
234  res.set(i) = nbr_conditions_val_domain (tt(3, 1)(dom), 0, order) ;
235  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
236  res.set(i) = nbr_conditions_val_domain (tt(3, 2)(dom), 0, order) ;
237  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
238  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 0, order) ;
239  }
240  found = true ;
241  }
242  // Spherical coordinates and symetric
243  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
244  if (n_cmp==-1) {
245  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 0, order) ;
246  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 1, order) ;
247  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 1, order) ;
248  res.set(3) = nbr_conditions_val_domain (tt(2,2)(dom), 2, order) ;
249  res.set(4) = nbr_conditions_val_domain (tt(2,3)(dom), 2, order) ;
250  res.set(5) = nbr_conditions_val_domain (tt(3,3)(dom), 2, order) ;
251  }
252  else for (int i=0 ; i<n_cmp ; i++) {
253  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
254  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 0, order) ;
255  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
256  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 1, order) ;
257  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
258  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 1, order) ;
259  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
260  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 2, order) ;
261  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
262  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 2, order) ;
263  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
264  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 2, order) ;
265  }
266  found = true ;
267  }
268  // Spherical coordinates and not symetric
269  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
270  if (n_cmp==-1) {
271  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 0, order) ;
272  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 1, order) ;
273  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 1, order) ;
274  res.set(3) = nbr_conditions_val_domain (tt(2,1)(dom), 1, order) ;
275  res.set(4) = nbr_conditions_val_domain (tt(2,2)(dom), 2, order) ;
276  res.set(5) = nbr_conditions_val_domain (tt(2,3)(dom), 2, order) ;
277  res.set(6) = nbr_conditions_val_domain (tt(3,1)(dom), 1, order) ;
278  res.set(7) = nbr_conditions_val_domain (tt(3,2)(dom), 2, order) ;
279  res.set(8) = nbr_conditions_val_domain (tt(3,3)(dom), 2, order) ;
280 
281  }
282  else for (int i=0 ; i<n_cmp ; i++) {
283  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
284  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 0, order) ;
285  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
286  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 1, order) ;
287  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
288  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 1, order) ;
289  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
290  res.set(i) = nbr_conditions_val_domain (tt(2, 1)(dom), 1, order) ;
291  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
292  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 2, order) ;
293  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
294  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 2, order) ;
295  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
296  res.set(i) = nbr_conditions_val_domain (tt(3, 1)(dom), 1, order) ;
297  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
298  res.set(i) = nbr_conditions_val_domain (tt(3, 2)(dom), 2, order) ;
299  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
300  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 2, order) ;
301  }
302  found = true ;
303  }
304  if (!found) {
305  cerr << "Unknown type of 2-tensor Domain_compact::nbr_conditions" << endl ;
306  abort() ;
307  }
308  }
309  break ;
310  default :
311  cerr << "Valence " << val << " not implemented in Domain_compact::nbr_conditions" << endl ;
312  break ;
313  }
314  return res ;
315 }}
reference set(const Index &pos)
Read/write of an element.
Definition: array.hpp:186
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_conditions_val_domain(const Val_domain &eq, int mlim, int order) const
Computes number of discretized equations associated with a given tensorial equation in the bulk.
virtual Array< int > nbr_conditions(const Tensor &, int, int, int n_cmp=-1, Array< int > **p_cmp=0x0) const
Computes number of discretized equations associated with a given tensorial equation in the bulk.
int nbr_conditions_val_domain_mquant(const Val_domain &eq, int mquant, int order) const
Computes number of discretized equations associated with a given tensorial equation in the bulk.
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_order() const
Returns .
Definition: tensor.hpp:737
int get_m_quant() const
Returns .
Definition: tensor.hpp:747
Tensor handling.
Definition: tensor.hpp:149
bool is_m_order_affected() const
Checks whether the additional parameter order is affected (not very used).
Definition: tensor.hpp:323
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
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