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