KADATH
domain_bispheric_rect_export_tau_boundary_one_side.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 "bispheric.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
28 void Domain_bispheric_rect::export_tau_val_domain_boundary_one_side (const Val_domain& so, int bound, Array<double>& sec, int& pos_sec, int ncond) const {
29 
30  if (so.check_if_zero())
31  pos_sec += ncond ;
32  else {
33  so.coef() ;
34 
35  Index pos (nbr_coefs) ;
36  Index pos_galerkin (nbr_coefs) ;
37  int basep = (*so.get_base().bases_1d[2]) (0) ;
38 
39  if (bound==INNER_BC) {
40 
41  // Loop on phi :
42  for (int k=0 ; k<nbr_coefs(2) ; k++) {
43  pos.set(2) = k ;
44  // Loop on chi :
45  for (int j=0 ; j<nbr_coefs(1) ; j++) {
46  pos.set(1) = j ;
47  switch (basep) {
48  case COS :
49  // Avoid last odd ones
50  if ((k%2!=1) || (j!=nbr_coefs(1)-1)) {
51  if ((k==0) || (k%2==1)) {
52  // The ones without regularity issues
53  sec.set(pos_sec) = val_boundary (bound, so, pos) ;
54  pos_sec ++ ;
55  }
56  else if (j!=0) {
57  // Regularity on the axis thanks to Galerkin
58  // Factor fo Galerkin different for Legendre or Chebyshev:
59  double factor_galerkin ;
60  switch (type_base) {
61  case CHEB_TYPE :
62  factor_galerkin = (j%2==1) ? -2. : 2. ;
63  break ;
64  case LEG_TYPE :
65  factor_galerkin = -double(4*j+1) ;
66  for (int jj=1 ; jj<=j ; jj++)
67  factor_galerkin *= -double(2*jj-1)/double(2*jj) ;
68  break ;
69  default :
70  cerr << "Unknown type of basis in Domain_bispheric_rect::export_tau_boundary_one_side" << endl ;
71  abort() ;
72  }
73  pos_galerkin = pos ;
74  pos_galerkin.set(1) = 0 ;
75  sec.set(pos_sec) = val_boundary (bound, so, pos) +
76  factor_galerkin * val_boundary (bound, so, pos_galerkin) ;
77  pos_sec ++ ;
78  }}
79  break ;
80  case SIN :
81  // Avoid sin(0)
82  if ((k!=0) && (k!=nbr_coefs(2)-1))
83  //Avoid last odd ones
84  if ((k%2!=1) || (j!=nbr_coefs(1)-1)) {
85  if (k%2==1) {
86  // The ones without regularity issues
87  sec.set(pos_sec) = val_boundary (bound, so, pos) ;
88  pos_sec ++ ;
89  }
90  else if (j!=0) {
91  // Regularity on the axis thanks to Galerkin
92  // Factor fo Galerkin different for Legendre or Chebyshev:
93  double factor_galerkin ;
94  switch (type_base) {
95  case CHEB_TYPE :
96  factor_galerkin = (j%2==1) ? -2. : 2. ;
97  break ;
98  case LEG_TYPE :
99  factor_galerkin = -double(4*j+1) ;
100  for (int jj=1 ; jj<=j ; jj++)
101  factor_galerkin *= -double(2*jj-1)/double(2*jj) ;
102  break ;
103  default :
104  cerr << "Unknown type of basis in Domain_bispheric_rect::export_tau_boundary_one_side" << endl ;
105  abort() ;
106  }
107  pos_galerkin = pos ;
108  pos_galerkin.set(1) = 0 ;
109  sec.set(pos_sec) = val_boundary (bound, so, pos) +
110  factor_galerkin * val_boundary (bound, so, pos_galerkin) ;
111  pos_sec ++ ;
112  }}
113  break ;
114  default :
115  cerr << "Unknown base in Domain_bispheric_rect::export_tau_boundary_one_side" << endl ;
116  break ;
117  }
118  }
119  }
120  }
121 
122  if (bound==ETA_PLUS_BC) {
123  // Loop on phi :
124  for (int k=0 ; k<nbr_coefs(2) ; k++) {
125  pos.set(2) = k ;
126  // Loop on chi :
127  for (int j=0 ; j<nbr_coefs(1)-1 ; j++) {
128  pos.set(1) = j ;
129  switch (basep) {
130  case COS :
131  // Avoid last odd ones
132  if ((k%2!=1) || (j!=nbr_coefs(1)-2)) {
133  if ((k==0) || (k%2==1)) {
134  // The ones without regularity issues
135  sec.set(pos_sec) = val_boundary (bound, so, pos) ;
136  pos_sec ++ ;
137  }
138  else if (j!=0) {
139  // Regularity on the axis thanks to Galerkin
140  // Factor fo Galerkin different for Legendre or Chebyshev:
141  double factor_galerkin ;
142  switch (type_base) {
143  case CHEB_TYPE :
144  factor_galerkin = (j%2==1) ? -2. : 2. ;
145  break ;
146  case LEG_TYPE :
147  factor_galerkin = -double(4*j+1) ;
148  for (int jj=1 ; jj<=j ; jj++)
149  factor_galerkin *= -double(2*jj-1)/double(2*jj) ;
150  break ;
151  default :
152  cerr << "Unknown type of basis in Domain_bispheric_rect::export_tau_val_domain_boundary_one_side_one_side" << endl ;
153  abort() ;
154  }
155  pos_galerkin = pos ;
156  pos_galerkin.set(1) = 0 ;
157  sec.set(pos_sec) = val_boundary (bound, so, pos) +
158  factor_galerkin * val_boundary (bound, so, pos_galerkin) ;
159  pos_sec ++ ;
160  }}
161  break ;
162  case SIN :
163  // Avoid sin(0)
164  if ((k!=0) && (k!=nbr_coefs(2)-1))
165  //Avoid last odd ones
166  if ((k%2!=1) || (j!=nbr_coefs(1)-2)) {
167  if (k%2==1) {
168  // The ones without regularity issues
169  sec.set(pos_sec) = val_boundary (bound, so, pos) ;
170  pos_sec ++ ;
171  }
172  else if (j!=0) {
173  // Regularity on the axis thanks to Galerkin
174  // Factor fo Galerkin different for Legendre or Chebyshev:
175  double factor_galerkin ;
176  switch (type_base) {
177  case CHEB_TYPE :
178  factor_galerkin = (j%2==1) ? -2. : 2. ;
179  break ;
180  case LEG_TYPE :
181  factor_galerkin = -double(4*j+1) ;
182  for (int jj=1 ; jj<=j ; jj++)
183  factor_galerkin *= -double(2*jj-1)/double(2*jj) ;
184  break ;
185  default :
186  cerr << "Unknown type of basis in Domain_bispheric_rect::export_tau_val_domain_boundary_one_side" << endl ;
187  abort() ;
188  }
189  pos_galerkin = pos ;
190  pos_galerkin.set(1) = 0 ;
191  sec.set(pos_sec) = val_boundary (bound, so, pos) +
192  factor_galerkin * val_boundary (bound, so, pos_galerkin) ;
193  pos_sec ++ ;
194  }}
195  break ;
196  default :
197  cerr << "Unknown base in Domain_bispheric_rect::export_tau_val_domain_boundary_one_side" << endl ;
198  break ;
199  }
200  }
201  }
202  }
203 
204  if (bound==CHI_ONE_BC) {
205  for (int k=0 ; k<nbr_coefs(2) ; k++) {
206  pos.set(2) = k ;
207  if ((basep==COS) || ((k!=0) && (k!=nbr_coefs(2)-1)))
208  for (int i=0 ; i<nbr_coefs(0)-1 ; i++) {
209  pos.set(0) = i ;
210  sec.set(pos_sec) = val_boundary (bound, so, pos) ;
211  pos_sec ++ ;
212  }
213  }
214  }
215 
216  if (bound==OUTER_BC) {
217  pos.set(1) = 0 ;
218  pos.set(0) = 0 ;
219  for (int k=0 ; k<nbr_coefs(2) ; k++) {
220  pos.set(2) = k ;
221  if ((basep==COS) || ((k!=0) && (k!=nbr_coefs(2)-1))) {
222  sec.set(pos_sec) = val_boundary (bound, so, pos) ;
223  pos_sec ++ ;
224  }
225  }
226  }
227  }
228 }
229 
230 void Domain_bispheric_rect::export_tau_boundary_one_side (const Tensor& tt, int dom, int bound, Array<double>& res, int& pos_res, const Array<int>& ncond,
231  int n_cmp, Array<int>** p_cmp) const {
232 
233  // Check boundary
234  if ((bound!=INNER_BC) && (bound!=ETA_PLUS_BC) && (bound!=CHI_ONE_BC) && (bound!=OUTER_BC)) {
235  cerr << "Unknown boundary in Domain_bispheric_rect::export_tau_boundary_one_side" << endl ;
236  abort() ;
237  }
238 
239  int val = tt.get_valence() ;
240  switch (val) {
241  case 0 :
242  export_tau_val_domain_boundary_one_side (tt()(dom), bound, res, pos_res, ncond(0)) ;
243  break ;
244  case 1 : {
245  bool found = false ;
246  // Cartesian basis
247  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
248  if (n_cmp==-1) {
249  export_tau_val_domain_boundary_one_side (tt(1)(dom), bound, res, pos_res, ncond(0)) ;
250  export_tau_val_domain_boundary_one_side (tt(2)(dom), bound, res, pos_res, ncond(1)) ;
251  export_tau_val_domain_boundary_one_side (tt(3)(dom), bound, res, pos_res, ncond(2)) ;
252  }
253  else for (int i=0 ; i<n_cmp ; i++) {
254  if ((*p_cmp[i])(0)==1)
255  export_tau_val_domain_boundary_one_side (tt(1)(dom), bound, res, pos_res, ncond(i)) ;
256  if ((*p_cmp[i])(0)==2)
257  export_tau_val_domain_boundary_one_side (tt(2)(dom), bound, res, pos_res, ncond(i)) ;
258  if ((*p_cmp[i])(0)==3)
259  export_tau_val_domain_boundary_one_side (tt(3)(dom), bound, res, pos_res, ncond(i)) ;
260  }
261  found = true ;
262  }
263  if (!found) {
264  cerr << "Unknown type of vector Domain_bispheric_rect::export_tau_boundary_one_side" << endl ;
265  abort() ;
266  }
267  }
268  break ;
269  case 2 : {
270  bool found = false ;
271  // Cartesian basis and symetric
272  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
273  if (n_cmp==-1) {
274  export_tau_val_domain_boundary_one_side (tt(1,1)(dom), bound, res, pos_res, ncond(0)) ;
275  export_tau_val_domain_boundary_one_side (tt(1,2)(dom), bound, res, pos_res, ncond(1)) ;
276  export_tau_val_domain_boundary_one_side (tt(1,3)(dom), bound, res, pos_res, ncond(2)) ;
277  export_tau_val_domain_boundary_one_side (tt(2,2)(dom), bound, res, pos_res, ncond(3)) ;
278  export_tau_val_domain_boundary_one_side (tt(2,3)(dom), bound, res, pos_res, ncond(4)) ;
279  export_tau_val_domain_boundary_one_side (tt(3,3)(dom), bound, res, pos_res, ncond(5)) ;
280  }
281  else for (int i=0 ; i<n_cmp ; i++) {
282  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
283  export_tau_val_domain_boundary_one_side (tt(1, 1)(dom), bound, res, pos_res, ncond(i)) ;
284  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
285  export_tau_val_domain_boundary_one_side (tt(1, 2)(dom), bound, res, pos_res, ncond(i)) ;
286  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
287  export_tau_val_domain_boundary_one_side (tt(1, 3)(dom), bound, res, pos_res, ncond(i)) ;
288  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
289  export_tau_val_domain_boundary_one_side (tt(2, 2)(dom), bound, res, pos_res, ncond(i)) ;
290  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
291  export_tau_val_domain_boundary_one_side (tt(2, 3)(dom), bound, res, pos_res, ncond(i)) ;
292  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
293  export_tau_val_domain_boundary_one_side (tt(3, 3)(dom), bound, res, pos_res, ncond(i)) ;
294  }
295  found = true ;
296  }
297  // Cartesian basis and not symetric
298  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
299  if (n_cmp==-1) {
300  export_tau_val_domain_boundary_one_side (tt(1,1)(dom), bound, res, pos_res, ncond(0)) ;
301  export_tau_val_domain_boundary_one_side (tt(1,2)(dom), bound, res, pos_res, ncond(1)) ;
302  export_tau_val_domain_boundary_one_side (tt(1,3)(dom), bound, res, pos_res, ncond(2)) ;
303  export_tau_val_domain_boundary_one_side (tt(2,1)(dom), bound, res, pos_res, ncond(3)) ;
304  export_tau_val_domain_boundary_one_side (tt(2,2)(dom), bound, res, pos_res, ncond(4)) ;
305  export_tau_val_domain_boundary_one_side (tt(2,3)(dom), bound, res, pos_res, ncond(5)) ;
306  export_tau_val_domain_boundary_one_side (tt(3,1)(dom), bound, res, pos_res, ncond(6)) ;
307  export_tau_val_domain_boundary_one_side (tt(3,2)(dom), bound, res, pos_res, ncond(7)) ;
308  export_tau_val_domain_boundary_one_side (tt(3,3)(dom), bound, res, pos_res, ncond(8)) ;
309 
310  }
311  else for (int i=0 ; i<n_cmp ; i++) {
312  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
313  export_tau_val_domain_boundary_one_side (tt(1, 1)(dom), bound, res, pos_res, ncond(i)) ;
314  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
315  export_tau_val_domain_boundary_one_side (tt(1, 2)(dom), bound, res, pos_res, ncond(i)) ;
316  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
317  export_tau_val_domain_boundary_one_side (tt(1, 3)(dom), bound, res, pos_res, ncond(i)) ;
318  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
319  export_tau_val_domain_boundary_one_side (tt(2, 1)(dom), bound, res, pos_res, ncond(i)) ;
320  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
321  export_tau_val_domain_boundary_one_side (tt(2, 2)(dom), bound, res, pos_res, ncond(i)) ;
322  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
323  export_tau_val_domain_boundary_one_side (tt(2, 3)(dom), bound, res, pos_res, ncond(i)) ;
324  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
325  export_tau_val_domain_boundary_one_side (tt(3, 1)(dom), bound, res, pos_res, ncond(i)) ;
326  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
327  export_tau_val_domain_boundary_one_side (tt(3, 2)(dom), bound, res, pos_res, ncond(i)) ;
328  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
329  export_tau_val_domain_boundary_one_side (tt(3, 3)(dom), bound, res, pos_res, ncond(i)) ;
330  }
331  found = true ;
332  }
333  if (!found) {
334  cerr << "Unknown type of 2-tensor Domain_bispheric_rect::export_tau_boundary_one_side" << endl ;
335  abort() ;
336  }
337  }
338  break ;
339  default :
340  cerr << "Valence " << val << " not implemented in Domain_bispheric_rect::export_tau_boundary_one_side" << endl ;
341  break ;
342  }
343 }}
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 double val_boundary(int, const Val_domain &, const Index &) const
Computes the value of a field at a boundary.
virtual void export_tau_boundary_one_side(const Tensor &, int, int, Array< double > &, int &, const Array< int > &, int n_cmp=-1, Array< int > **p_cmp=0x0) const
Exports all the residual equations corresponding to one tensorial one on a given boundary.
void export_tau_val_domain_boundary_one_side(const Val_domain &eq, int bound, Array< double > &res, int &pos_res, int ncond) const
Exports all the residual equations corresponding to a tensorial one on a given boundary,...
Dim_array nbr_coefs
Number of coefficients.
Definition: space.hpp:66
int type_base
Type of colocation point :
Definition: space.hpp:73
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
int & set(int i)
Read/write of the position in a given dimension.
Definition: index.hpp:72
Tensor handling.
Definition: tensor.hpp:149
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
bool check_if_zero() const
Check whether the logical state is zero or not.
Definition: val_domain.hpp:142
void coef() const
Computes the coefficients.
Definition: val_domain.cpp:622
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122