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