KADATH
domain_shell_outer_adapted_export_tau.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 "adapted.hpp"
22 #include "point.hpp"
23 #include "array_math.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "tensor.hpp"
27 
28 namespace Kadath {
29 void Domain_shell_outer_adapted::export_tau_val_domain (const Val_domain& so, int mlim, int order, Array<double>& sec, int& pos_sec, int ncond) const {
30 
31  if (so.check_if_zero())
32  pos_sec += ncond ;
33  else {
34 
35  so.coef() ;
36  int kmin = 2*mlim + 2 ;
37  Index pos_cf (nbr_coefs) ;
38  Index pos_galerkin (nbr_coefs) ;
39 
40  // Loop on phi :
41  for (int k=0 ; k<nbr_coefs(2)-1 ; k++)
42  if (k!=1) {
43  pos_cf.set(2) = k ;
44  // Loop on theta
45  int baset = (*so.get_base().bases_1d[1]) (k) ;
46  for (int j=0 ; j<nbr_coefs(1) ; j++) {
47  pos_cf.set(1) = j ;
48  // Loop on r :
49  for (int i=0 ; i<nbr_coefs(0)-order ; i++) {
50  pos_cf.set(0) = i ;
51  switch (baset) {
52  case COS_EVEN:
53  if (k<kmin) {
54  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
55  pos_sec ++ ;
56  }
57  else if (j!=0) {
58  // Galerkin base
59  pos_galerkin = pos_cf ;
60  pos_galerkin.set(1) = 0 ;
61  sec.set(pos_sec) = (*so.cf)(pos_cf)
62  -2*(*so.cf)(pos_galerkin) ;
63  pos_sec ++ ;
64  }
65  break ;
66  case COS_ODD:
67  if (j!=nbr_coefs(1)-1) {
68  if (k<kmin) {
69  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
70  pos_sec ++ ;
71  }
72  else if (j!=0) {
73  // Galerkin base
74  pos_galerkin = pos_cf ;
75  pos_galerkin.set(1) = 0 ;
76  sec.set(pos_sec) = (*so.cf)(pos_cf)
77  -(*so.cf)(pos_galerkin) ;
78  pos_sec ++ ;
79  }
80  }
81  break ;
82  case SIN_EVEN:
83  if ((j!=0) && (j!=nbr_coefs(1)-1)) {
84  if (k<kmin+2) {
85  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
86  pos_sec ++ ;
87  }
88  else if (j!=1) {
89  // Galerkin
90  pos_galerkin = pos_cf ;
91  pos_galerkin.set(1) = 1 ;
92  sec.set(pos_sec) = (*so.cf)(pos_cf)
93  -j*(*so.cf)(pos_galerkin) ;
94  pos_sec ++ ;
95  }
96  }
97  break ;
98  case SIN_ODD:
99  if (j!=nbr_coefs(1)-1) {
100  if (k<kmin+2) {
101  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
102  pos_sec ++ ;
103  }
104  else if (j!=0) {
105  // Galerkin
106  pos_galerkin = pos_cf ;
107  pos_galerkin.set(1) = 0 ;
108  sec.set(pos_sec) = (*so.cf)(pos_cf)
109  -(2*j+1)*(*so.cf)(pos_galerkin) ;
110  pos_sec ++ ;
111  }
112  }
113  break ;
114  default:
115  cerr << "Unknow theta basis in Domain_shell_outer_adapted::export_tau_val_domain" << endl ;
116  abort() ;
117  }
118  }
119  }
120  }
121  }
122 }
123 
124 void Domain_shell_outer_adapted::export_tau (const Tensor& tt, int dom, int order, Array<double>& res, int& pos_res, const Array<int>& ncond,
125  int n_cmp, Array<int>** p_cmp) const {
126  int val = tt.get_valence() ;
127  switch (val) {
128  case 0 :
129  if (!tt.is_m_order_affected())
130  export_tau_val_domain (tt()(dom), 0, order, res, pos_res, ncond(0)) ;
131  else
132  export_tau_val_domain (tt()(dom), tt.get_parameters().get_m_order(), order, res, pos_res, ncond(0)) ;
133  break ;
134  case 1 : {
135  bool found = false ;
136  // Cartesian basis
137  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
138  if (n_cmp==-1) {
139  export_tau_val_domain (tt(1)(dom), 0, order, res, pos_res, ncond(0)) ;
140  export_tau_val_domain (tt(2)(dom), 0, order, res, pos_res, ncond(1)) ;
141  export_tau_val_domain (tt(3)(dom), 0, order, res, pos_res, ncond(2)) ;
142  }
143  else for (int i=0 ; i<n_cmp ; i++) {
144  if ((*p_cmp[i])(0)==1)
145  export_tau_val_domain (tt(1)(dom), 0, order, res, pos_res, ncond(i)) ;
146  if ((*p_cmp[i])(0)==2)
147  export_tau_val_domain (tt(2)(dom), 0, order, res, pos_res, ncond(i)) ;
148  if ((*p_cmp[i])(0)==3)
149  export_tau_val_domain (tt(3)(dom), 0, order, res, pos_res, ncond(i)) ;
150  }
151  found = true ;
152  }
153  // Spherical coordinates
154  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
155  if (n_cmp==-1) {
156  export_tau_val_domain (tt(1)(dom), 0, order, res, pos_res, ncond(0)) ;
157  export_tau_val_domain (tt(2)(dom), 1, order, res, pos_res, ncond(1)) ;
158  export_tau_val_domain (tt(3)(dom), 1, order, res, pos_res, ncond(2)) ;
159  }
160  else for (int i=0 ; i<n_cmp ; i++) {
161  if ((*p_cmp[i])(0)==1)
162  export_tau_val_domain (tt(1)(dom), 0, order, res, pos_res, ncond(i)) ;
163  if ((*p_cmp[i])(0)==2)
164  export_tau_val_domain (tt(2)(dom), 1, order, res, pos_res, ncond(i)) ;
165  if ((*p_cmp[i])(0)==3)
166  export_tau_val_domain (tt(3)(dom), 1, order, res, pos_res, ncond(i)) ;
167  }
168  found = true ;
169  }
170  if (!found) {
171  cerr << "Unknown type of vector Domain_shell_outer_adapted::export_tau" << endl ;
172  abort() ;
173  }
174  }
175  break ;
176  case 2 : {
177  bool found = false ;
178  // Cartesian basis and symetric
179  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
180  if (n_cmp==-1) {
181  export_tau_val_domain (tt(1,1)(dom), 0, order, res, pos_res, ncond(0)) ;
182  export_tau_val_domain (tt(1,2)(dom), 0, order, res, pos_res, ncond(1)) ;
183  export_tau_val_domain (tt(1,3)(dom), 0, order, res, pos_res, ncond(2)) ;
184  export_tau_val_domain (tt(2,2)(dom), 0, order, res, pos_res, ncond(3)) ;
185  export_tau_val_domain (tt(2,3)(dom), 0, order, res, pos_res, ncond(4)) ;
186  export_tau_val_domain (tt(3,3)(dom), 0, order, res, pos_res, ncond(5)) ;
187  }
188  else for (int i=0 ; i<n_cmp ; i++) {
189  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
190  export_tau_val_domain (tt(1, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
191  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
192  export_tau_val_domain (tt(1, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
193  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
194  export_tau_val_domain (tt(1, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
195  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
196  export_tau_val_domain (tt(2, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
197  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
198  export_tau_val_domain (tt(2, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
199  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
200  export_tau_val_domain (tt(3, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
201  }
202  found = true ;
203  }
204  // Cartesian basis and not symetric
205  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
206  if (n_cmp==-1) {
207  export_tau_val_domain (tt(1,1)(dom), 0, order, res, pos_res, ncond(0)) ;
208  export_tau_val_domain (tt(1,2)(dom), 0, order, res, pos_res, ncond(1)) ;
209  export_tau_val_domain (tt(1,3)(dom), 0, order, res, pos_res, ncond(2)) ;
210  export_tau_val_domain (tt(2,1)(dom), 0, order, res, pos_res, ncond(3)) ;
211  export_tau_val_domain (tt(2,2)(dom), 0, order, res, pos_res, ncond(4)) ;
212  export_tau_val_domain (tt(2,3)(dom), 0, order, res, pos_res, ncond(5)) ;
213  export_tau_val_domain (tt(3,1)(dom), 0, order, res, pos_res, ncond(6)) ;
214  export_tau_val_domain (tt(3,2)(dom), 0, order, res, pos_res, ncond(7)) ;
215  export_tau_val_domain (tt(3,3)(dom), 0, order, res, pos_res, ncond(8)) ;
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 (tt(1, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
220  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
221  export_tau_val_domain (tt(1, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
222  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
223  export_tau_val_domain (tt(1, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
224  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
225  export_tau_val_domain (tt(2, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
226  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
227  export_tau_val_domain (tt(2, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
228  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
229  export_tau_val_domain (tt(2, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
230  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
231  export_tau_val_domain (tt(3, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
232  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
233  export_tau_val_domain (tt(3, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
234  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
235  export_tau_val_domain (tt(3, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
236  }
237  found = true ;
238  }
239  // Spherical coordinates and not symetric
240  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
241  if (n_cmp==-1) {
242  export_tau_val_domain (tt(1,1)(dom), 0, order, res, pos_res, ncond(0)) ;
243  export_tau_val_domain (tt(1,2)(dom), 1, order, res, pos_res, ncond(1)) ;
244  export_tau_val_domain (tt(1,3)(dom), 1, order, res, pos_res, ncond(2)) ;
245  export_tau_val_domain (tt(2,1)(dom), 1, order, res, pos_res, ncond(3)) ;
246  export_tau_val_domain (tt(2,2)(dom), 2, order, res, pos_res, ncond(4)) ;
247  export_tau_val_domain (tt(2,3)(dom), 2, order, res, pos_res, ncond(5)) ;
248  export_tau_val_domain (tt(3,1)(dom), 1, order, res, pos_res, ncond(6)) ;
249  export_tau_val_domain (tt(3,2)(dom), 2, order, res, pos_res, ncond(7)) ;
250  export_tau_val_domain (tt(3,3)(dom), 2, order, res, pos_res, ncond(8)) ;
251  }
252  else for (int i=0 ; i<n_cmp ; i++) {
253  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
254  export_tau_val_domain (tt(1, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
255  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
256  export_tau_val_domain (tt(1, 2)(dom), 1, order, res, pos_res, ncond(i)) ;
257  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
258  export_tau_val_domain (tt(1, 3)(dom), 1, order, res, pos_res, ncond(i)) ;
259  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
260  export_tau_val_domain (tt(2, 1)(dom), 1, order, res, pos_res, ncond(i)) ;
261  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
262  export_tau_val_domain (tt(2, 2)(dom), 2, order, res, pos_res, ncond(i)) ;
263  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
264  export_tau_val_domain (tt(2, 3)(dom), 2, order, res, pos_res, ncond(i)) ;
265  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
266  export_tau_val_domain (tt(3, 1)(dom), 1, order, res, pos_res, ncond(i)) ;
267  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
268  export_tau_val_domain (tt(3, 2)(dom), 2, order, res, pos_res, ncond(i)) ;
269  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
270  export_tau_val_domain (tt(3, 3)(dom), 2, order, res, pos_res, ncond(i)) ;
271  }
272  found = true ;
273  }
274  // Spherical coordinates and not symetric
275  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
276  if (n_cmp==-1) {
277  export_tau_val_domain (tt(1,1)(dom), 0, order, res, pos_res, ncond(0)) ;
278  export_tau_val_domain (tt(1,2)(dom), 1, order, res, pos_res, ncond(1)) ;
279  export_tau_val_domain (tt(1,3)(dom), 1, order, res, pos_res, ncond(2)) ;
280  export_tau_val_domain (tt(2,2)(dom), 2, order, res, pos_res, ncond(3)) ;
281  export_tau_val_domain (tt(2,3)(dom), 2, order, res, pos_res, ncond(4)) ;
282  export_tau_val_domain (tt(3,3)(dom), 2, order, res, pos_res, ncond(5)) ;
283  }
284  else for (int i=0 ; i<n_cmp ; i++) {
285  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
286  export_tau_val_domain (tt(1, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
287  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
288  export_tau_val_domain (tt(1, 2)(dom), 1, order, res, pos_res, ncond(i)) ;
289  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
290  export_tau_val_domain (tt(1, 3)(dom), 1, order, res, pos_res, ncond(i)) ;
291  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
292  export_tau_val_domain (tt(2, 2)(dom), 2, order, res, pos_res, ncond(i)) ;
293  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
294  export_tau_val_domain (tt(2, 3)(dom), 2, order, res, pos_res, ncond(i)) ;
295  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
296  export_tau_val_domain (tt(3, 3)(dom), 2, order, res, pos_res, ncond(i)) ;
297  }
298  found = true ;
299  }
300  if (!found) {
301  cerr << "Unknown type of 2-tensor Domain_shell_outer_adapted::export_tau" << endl ;
302  abort() ;
303  }
304  }
305  break ;
306  default :
307  cerr << "Valence " << val << " not implemented in Domain_shell_outer_adapted::export_tau" << endl ;
308  break ;
309  }
310 }
311 }
312 
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(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 in the bulk.
void export_tau_val_domain(const Val_domain &eq, int mlim, int order, Array< double > &res, int &pos_res, int ncond) const
Exports a residual equation in the bulk.
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
int get_m_order() const
Returns .
Definition: tensor.hpp:737
Tensor handling.
Definition: tensor.hpp:149
bool is_m_order_affected() const
Checks whether the additional parameter order is affected (not very used).
Definition: tensor.hpp:323
const Param_tensor & get_parameters() const
Returns a pointer on the possible additional parameter.
Definition: tensor.hpp:311
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
Array< double > * cf
Pointer on the Array of the values in the coefficients space.
Definition: val_domain.hpp:77
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