KADATH
domain_shell_symphi_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 "spheric_symphi.hpp"
22 #include "array_math.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
28 void Domain_shell_symphi::export_tau_val_domain_boundary (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  Index pos_cf (nbr_coefs) ;
35  Index pos_galerkin (nbr_coefs) ;
36 
37  int kmin, kmax ;
38  // Base in phi
39  int basep = (*so.get_base().bases_1d[2]) (0) ;
40  switch (basep) {
41  case COS_EVEN:
42  kmin = 0 ;
43  kmax = nbr_coefs(2)-1 ;
44  break ;
45  case COS_ODD:
46  kmin = 0 ;
47  kmax = nbr_coefs(2)-2 ;
48  break ;
49  case SIN_EVEN:
50  kmin = 1 ;
51  kmax = nbr_coefs(2)-2 ;
52  break ;
53  case SIN_ODD:
54  kmin = 0 ;
55  kmax = nbr_coefs(2)-2 ;
56  break ;
57  default:
58  cerr << "Unknow phi basis in Domain_shell_symphi::export_tau_val_domain" << endl ;
59  abort() ;
60  }
61 
62  // Loop on phi :
63  for (int k=kmin ; k<=kmax ; k++) {
64  pos_cf.set(2) = k ;
65  // Loop on theta
66  int baset = (*so.get_base().bases_1d[1]) (k) ;
67 
68 
69  int mquant ;
70 
71  switch (basep) {
72  case COS_EVEN:
73  mquant = 2*k ;
74  break ;
75  case COS_ODD:
76  mquant = 2*k+1 ;
77  break ;
78  case SIN_EVEN:
79  mquant = 2*k ;
80  break ;
81  case SIN_ODD:
82  mquant = 2*k+1 ;
83  break ;
84  default:
85  cerr << "Unknow phi basis in Domain_shell_symphi::export_tau_val_domain" << endl ;
86  abort() ;
87  }
88 
89  for (int j=0 ; j<nbr_coefs(1) ; j++) {
90  pos_cf.set(1) = j ;
91  switch (baset) {
92  case COS_EVEN:
93  if (mquant==0) {
94  sec.set(pos_sec) = val_boundary(bound, so, pos_cf) ;
95  pos_sec ++ ;
96  }
97  else if (j!=0) {
98  // Galerkin base
99  pos_galerkin = pos_cf ;
100  pos_galerkin.set(1) = 0 ;
101  sec.set(pos_sec) = val_boundary(bound, so, pos_cf)
102  -2.*val_boundary(bound, so, pos_galerkin) ;
103  pos_sec ++ ;
104  }
105  break ;
106  case COS_ODD:
107  if (j!=nbr_coefs(1)-1) {
108  if (mquant==0) {
109  sec.set(pos_sec) = val_boundary(bound, so, pos_cf) ;
110  pos_sec ++ ;
111  }
112  else if (j!=0) {
113  // Galerkin base
114  pos_galerkin = pos_cf ;
115  pos_galerkin.set(1) = 0 ;
116  sec.set(pos_sec) = val_boundary(bound, so, pos_cf)
117  -val_boundary(bound, so, pos_galerkin) ;
118  pos_sec ++ ;
119  }}
120  break ;
121  case SIN_EVEN:
122  if ((j!=0) && (j!=nbr_coefs(1)-1)) {
123  if (mquant<=1) {
124  sec.set(pos_sec) = val_boundary(bound, so, pos_cf) ;
125  pos_sec ++ ;
126  }
127  else if (j!=1) {
128  // Galerkin base
129  // Galerkin base
130  pos_galerkin = pos_cf ;
131  pos_galerkin.set(1) = 1 ;
132  sec.set(pos_sec) = val_boundary(bound, so, pos_cf)
133  -j*val_boundary(bound, so, pos_galerkin) ;
134  pos_sec ++ ;
135  }
136  }
137  break ;
138  case SIN_ODD:
139  if (j!=nbr_coefs(1)-1) {
140  if (mquant<=1) {
141  sec.set(pos_sec) = val_boundary(bound, so, pos_cf) ;
142  pos_sec ++ ;
143  }
144  else if (j!=0) {
145  // Galerkin base
146  pos_galerkin = pos_cf ;
147  pos_galerkin.set(1) = 0 ;
148  sec.set(pos_sec) = val_boundary(bound, so, pos_cf)
149  -(2*j+1)*val_boundary(bound, so, pos_galerkin) ;
150  pos_sec ++ ;
151  }}
152  break ;
153  default:
154  cerr << "Unknow theta basis in Domain_shell_symphi::export_tau_val_domain_boundary" << endl ;
155  abort() ;
156  }
157  }
158  }
159  }
160 }
161 
162 void Domain_shell_symphi::export_tau_boundary (const Tensor& tt, int dom, int bound, Array<double>& res, int& pos_res, const Array<int>& ncond,
163  int n_cmp, Array<int>** p_cmp) const {
164 
165  // Check boundary
166  if ((bound!=OUTER_BC) && (bound!=INNER_BC)) {
167  cerr << "Unknown boundary in Domain_shell_symphi::export_tau_boundary" << endl ;
168  abort() ;
169  }
170 
171  int val = tt.get_valence() ;
172  switch (val) {
173  case 0 :
174  export_tau_val_domain_boundary (tt()(dom), bound, res, pos_res, ncond(0)) ;
175  break ;
176  case 1 : {
177  bool found = false ;
178  // Cartesian basis
179  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
180  if (n_cmp==-1) {
181  export_tau_val_domain_boundary (tt(1)(dom), bound, res, pos_res, ncond(0)) ;
182  export_tau_val_domain_boundary (tt(2)(dom), bound, res, pos_res, ncond(1)) ;
183  export_tau_val_domain_boundary (tt(3)(dom), bound, res, pos_res, ncond(2)) ;
184  }
185  else for (int i=0 ; i<n_cmp ; i++) {
186  if ((*p_cmp[i])(0)==1)
187  export_tau_val_domain_boundary (tt(1)(dom), bound, res, pos_res, ncond(i)) ;
188  if ((*p_cmp[i])(0)==2)
189  export_tau_val_domain_boundary (tt(2)(dom), bound, res, pos_res, ncond(i)) ;
190  if ((*p_cmp[i])(0)==3)
191  export_tau_val_domain_boundary (tt(3)(dom), bound, res, pos_res, ncond(i)) ;
192  }
193  found = true ;
194  }
195 
196  if (!found) {
197  cerr << "Unknown type of vector Domain_shell_symphi::export_tau_boundary" << endl ;
198  abort() ;
199  }
200  }
201  break ;
202  case 2 : {
203  bool found = false ;
204  // Cartesian basis and symetric
205  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
206  if (n_cmp==-1) {
207  export_tau_val_domain_boundary (tt(1,1)(dom), bound, res, pos_res, ncond(0)) ;
208  export_tau_val_domain_boundary (tt(1,2)(dom), bound, res, pos_res, ncond(1)) ;
209  export_tau_val_domain_boundary (tt(1,3)(dom), bound, res, pos_res, ncond(2)) ;
210  export_tau_val_domain_boundary (tt(2,2)(dom), bound, res, pos_res, ncond(3)) ;
211  export_tau_val_domain_boundary (tt(2,3)(dom), bound, res, pos_res, ncond(4)) ;
212  export_tau_val_domain_boundary (tt(3,3)(dom), bound, res, pos_res, ncond(5)) ;
213  }
214  else for (int i=0 ; i<n_cmp ; i++) {
215  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
216  export_tau_val_domain_boundary (tt(1, 1)(dom), bound, res, pos_res, ncond(i)) ;
217  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
218  export_tau_val_domain_boundary (tt(1, 2)(dom), bound, res, pos_res, ncond(i)) ;
219  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
220  export_tau_val_domain_boundary (tt(1, 3)(dom), bound, res, pos_res, ncond(i)) ;
221  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
222  export_tau_val_domain_boundary (tt(2, 2)(dom), bound, res, pos_res, ncond(i)) ;
223  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
224  export_tau_val_domain_boundary (tt(2, 3)(dom), bound, res, pos_res, ncond(i)) ;
225  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
226  export_tau_val_domain_boundary (tt(3, 3)(dom), bound, res, pos_res, ncond(i)) ;
227  }
228  found = true ;
229  }
230  // Cartesian basis and not symetric
231  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
232  if (n_cmp==-1) {
233  export_tau_val_domain_boundary (tt(1,1)(dom), bound, res, pos_res, ncond(0)) ;
234  export_tau_val_domain_boundary (tt(1,2)(dom), bound, res, pos_res, ncond(1)) ;
235  export_tau_val_domain_boundary (tt(1,3)(dom), bound, res, pos_res, ncond(2)) ;
236  export_tau_val_domain_boundary (tt(2,1)(dom), bound, res, pos_res, ncond(3)) ;
237  export_tau_val_domain_boundary (tt(2,2)(dom), bound, res, pos_res, ncond(4)) ;
238  export_tau_val_domain_boundary (tt(2,3)(dom), bound, res, pos_res, ncond(5)) ;
239  export_tau_val_domain_boundary (tt(3,1)(dom), bound, res, pos_res, ncond(6)) ;
240  export_tau_val_domain_boundary (tt(3,2)(dom), bound, res, pos_res, ncond(7)) ;
241  export_tau_val_domain_boundary (tt(3,3)(dom), bound, res, pos_res, ncond(8)) ;
242 
243  }
244  else for (int i=0 ; i<n_cmp ; i++) {
245  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
246  export_tau_val_domain_boundary (tt(1, 1)(dom), bound, res, pos_res, ncond(i)) ;
247  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
248  export_tau_val_domain_boundary (tt(1, 2)(dom), bound, res, pos_res, ncond(i)) ;
249  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
250  export_tau_val_domain_boundary (tt(1, 3)(dom), bound, res, pos_res, ncond(i)) ;
251  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
252  export_tau_val_domain_boundary (tt(2, 1)(dom), bound, res, pos_res, ncond(i)) ;
253  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
254  export_tau_val_domain_boundary (tt(2, 2)(dom), bound, res, pos_res, ncond(i)) ;
255  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
256  export_tau_val_domain_boundary (tt(2, 3)(dom), bound, res, pos_res, ncond(i)) ;
257  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
258  export_tau_val_domain_boundary (tt(3, 1)(dom), bound, res, pos_res, ncond(i)) ;
259  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
260  export_tau_val_domain_boundary (tt(3, 2)(dom), bound, res, pos_res, ncond(i)) ;
261  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
262  export_tau_val_domain_boundary (tt(3, 3)(dom), bound, res, pos_res, ncond(i)) ;
263  }
264  found = true ;
265  }
266  if (!found) {
267  cerr << "Unknown type of 2-tensor Domain_shell_symphi::export_tau_boundary" << endl ;
268  abort() ;
269  }
270  }
271  break ;
272  default :
273  cerr << "Valence " << val << " not implemented in Domain_shell_symphi::export_tau_boundary" << endl ;
274  break ;
275  }
276 }}
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
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