KADATH
domain_bispheric_eta_first_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 
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 (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  int forgot_chi = 0;
35  int forgot_eta = 0 ;
36  switch (order) {
37  case 0 :
38  forgot_chi = 0 ;
39  forgot_eta = 0 ;
40  break ;
41  case 1 :
42  forgot_chi = 1 ;
43  forgot_eta = 2 ;
44  break ;
45  case 2 :
46  forgot_chi = 1 ;
47  forgot_eta = 2 ;
48  break ;
49  default:
50  cerr << "Unknown order in Domain_bispheric_eta_first::export_tau_val_domain" << endl ;
51  break ;
52  }
53 
54  Index pos_cf (nbr_coefs) ;
55  Index pos_galerkin (nbr_coefs) ;
56  int basep = (*so.get_base().bases_1d[2]) (0) ;
57 
58  so.coef() ;
59  // Loop on phi :
60  for (int k=0 ; k<nbr_coefs(2) ; k++) {
61  pos_cf.set(2) = k ;
62  // Loop on eta :
63  for (int j=0 ; j<nbr_coefs(1)-forgot_eta ; j++) {
64  pos_cf.set(1) = j ;
65  // Loop on chi ;
66  for (int i=0 ; i<nbr_coefs(0)-forgot_chi ; i++) {
67  pos_cf.set(0) = i ;
68  switch (basep) {
69  case COS :
70  // Avoid last odd ones
71  if ((k%2!=1) || (i!=nbr_coefs(0)-1-forgot_chi)) {
72  if ((k==0) || (k%2==1)) {
73  // The ones without regularity issues
74  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
75  pos_sec ++ ;
76  }
77  else if (i!=0) {
78  // Regularity on the axis thanks to Galerkin
79  // Factor fo Galerkin different for Legendre or Chebyshev:
80  double factor_galerkin ;
81  switch (type_base) {
82  case CHEB_TYPE :
83  factor_galerkin = (i%2==1) ? -2. : 2. ;
84  break ;
85  case LEG_TYPE :
86  factor_galerkin = -double(4*i+1) ;
87  for (int ii=1 ; ii<=i ; ii++)
88  factor_galerkin *= -double(2*ii-1)/double(2*ii) ;
89  break ;
90  default :
91  cerr << "Unknown type of basis in Domain_bispheric_eta_first::export_tau_val_domain" << endl ;
92  abort() ;
93  }
94  pos_galerkin = pos_cf ;
95  pos_galerkin.set(0) = 0 ;
96  sec.set(pos_sec) = (*so.cf)(pos_cf) + factor_galerkin * (*so.cf)(pos_galerkin) ;
97  pos_sec ++ ;
98  }}
99  break ;
100  case SIN :
101  // Avoid sin(0)
102  if ((k!=0) && (k!=nbr_coefs(2)-1))
103  //Avoid last odd ones
104  if ((k%2!=1) || (i!=nbr_coefs(0)-1-forgot_chi)) {
105  if (k%2==1) {
106  // The ones without regularity issues
107  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
108  pos_sec ++ ;
109  }
110  else if (i!=0) {
111  // Regularity on the axis thanks to Galerkin
112  // Factor fo Galerkin different for Legendre or Chebyshev:
113  double factor_galerkin ;
114  switch (type_base) {
115  case CHEB_TYPE :
116  factor_galerkin = (i%2==1) ? -2. : 2. ;
117  break ;
118  case LEG_TYPE :
119  factor_galerkin = -double(4*i+1) ;
120  for (int ii=1 ; ii<=i ; ii++)
121  factor_galerkin *= -double(2*ii-1)/double(2*ii) ;
122  break ;
123  default :
124  cerr << "Unknown type of basis in Domain_bispheric_eta_first::export_tau_val_domain" << endl ;
125  abort() ;
126  }
127  pos_galerkin = pos_cf ;
128  pos_galerkin.set(0) = 0 ;
129  sec.set(pos_sec) = (*so.cf)(pos_cf) + factor_galerkin * (*so.cf)(pos_galerkin) ;
130  pos_sec ++ ;
131  }}
132  break ;
133  default :
134  cerr << "Unknown base in Domain_bispheric_eta_first::export_tau_val_domain" << endl ;
135  break ;
136  }
137  }
138  }
139  }
140 
141  }
142 }
143 
144 void Domain_bispheric_eta_first::export_tau (const Tensor& tt, int dom, int order, Array<double>& res, int& pos_res, const Array<int>& ncond,
145  int n_cmp, Array<int>** p_cmp) const {
146  int val = tt.get_valence() ;
147  switch (val) {
148  case 0 :
149  export_tau_val_domain (tt()(dom), order, res, pos_res, ncond(0)) ;
150 
151  break ;
152  case 1 : {
153  bool found = false ;
154  // Cartesian basis
155  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
156  if (n_cmp==-1) {
157  export_tau_val_domain (tt(1)(dom), order, res, pos_res, ncond(0)) ;
158  export_tau_val_domain (tt(2)(dom), order, res, pos_res, ncond(1)) ;
159  export_tau_val_domain (tt(3)(dom), order, res, pos_res, ncond(2)) ;
160  }
161  else for (int i=0 ; i<n_cmp ; i++) {
162  if ((*p_cmp[i])(0)==1)
163  export_tau_val_domain (tt(1)(dom), order, res, pos_res, ncond(i)) ;
164  if ((*p_cmp[i])(0)==2)
165  export_tau_val_domain (tt(2)(dom), order, res, pos_res, ncond(i)) ;
166  if ((*p_cmp[i])(0)==3)
167  export_tau_val_domain (tt(3)(dom), order, res, pos_res, ncond(i)) ;
168  }
169  found = true ;
170  }
171  if (!found) {
172  cerr << "Unknown type of vector Domain_bispheric_eta_first::export_tau" << endl ;
173  abort() ;
174  }
175  }
176  break ;
177  case 2 : {
178  bool found = false ;
179  // Cartesian basis and symetric
180  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
181  if (n_cmp==-1) {
182  export_tau_val_domain (tt(1,1)(dom), order, res, pos_res, ncond(0)) ;
183  export_tau_val_domain (tt(1,2)(dom), order, res, pos_res, ncond(1)) ;
184  export_tau_val_domain (tt(1,3)(dom), order, res, pos_res, ncond(2)) ;
185  export_tau_val_domain (tt(2,2)(dom), order, res, pos_res, ncond(3)) ;
186  export_tau_val_domain (tt(2,3)(dom), order, res, pos_res, ncond(4)) ;
187  export_tau_val_domain (tt(3,3)(dom), order, res, pos_res, ncond(5)) ;
188  }
189  else for (int i=0 ; i<n_cmp ; i++) {
190  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
191  export_tau_val_domain (tt(1, 1)(dom), order, res, pos_res, ncond(i)) ;
192  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
193  export_tau_val_domain (tt(1, 2)(dom), order, res, pos_res, ncond(i)) ;
194  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
195  export_tau_val_domain (tt(1, 3)(dom), order, res, pos_res, ncond(i)) ;
196  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
197  export_tau_val_domain (tt(2, 2)(dom), order, res, pos_res, ncond(i)) ;
198  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
199  export_tau_val_domain (tt(2, 3)(dom), order, res, pos_res, ncond(i)) ;
200  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
201  export_tau_val_domain (tt(3, 3)(dom), order, res, pos_res, ncond(i)) ;
202  }
203  found = true ;
204  }
205  // Cartesian basis and not symetric
206  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
207  if (n_cmp==-1) {
208  export_tau_val_domain (tt(1,1)(dom), order, res, pos_res, ncond(0)) ;
209  export_tau_val_domain (tt(1,2)(dom), order, res, pos_res, ncond(1)) ;
210  export_tau_val_domain (tt(1,3)(dom), order, res, pos_res, ncond(2)) ;
211  export_tau_val_domain (tt(2,1)(dom), order, res, pos_res, ncond(3)) ;
212  export_tau_val_domain (tt(2,2)(dom), order, res, pos_res, ncond(4)) ;
213  export_tau_val_domain (tt(2,3)(dom), order, res, pos_res, ncond(5)) ;
214  export_tau_val_domain (tt(3,1)(dom), order, res, pos_res, ncond(6)) ;
215  export_tau_val_domain (tt(3,2)(dom), order, res, pos_res, ncond(7)) ;
216  export_tau_val_domain (tt(3,3)(dom), order, res, pos_res, ncond(8)) ;
217  }
218  else for (int i=0 ; i<n_cmp ; i++) {
219  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
220  export_tau_val_domain (tt(1, 1)(dom), order, res, pos_res, ncond(i)) ;
221  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
222  export_tau_val_domain (tt(1, 2)(dom), order, res, pos_res, ncond(i)) ;
223  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
224  export_tau_val_domain (tt(1, 3)(dom), order, res, pos_res, ncond(i)) ;
225  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
226  export_tau_val_domain (tt(2, 1)(dom), order, res, pos_res, ncond(i)) ;
227  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
228  export_tau_val_domain (tt(2, 2)(dom), order, res, pos_res, ncond(i)) ;
229  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
230  export_tau_val_domain (tt(2, 3)(dom), order, res, pos_res, ncond(i)) ;
231  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
232  export_tau_val_domain (tt(3, 1)(dom), order, res, pos_res, ncond(i)) ;
233  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
234  export_tau_val_domain (tt(3, 2)(dom), order, res, pos_res, ncond(i)) ;
235  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
236  export_tau_val_domain (tt(3, 3)(dom), order, res, pos_res, ncond(i)) ;
237  }
238  found = true ;
239  }
240  if (!found) {
241  cerr << "Unknown type of 2-tensor Domain_bispheric_eta_first::export_tau" << endl ;
242  abort() ;
243  }
244  }
245  break ;
246  default :
247  cerr << "Valence " << val << " not implemented in Domain_bispheric_eta_first::export_tau" << endl ;
248  break ;
249  }
250 }
251 }
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
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
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