KADATH
domain_shell_inner_adapted_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 #include "adapted.hpp"
22 #include "point.hpp"
23 #include "array_math.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "tensor.hpp"
27 
28 namespace Kadath {
29 int Domain_shell_inner_adapted::nbr_conditions_val_domain (const Val_domain& so, int mlim, int order) const {
30 
31  int res = 0 ;
32  int kmin = 2*mlim + 2 ;
33 
34  Index pos (nbr_coefs) ;
35  do {
36  bool indic = true ;
37  // True coef in phi ?
38  if ((pos(2)==1) || (pos(2)==nbr_coefs(2)-1))
39  indic = false ;
40  // Get base in theta :
41  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
42  switch (baset) {
43  case COS_EVEN:
44  if ((pos(1)==0) && (pos(2)>=kmin))
45  indic = false ;
46  break ;
47  case COS_ODD:
48  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (pos(2)>=kmin)))
49  indic = false ;
50  break ;
51  case SIN_EVEN:
52  if (((pos(1)==1)&&(pos(2)>=kmin+2)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
53  indic = false ;
54  break ;
55  case SIN_ODD:
56  if (((pos(1)==0)&&(pos(2)>=kmin+2)) || (pos(1)==nbr_coefs(1)-1))
57  indic = false ;
58  break ;
59  default:
60  cerr << "Unknow theta basis in Domain_shell_inner_adapted::nbr_conditions_val_domain" << endl ;
61  abort() ;
62  }
63  // Order with respect to r :
64  if (pos(0)>nbr_coefs(0)-order-1)
65  indic = false ;
66 
67  if (indic)
68  res ++ ;
69  }
70  while (pos.inc()) ;
71 
72  return res ;
73 }
74 
75 Array<int> Domain_shell_inner_adapted::nbr_conditions (const Tensor& tt, int dom, int order, int n_cmp, Array<int>** p_cmp) const {
76 
77  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
78  Array<int> res (size) ;
79  int val = tt.get_valence() ;
80  switch (val) {
81  case 0 :
82  if (!tt.is_m_order_affected())
83  res.set(0) = nbr_conditions_val_domain (tt()(dom), 0, order) ;
84  else
85  res.set(0) = nbr_conditions_val_domain (tt()(dom), tt.get_parameters().get_m_order(), order) ;
86  break ;
87  case 1 : {
88  bool found = false ;
89  // Cartesian basis
90  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
91  if (n_cmp==-1) {
92  res.set(0) = nbr_conditions_val_domain (tt(1)(dom), 0, order) ;
93  res.set(1) = nbr_conditions_val_domain (tt(2)(dom), 0, order) ;
94  res.set(2) = nbr_conditions_val_domain (tt(3)(dom), 0, order) ;
95  }
96  else for (int i=0 ; i<n_cmp ; i++) {
97  if ((*p_cmp[i])(0)==1)
98  res.set(i) = nbr_conditions_val_domain (tt(1)(dom), 0, order) ;
99  if ((*p_cmp[i])(0)==2)
100  res.set(i) = nbr_conditions_val_domain (tt(2)(dom), 0, order) ;
101  if ((*p_cmp[i])(0)==3)
102  res.set(i) = nbr_conditions_val_domain (tt(3)(dom), 0, order) ;
103  }
104  found = true ;
105  }
106  // Spherical coordinates
107  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
108  if (n_cmp==-1) {
109  res.set(0) = nbr_conditions_val_domain (tt(1)(dom), 0, order) ;
110  res.set(1) = nbr_conditions_val_domain (tt(2)(dom), 1, order) ;
111  res.set(2) = nbr_conditions_val_domain (tt(3)(dom), 1, order) ;
112  }
113  else for (int i=0 ; i<n_cmp ; i++) {
114  if ((*p_cmp[i])(0)==1)
115  res.set(i) = nbr_conditions_val_domain (tt(1)(dom), 0, order) ;
116  if ((*p_cmp[i])(0)==2)
117  res.set(i) = nbr_conditions_val_domain (tt(2)(dom), 1, order) ;
118  if ((*p_cmp[i])(0)==3)
119  res.set(i) = nbr_conditions_val_domain (tt(3)(dom), 1, order) ;
120  }
121  found = true ;
122  }
123  if (!found) {
124  cerr << "Unknown type of vector Domain_shell_inner_adapted::nbr_conditions" << endl ;
125  abort() ;
126  }
127  }
128  break ;
129  case 2 : {
130  bool found = false ;
131  // Cartesian basis and symetric
132  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
133  if (n_cmp==-1) {
134  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 0, order) ;
135  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 0, order) ;
136  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 0, order) ;
137  res.set(3) = nbr_conditions_val_domain (tt(2,2)(dom), 0, order) ;
138  res.set(4) = nbr_conditions_val_domain (tt(2,3)(dom), 0, order) ;
139  res.set(5) = nbr_conditions_val_domain (tt(3,3)(dom), 0, order) ;
140  }
141  else for (int i=0 ; i<n_cmp ; i++) {
142  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
143  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 0, order) ;
144  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
145  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 0, order) ;
146  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
147  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 0, order) ;
148  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
149  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 0, order) ;
150  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
151  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 0, order) ;
152  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
153  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 0, order) ;
154  }
155  found = true ;
156  }
157  // Cartesian basis and not symetric
158  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
159  if (n_cmp==-1) {
160  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 0, order) ;
161  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 0, order) ;
162  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 0, order) ;
163  res.set(3) = nbr_conditions_val_domain (tt(2,1)(dom), 0, order) ;
164  res.set(4) = nbr_conditions_val_domain (tt(2,2)(dom), 0, order) ;
165  res.set(5) = nbr_conditions_val_domain (tt(2,3)(dom), 0, order) ;
166  res.set(6) = nbr_conditions_val_domain (tt(3,1)(dom), 0, order) ;
167  res.set(7) = nbr_conditions_val_domain (tt(3,2)(dom), 0, order) ;
168  res.set(8) = nbr_conditions_val_domain (tt(3,3)(dom), 0, order) ;
169  }
170  else for (int i=0 ; i<n_cmp ; i++) {
171  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
172  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 0, order) ;
173  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
174  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 0, order) ;
175  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
176  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 0, order) ;
177  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
178  res.set(i) = nbr_conditions_val_domain (tt(2, 1)(dom), 0, order) ;
179  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
180  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 0, order) ;
181  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
182  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 0, order) ;
183  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
184  res.set(i) = nbr_conditions_val_domain (tt(3, 1)(dom), 0, order) ;
185  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
186  res.set(i) = nbr_conditions_val_domain (tt(3, 2)(dom), 0, order) ;
187  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
188  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 0, order) ;
189  }
190  found = true ;
191  }
192  // Spherical coordinates and symetric
193  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
194  if (n_cmp==-1) {
195  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 0, order) ;
196  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 1, order) ;
197  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 1, order) ;
198  res.set(3) = nbr_conditions_val_domain (tt(2,2)(dom), 2, order) ;
199  res.set(4) = nbr_conditions_val_domain (tt(2,3)(dom), 2, order) ;
200  res.set(5) = nbr_conditions_val_domain (tt(3,3)(dom), 2, order) ;
201  }
202  else for (int i=0 ; i<n_cmp ; i++) {
203  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
204  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 0, order) ;
205  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
206  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 1, order) ;
207  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
208  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 1, order) ;
209  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
210  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 2, order) ;
211  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
212  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 2, order) ;
213  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
214  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 2, order) ;
215  }
216  found = true ;
217  }
218  // Spherical coordinates and not symetric
219  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
220  if (n_cmp==-1) {
221  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 0, order) ;
222  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 1, order) ;
223  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 1, order) ;
224  res.set(3) = nbr_conditions_val_domain (tt(2,1)(dom), 1, order) ;
225  res.set(4) = nbr_conditions_val_domain (tt(2,2)(dom), 2, order) ;
226  res.set(5) = nbr_conditions_val_domain (tt(2,3)(dom), 2, order) ;
227  res.set(6) = nbr_conditions_val_domain (tt(3,1)(dom), 1, order) ;
228  res.set(7) = nbr_conditions_val_domain (tt(3,2)(dom), 2, order) ;
229  res.set(8) = nbr_conditions_val_domain (tt(3,3)(dom), 2, order) ;
230 
231  }
232  else for (int i=0 ; i<n_cmp ; i++) {
233  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
234  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 0, order) ;
235  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
236  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 1, order) ;
237  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
238  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 1, order) ;
239  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
240  res.set(i) = nbr_conditions_val_domain (tt(2, 1)(dom), 1, order) ;
241  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
242  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 2, order) ;
243  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
244  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 2, order) ;
245  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
246  res.set(i) = nbr_conditions_val_domain (tt(3, 1)(dom), 1, order) ;
247  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
248  res.set(i) = nbr_conditions_val_domain (tt(3, 2)(dom), 2, order) ;
249  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
250  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 2, order) ;
251  }
252  found = true ;
253  }
254  if (!found) {
255  cerr << "Unknown type of 2-tensor Domain_shell_inner_adapted::nbr_conditions" << endl ;
256  abort() ;
257  }
258  }
259  break ;
260  default :
261  cerr << "Valence " << val << " not implemented in Domain_shell_inner_adapted::nbr_conditions" << endl ;
262  break ;
263  }
264  return res ;
265 }
266 }
267 
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 &so, 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.
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
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
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