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