KADATH
domain_bispheric_eta_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_eta_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==ETA_MINUS_BC) || (bound==ETA_PLUS_BC)) {
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 i=0 ; i<nbr_coefs(0)-1 ; i++) {
45  pos.set(0) = i ;
46  switch (basep) {
47  case COS :
48  // Avoid last odd ones
49  if ((k%2!=1) || (i!=nbr_coefs(1)-2)) {
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 (i!=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 = (i%2==1) ? -2. : 2. ;
62  break ;
63  case LEG_TYPE :
64  factor_galerkin = -double(4*i+1) ;
65  for (int ii=1 ; ii<=i ; ii++)
66  factor_galerkin *= -double(2*ii-1)/double(2*ii) ;
67  break ;
68  default :
69  cerr << "Unknown type of basis in Domain_bispheric_eta_first::export_tau_val_domain_boundary_one_side" << endl ;
70  abort() ;
71  }
72  pos_galerkin = pos ;
73  pos_galerkin.set(0) = 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) || (i!=nbr_coefs(1)-2)) {
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 (i!=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 = (i%2==1) ? -2. : 2. ;
96  break ;
97  case LEG_TYPE :
98  factor_galerkin = -double(4*i+1) ;
99  for (int ii=1 ; ii<=i ; ii++)
100  factor_galerkin *= -double(2*ii-1)/double(2*ii) ;
101  break ;
102  default :
103  cerr << "Unknown type of basis in Domain_bispheric_eta_first::export_tau_val_domain_boundary_one_side" << endl ;
104  abort() ;
105  }
106  pos_galerkin = pos ;
107  pos_galerkin.set(0) = 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_eta_first::export_tau_val_domain_boundary_one_side" << endl ;
115  break ;
116  }
117  }
118  }
119  }
120 
121  if (bound==OUTER_BC) {
122  for (int k=0 ; k<nbr_coefs(2) ; k++) {
123  pos.set(2) = k ;
124  if ((basep==COS) || ((k!=0) && (k!=nbr_coefs(2)-1)))
125  for (int j=0 ; j<nbr_coefs(1) ; j++) {
126  pos.set(1) = j ;
127  sec.set(pos_sec) = val_boundary (bound, so, pos) ;
128  pos_sec ++ ;
129  }
130  }
131  }
132  }
133 }
134 
135 void Domain_bispheric_eta_first::export_tau_boundary_one_side (const Tensor& tt, int dom, int bound, Array<double>& res, int& pos_res, const Array<int>& ncond,
136  int n_cmp, Array<int>** p_cmp) const {
137 
138  // Check boundary
139  if ((bound!=ETA_MINUS_BC) && (bound!=ETA_PLUS_BC) && (bound!=OUTER_BC)) {
140  cerr << "Unknown boundary in Domain_bispheric_eta_first::export_tau_boundary_one_side" << endl ;
141  abort() ;
142  }
143 
144  int val = tt.get_valence() ;
145  switch (val) {
146  case 0 :
147  export_tau_val_domain_boundary_one_side (tt()(dom), bound, res, pos_res, ncond(0)) ;
148  break ;
149  case 1 : {
150  bool found = false ;
151  // Cartesian basis
152  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
153  if (n_cmp==-1) {
154  export_tau_val_domain_boundary_one_side (tt(1)(dom), bound, res, pos_res, ncond(0)) ;
155  export_tau_val_domain_boundary_one_side (tt(2)(dom), bound, res, pos_res, ncond(1)) ;
156  export_tau_val_domain_boundary_one_side (tt(3)(dom), bound, res, pos_res, ncond(2)) ;
157  }
158  else for (int i=0 ; i<n_cmp ; i++) {
159  if ((*p_cmp[i])(0)==1)
160  export_tau_val_domain_boundary_one_side (tt(1)(dom), bound, res, pos_res, ncond(i)) ;
161  if ((*p_cmp[i])(0)==2)
162  export_tau_val_domain_boundary_one_side (tt(2)(dom), bound, res, pos_res, ncond(i)) ;
163  if ((*p_cmp[i])(0)==3)
164  export_tau_val_domain_boundary_one_side (tt(3)(dom), bound, res, pos_res, ncond(i)) ;
165  }
166  found = true ;
167  }
168  if (!found) {
169  cerr << "Unknown type of vector Domain_bispheric_eta_first::export_tau_boundary_one_side" << endl ;
170  abort() ;
171  }
172  }
173  break ;
174  case 2 : {
175  bool found = false ;
176  // Cartesian basis and symetric
177  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
178  if (n_cmp==-1) {
179  export_tau_val_domain_boundary_one_side (tt(1,1)(dom), bound, res, pos_res, ncond(0)) ;
180  export_tau_val_domain_boundary_one_side (tt(1,2)(dom), bound, res, pos_res, ncond(1)) ;
181  export_tau_val_domain_boundary_one_side (tt(1,3)(dom), bound, res, pos_res, ncond(2)) ;
182  export_tau_val_domain_boundary_one_side (tt(2,2)(dom), bound, res, pos_res, ncond(3)) ;
183  export_tau_val_domain_boundary_one_side (tt(2,3)(dom), bound, res, pos_res, ncond(4)) ;
184  export_tau_val_domain_boundary_one_side (tt(3,3)(dom), bound, res, pos_res, ncond(5)) ;
185  }
186  else for (int i=0 ; i<n_cmp ; i++) {
187  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
188  export_tau_val_domain_boundary_one_side (tt(1, 1)(dom), bound, res, pos_res, ncond(i)) ;
189  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
190  export_tau_val_domain_boundary_one_side (tt(1, 2)(dom), bound, res, pos_res, ncond(i)) ;
191  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
192  export_tau_val_domain_boundary_one_side (tt(1, 3)(dom), bound, res, pos_res, ncond(i)) ;
193  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
194  export_tau_val_domain_boundary_one_side (tt(2, 2)(dom), bound, res, pos_res, ncond(i)) ;
195  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
196  export_tau_val_domain_boundary_one_side (tt(2, 3)(dom), bound, res, pos_res, ncond(i)) ;
197  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
198  export_tau_val_domain_boundary_one_side (tt(3, 3)(dom), bound, res, pos_res, ncond(i)) ;
199  }
200  found = true ;
201  }
202  // Cartesian basis and not symetric
203  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
204  if (n_cmp==-1) {
205  export_tau_val_domain_boundary_one_side (tt(1,1)(dom), bound, res, pos_res, ncond(0)) ;
206  export_tau_val_domain_boundary_one_side (tt(1,2)(dom), bound, res, pos_res, ncond(1)) ;
207  export_tau_val_domain_boundary_one_side (tt(1,3)(dom), bound, res, pos_res, ncond(2)) ;
208  export_tau_val_domain_boundary_one_side (tt(2,1)(dom), bound, res, pos_res, ncond(3)) ;
209  export_tau_val_domain_boundary_one_side (tt(2,2)(dom), bound, res, pos_res, ncond(4)) ;
210  export_tau_val_domain_boundary_one_side (tt(2,3)(dom), bound, res, pos_res, ncond(5)) ;
211  export_tau_val_domain_boundary_one_side (tt(3,1)(dom), bound, res, pos_res, ncond(6)) ;
212  export_tau_val_domain_boundary_one_side (tt(3,2)(dom), bound, res, pos_res, ncond(7)) ;
213  export_tau_val_domain_boundary_one_side (tt(3,3)(dom), bound, res, pos_res, ncond(8)) ;
214 
215  }
216  else for (int i=0 ; i<n_cmp ; i++) {
217  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
218  export_tau_val_domain_boundary_one_side (tt(1, 1)(dom), bound, res, pos_res, ncond(i)) ;
219  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
220  export_tau_val_domain_boundary_one_side (tt(1, 2)(dom), bound, res, pos_res, ncond(i)) ;
221  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
222  export_tau_val_domain_boundary_one_side (tt(1, 3)(dom), bound, res, pos_res, ncond(i)) ;
223  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
224  export_tau_val_domain_boundary_one_side (tt(2, 1)(dom), bound, res, pos_res, ncond(i)) ;
225  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
226  export_tau_val_domain_boundary_one_side (tt(2, 2)(dom), bound, res, pos_res, ncond(i)) ;
227  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
228  export_tau_val_domain_boundary_one_side (tt(2, 3)(dom), bound, res, pos_res, ncond(i)) ;
229  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
230  export_tau_val_domain_boundary_one_side (tt(3, 1)(dom), bound, res, pos_res, ncond(i)) ;
231  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
232  export_tau_val_domain_boundary_one_side (tt(3, 2)(dom), bound, res, pos_res, ncond(i)) ;
233  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
234  export_tau_val_domain_boundary_one_side (tt(3, 3)(dom), bound, res, pos_res, ncond(i)) ;
235  }
236  found = true ;
237  }
238  if (!found) {
239  cerr << "Unknown type of 2-tensor Domain_bispheric_eta_first::export_tau_boundary_one_side" << endl ;
240  abort() ;
241  }
242  }
243  break ;
244  default :
245  cerr << "Valence " << val << " not implemented in Domain_bispheric_eta_first::export_tau_boundary_one_side" << endl ;
246  break ;
247  }
248 }
249 }
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 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.
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