KADATH
domain_nucleus_nbr_conditions_boundary.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 {
29 
30  int res = 0 ;
31 
32  for (int k=0 ; k<nbr_coefs(2) ; k++)
33  for (int j=0 ; j<nbr_coefs(1) ; j++) {
34  bool indic = true ;
35  // True coef in phi ?
36  if ((k==1) || (k==nbr_coefs(2)-1))
37  indic = false ;
38  // Get base in theta :
39  int baset = (*so.get_base().bases_1d[1]) (k) ;
40  switch (baset) {
41  case COS_EVEN:
42  if ((j==0) && (k!=0))
43  indic = false ;
44  break ;
45  case SIN_ODD:
46  if (j==nbr_coefs(1)-1)
47  indic = false ;
48  break ;
49  default:
50  cerr << "Unknow theta basis in Domain_nucleus::nbr_conditions_val_domain_boundary_vr" << endl ;
51  abort() ;
52  }
53 
54 
55  if (indic)
56  res ++ ;
57  }
58 
59  return res ;
60 }
61 
63 
64  int res = 0 ;
65 
66  for (int k=0 ; k<nbr_coefs(2) ; k++)
67  for (int j=0 ; j<nbr_coefs(1) ; j++) {
68  bool indic = true ;
69  // True coef in phi ?
70  if ((k==1) || (k==nbr_coefs(2)-1))
71  indic = false ;
72  // Get base in theta :
73  int baset = (*so.get_base().bases_1d[1]) (k) ;
74  switch (baset) {
75  case SIN_EVEN:
76  if ((j==nbr_coefs(1)-1) || (j==0))
77  indic= false ;
78  break ;
79  case COS_ODD:
80  if (j==nbr_coefs(1)-1)
81  indic = false ;
82  if ((j==0) && (k>3))
83  indic = false ;
84  break ;
85  default:
86  cerr << "Unknow theta basis in Domain_nucleus::nbr_conditions_val_domain_boundary_vt" << endl ;
87  abort() ;
88  }
89 
90  if (indic)
91  res ++ ;
92  }
93 
94  return res ;
95 }
96 
98 
99  int res = 0 ;
100 
101  for (int k=0 ; k<nbr_coefs(2) ; k++)
102  for (int j=0 ; j<nbr_coefs(1) ; j++)
103  {
104  bool indic = true ;
105  // True coef in phi ?
106  if ((k==1) || (k==nbr_coefs(2)-1))
107  indic = false ;
108  // Get base in theta :
109  int baset = (*so.get_base().bases_1d[1]) (k) ;
110  switch (baset) {
111  case COS_EVEN:
112  if ((k>3) && (j==0))
113  indic = false ;
114  break ;
115  case SIN_ODD:
116  if (j==nbr_coefs(1)-1)
117  indic = false ;
118  break ;
119  default:
120  cerr << "Unknow theta basis in Domain_nucleus::nbr_conditions_val_domain_boundary_vp" << endl ;
121  abort() ;
122  }
123 
124  if (indic)
125  res ++ ;
126  }
127 
128  return res ;
129 }
131 
132  int res = 0 ;
133  int kmin = 2*mlim + 2 ;
134 
135  for (int k=0 ; k<nbr_coefs(2) ; k++)
136  for (int j=0 ; j<nbr_coefs(1) ; j++) {
137  bool indic = true ;
138  // True coef in phi ?
139  if ((k==1) || (k==nbr_coefs(2)-1))
140  indic = false ;
141  // Get base in theta :
142  int baset = (*so.get_base().bases_1d[1])(k) ;
143  switch (baset) {
144  case COS_EVEN:
145  if ((j==0) && (k>=kmin))
146  indic = false ;
147  break ;
148  case COS_ODD:
149  if ((j==nbr_coefs(1)-1) || ((j==0) && (k>=kmin)))
150  indic = false ;
151  break ;
152  case SIN_EVEN:
153  if (((j==1) && (k>=kmin+2)) || (j==0) || (j==nbr_coefs(1)-1))
154  indic = false ;
155  break ;
156  case SIN_ODD:
157  if (((j==0) && (k>=kmin+2)) || (j==nbr_coefs(1)-1))
158  indic = false ;
159  break ;
160  default:
161  cerr << "Unknow theta basis in Domain_nucleus::nbr_conditions_val_boundary" << endl ;
162  abort() ;
163  }
164 
165  if (indic)
166  res ++ ;
167  }
168  return res ;
169 }
170 
171 Array<int> Domain_nucleus::nbr_conditions_boundary (const Tensor& tt, int dom, int bound, int n_cmp, Array<int>** p_cmp) const {
172 
173  // Check boundary
174  if (bound!=OUTER_BC) {
175  cerr << "Unknown boundary in Domain_nucleus::nbr_conditions_boundary" << endl ;
176  abort() ;
177  }
178 
179  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
180  Array<int> res (size) ;
181  int val = tt.get_valence() ;
182  switch (val) {
183  case 0 :
184  if (!tt.is_m_order_affected())
185  res.set(0) = nbr_conditions_val_domain_boundary (tt()(dom), 0) ;
186  else
188  break ;
189  case 1 : {
190  bool found = false ;
191  // Cartesian basis
192  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
193  if (n_cmp==-1) {
194  res.set(0) = nbr_conditions_val_domain_boundary (tt(1)(dom), 0) ;
195  res.set(1) = nbr_conditions_val_domain_boundary (tt(2)(dom), 0) ;
196  res.set(2) = nbr_conditions_val_domain_boundary (tt(3)(dom), 0) ;
197  }
198  else for (int i=0 ; i<n_cmp ; i++) {
199  if ((*p_cmp[i])(0)==1)
200  res.set(i) = nbr_conditions_val_domain_boundary (tt(1)(dom), 0) ;
201  if ((*p_cmp[i])(0)==2)
202  res.set(i) = nbr_conditions_val_domain_boundary (tt(2)(dom), 0) ;
203  if ((*p_cmp[i])(0)==3)
204  res.set(i) = nbr_conditions_val_domain_boundary (tt(3)(dom), 0) ;
205  }
206  found = true ;
207  }
208  // Spherical coordinates
209  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
210  if (n_cmp==-1) {
211  res.set(0) = nbr_conditions_val_domain_boundary_vr (tt(1)(dom)) ;
212  res.set(1) = nbr_conditions_val_domain_boundary_vt (tt(2)(dom)) ;
213  res.set(2) = nbr_conditions_val_domain_boundary_vp (tt(3)(dom)) ;
214  }
215  else for (int i=0 ; i<n_cmp ; i++) {
216  if ((*p_cmp[i])(0)==1)
217  res.set(i) = nbr_conditions_val_domain_boundary_vr (tt(1)(dom)) ;
218  if ((*p_cmp[i])(0)==2)
219  res.set(i) = nbr_conditions_val_domain_boundary_vt (tt(2)(dom)) ;
220  if ((*p_cmp[i])(0)==3)
221  res.set(i) = nbr_conditions_val_domain_boundary_vp (tt(3)(dom)) ;
222  }
223  found = true ;
224  }
225  if (!found) {
226  cerr << "Unknown type of vector Domain_nucleus::nbr_conditions_boundary" << endl ;
227  abort() ;
228  }
229  }
230  break ;
231  case 2 : {
232  bool found = false ;
233  // Cartesian basis and symetric
234  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
235  if (n_cmp==-1) {
236  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), 0) ;
237  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), 0) ;
238  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), 0) ;
239  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), 0) ;
240  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), 0) ;
241  res.set(5) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), 0) ;
242  }
243  else for (int i=0 ; i<n_cmp ; i++) {
244  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
245  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), 0) ;
246  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
247  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), 0) ;
248  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
249  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), 0) ;
250  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
251  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), 0) ;
252  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
253  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), 0) ;
254  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
255  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), 0) ;
256  }
257  found = true ;
258  }
259  // Cartesian basis and not symetric
260  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
261  if (n_cmp==-1) {
262  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), 0) ;
263  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), 0) ;
264  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), 0) ;
265  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,1)(dom), 0) ;
266  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), 0) ;
267  res.set(5) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), 0) ;
268  res.set(6) = nbr_conditions_val_domain_boundary (tt(3,1)(dom), 0) ;
269  res.set(7) = nbr_conditions_val_domain_boundary (tt(3,2)(dom), 0) ;
270  res.set(8) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), 0) ;
271  }
272  else for (int i=0 ; i<n_cmp ; i++) {
273  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
274  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), 0) ;
275  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
276  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), 0) ;
277  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
278  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), 0) ;
279  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
280  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 1)(dom), 0) ;
281  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
282  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), 0) ;
283  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
284  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), 0) ;
285  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
286  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 1)(dom), 0) ;
287  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
288  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 2)(dom), 0) ;
289  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
290  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), 0) ;
291  }
292  found = true ;
293  }
294  // Spherical coordinates and symetric
295  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
296  if (n_cmp==-1) {
297  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), 0) ;
298  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), 1) ;
299  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), 1) ;
300  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), 2) ;
301  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), 2) ;
302  res.set(5) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), 2) ;
303  }
304  else for (int i=0 ; i<n_cmp ; i++) {
305  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
306  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), 0) ;
307  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
308  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), 1) ;
309  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
310  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), 1) ;
311  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
312  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), 2) ;
313  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
314  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), 2) ;
315  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
316  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), 2) ;
317  }
318  found = true ;
319  }
320  // Spherical coordinates and not symetric
321  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
322  if (n_cmp==-1) {
323  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), 0) ;
324  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), 1) ;
325  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), 1) ;
326  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,1)(dom), 1) ;
327  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), 2) ;
328  res.set(5) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), 2) ;
329  res.set(6) = nbr_conditions_val_domain_boundary (tt(3,1)(dom), 1) ;
330  res.set(7) = nbr_conditions_val_domain_boundary (tt(3,2)(dom), 2) ;
331  res.set(8) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), 2) ;
332 
333  }
334  else for (int i=0 ; i<n_cmp ; i++) {
335  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
336  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), 0) ;
337  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
338  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), 1) ;
339  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
340  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), 1) ;
341  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
342  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 1)(dom), 1) ;
343  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
344  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), 2) ;
345  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
346  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), 2) ;
347  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
348  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 1)(dom), 1) ;
349  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
350  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 2)(dom), 2) ;
351  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
352  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), 2) ;
353  }
354  found = true ;
355  }
356  if (!found) {
357  cerr << "Unknown type of 2-tensor Domain_nucleus::nbr_conditions_boundary" << endl ;
358  abort() ;
359  }
360  }
361  break ;
362  default :
363  cerr << "Valence " << val << " not implemented in Domain_nucleus::nbr_conditions_boundary" << endl ;
364  break ;
365  }
366  return res ;
367 }}
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_boundary_vt(const Val_domain &eq) const
Computes number of discretized equations associated with a given equation on a boundary.
int nbr_conditions_val_domain_boundary(const Val_domain &eq, int mlim) const
Computes number of discretized equations associated with a given equation on a boundary.
virtual Array< int > nbr_conditions_boundary(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 on a boundary.
int nbr_conditions_val_domain_boundary_vr(const Val_domain &eq) const
Computes number of discretized equations associated with a given equation on a boundary.
int nbr_conditions_val_domain_boundary_vp(const Val_domain &eq) const
Computes number of discretized equations associated with a given equation on a boundary.
Dim_array nbr_coefs
Number of coefficients.
Definition: space.hpp:66
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