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