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