KADATH
domain_bispheric_chi_first_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_chi_first::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) || (bound==OUTER_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_chi_first::export_tau_val_domain_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) and last one
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_chi_first::export_tau_val_domain_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_chi_first::export_tau_val_domain_boundary_one_side" << endl ;
116  break ;
117  }
118  }
119  }
120  }
121 
122  if (bound==CHI_ONE_BC) {
123  for (int k=0 ; k<nbr_coefs(2) ; k++) {
124  pos.set(2) = k ;
125  if ((basep==COS) || ((k!=0) && (k!=nbr_coefs(2)-1)))
126  for (int i=0 ; i<nbr_coefs(0)-1 ; i++) {
127  pos.set(0) = i ;
128  sec.set(pos_sec) = val_boundary (bound, so, pos) ;
129  pos_sec ++ ;
130  }
131  }
132  }
133  }
134 }
135 
136 void Domain_bispheric_chi_first::export_tau_boundary_one_side (const Tensor& tt, int dom, int bound, Array<double>& res, int& pos_res, const Array<int>& ncond,
137  int n_cmp, Array<int>** p_cmp) const {
138 
139  // Check boundary
140  if ((bound!=INNER_BC) && (bound!=CHI_ONE_BC) && (bound!=OUTER_BC)) {
141  cerr << "Unknown boundary in Domain_bispheric_chi_first::export_tau_boundary_one_side" << endl ;
142  abort() ;
143  }
144 
145  int val = tt.get_valence() ;
146  switch (val) {
147  case 0 :
148  export_tau_val_domain_boundary_one_side (tt()(dom), bound, res, pos_res, ncond(0)) ;
149  break ;
150  case 1 : {
151  bool found = false ;
152  // Cartesian basis
153  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
154  if (n_cmp==-1) {
155  export_tau_val_domain_boundary_one_side (tt(1)(dom), bound, res, pos_res, ncond(0)) ;
156  export_tau_val_domain_boundary_one_side (tt(2)(dom), bound, res, pos_res, ncond(1)) ;
157  export_tau_val_domain_boundary_one_side (tt(3)(dom), bound, res, pos_res, ncond(2)) ;
158  }
159  else for (int i=0 ; i<n_cmp ; i++) {
160  if ((*p_cmp[i])(0)==1)
161  export_tau_val_domain_boundary_one_side (tt(1)(dom), bound, res, pos_res, ncond(i)) ;
162  if ((*p_cmp[i])(0)==2)
163  export_tau_val_domain_boundary_one_side (tt(2)(dom), bound, res, pos_res, ncond(i)) ;
164  if ((*p_cmp[i])(0)==3)
165  export_tau_val_domain_boundary_one_side (tt(3)(dom), bound, res, pos_res, ncond(i)) ;
166  }
167  found = true ;
168  }
169  if (!found) {
170  cerr << "Unknown type of vector Domain_bispheric_chi_first::export_tau_boundary_one_side" << endl ;
171  abort() ;
172  }
173  }
174  break ;
175  case 2 : {
176  bool found = false ;
177  // Cartesian basis and symetric
178  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
179  if (n_cmp==-1) {
180  export_tau_val_domain_boundary_one_side (tt(1,1)(dom), bound, res, pos_res, ncond(0)) ;
181  export_tau_val_domain_boundary_one_side (tt(1,2)(dom), bound, res, pos_res, ncond(1)) ;
182  export_tau_val_domain_boundary_one_side (tt(1,3)(dom), bound, res, pos_res, ncond(2)) ;
183  export_tau_val_domain_boundary_one_side (tt(2,2)(dom), bound, res, pos_res, ncond(3)) ;
184  export_tau_val_domain_boundary_one_side (tt(2,3)(dom), bound, res, pos_res, ncond(4)) ;
185  export_tau_val_domain_boundary_one_side (tt(3,3)(dom), bound, res, pos_res, ncond(5)) ;
186  }
187  else for (int i=0 ; i<n_cmp ; i++) {
188  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
189  export_tau_val_domain_boundary_one_side (tt(1, 1)(dom), bound, res, pos_res, ncond(i)) ;
190  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
191  export_tau_val_domain_boundary_one_side (tt(1, 2)(dom), bound, res, pos_res, ncond(i)) ;
192  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
193  export_tau_val_domain_boundary_one_side (tt(1, 3)(dom), bound, res, pos_res, ncond(i)) ;
194  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
195  export_tau_val_domain_boundary_one_side (tt(2, 2)(dom), bound, res, pos_res, ncond(i)) ;
196  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
197  export_tau_val_domain_boundary_one_side (tt(2, 3)(dom), bound, res, pos_res, ncond(i)) ;
198  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
199  export_tau_val_domain_boundary_one_side (tt(3, 3)(dom), bound, res, pos_res, ncond(i)) ;
200  }
201  found = true ;
202  }
203  // Cartesian basis and not symetric
204  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
205  if (n_cmp==-1) {
206  export_tau_val_domain_boundary_one_side (tt(1,1)(dom), bound, res, pos_res, ncond(0)) ;
207  export_tau_val_domain_boundary_one_side (tt(1,2)(dom), bound, res, pos_res, ncond(1)) ;
208  export_tau_val_domain_boundary_one_side (tt(1,3)(dom), bound, res, pos_res, ncond(2)) ;
209  export_tau_val_domain_boundary_one_side (tt(2,1)(dom), bound, res, pos_res, ncond(3)) ;
210  export_tau_val_domain_boundary_one_side (tt(2,2)(dom), bound, res, pos_res, ncond(4)) ;
211  export_tau_val_domain_boundary_one_side (tt(2,3)(dom), bound, res, pos_res, ncond(5)) ;
212  export_tau_val_domain_boundary_one_side (tt(3,1)(dom), bound, res, pos_res, ncond(6)) ;
213  export_tau_val_domain_boundary_one_side (tt(3,2)(dom), bound, res, pos_res, ncond(7)) ;
214  export_tau_val_domain_boundary_one_side (tt(3,3)(dom), bound, res, pos_res, ncond(8)) ;
215 
216  }
217  else for (int i=0 ; i<n_cmp ; i++) {
218  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
219  export_tau_val_domain_boundary_one_side (tt(1, 1)(dom), bound, res, pos_res, ncond(i)) ;
220  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
221  export_tau_val_domain_boundary_one_side (tt(1, 2)(dom), bound, res, pos_res, ncond(i)) ;
222  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
223  export_tau_val_domain_boundary_one_side (tt(1, 3)(dom), bound, res, pos_res, ncond(i)) ;
224  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
225  export_tau_val_domain_boundary_one_side (tt(2, 1)(dom), bound, res, pos_res, ncond(i)) ;
226  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
227  export_tau_val_domain_boundary_one_side (tt(2, 2)(dom), bound, res, pos_res, ncond(i)) ;
228  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
229  export_tau_val_domain_boundary_one_side (tt(2, 3)(dom), bound, res, pos_res, ncond(i)) ;
230  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
231  export_tau_val_domain_boundary_one_side (tt(3, 1)(dom), bound, res, pos_res, ncond(i)) ;
232  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
233  export_tau_val_domain_boundary_one_side (tt(3, 2)(dom), bound, res, pos_res, ncond(i)) ;
234  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
235  export_tau_val_domain_boundary_one_side (tt(3, 3)(dom), bound, res, pos_res, ncond(i)) ;
236  }
237  found = true ;
238  }
239  if (!found) {
240  cerr << "Unknown type of 2-tensor Domain_bispheric_chi_first::export_tau_boundary_one_side" << endl ;
241  abort() ;
242  }
243  }
244  break ;
245  default :
246  cerr << "Valence " << val << " not implemented in Domain_bispheric_chi_first::export_tau_boundary_one_side" << endl ;
247  break ;
248  }
249 }
250 }
251 
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
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,...
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.
virtual double val_boundary(int, const Val_domain &, const Index &) const
Computes the value of a field at a 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