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