KADATH
domain_bispheric_eta_first_affecte_tau_one_coef.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 #include "exceptions.hpp"
27 
28 namespace Kadath {
30 
31  int basep = (*so.get_base().bases_1d[2]) (0) ;
32 
33  so.is_zero = false ;
34  so.allocate_coef() ;
35  *so.cf=0. ;
36  Index pos(nbr_coefs) ;
37 
38  bool found = false ;
39  do {
40 
41  bool indic = true ;
42  switch (basep) {
43  case COS :
44  // Last odd ones
45  if ((pos(2)%2==1) && (pos(0)==nbr_coefs(0)-1))
46  indic = false ;
47  // Regularity for even ones :
48  if ((pos(2)!=0) && (pos(2)%2==0) && (pos(0)==0))
49  indic = false ;
50  break ;
51  case SIN :
52  // sin(0)
53  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
54  indic = false ;
55  // Last odd ones :
56  if ((pos(2)%2==1) && (pos(0)==nbr_coefs(0)-1))
57  indic = false ;
58  // Regularity for even ones :
59  if ((pos(2)%2==0) && (pos(0)==0))
60  indic = false ;
61  break ;
62  default :
63  cerr << "Unknwon phi basis in Domain_bispheric_eta_first::export_tau_one_coef_val_domain" << endl ;
64  abort() ;
65  }
66 
67  if (indic) {
68  if (conte==cc) {
69  found = true ;
70  so.cf->set(pos) = 1;
71  if ((pos(2)%2==0) && (pos(2)!=0)) {
72  Index pos_galerkin (pos) ;
73  pos_galerkin.set(0) = 0 ;
74  double valreg ;
75  int basechi = (*so.get_base().bases_1d[0])(pos(1), pos(2)) ;
76  switch (basechi) {
77  case CHEB_EVEN :
78  valreg = (pos(0)%2==0) ? -1 : 1 ;
79  break ;
80  case LEG_EVEN :
81  valreg = 0.5 ;
82  for (int i=1 ; i<pos(0) ; i++)
83  valreg *= - double(2*i+1)/double(2*i+2) ;
84  break ;
85  default :
86  std::string where {"Domain_bispheric_eta_first::affecte_one_coef_val_domain (in file "};
87  where += std::string{__FILE__} + " at line " + std::string{__LINE__} + ") ";
88  cerr << "Unknown base in "<< where << "(base code = "<< basechi << ")." << endl ;
89  throw Unknown_base_error{basechi,where} ;
90  }
91  so.cf->set(pos_galerkin) = valreg ;
92  }
93  }
94  else
95  so.cf->set(pos) = 0. ;
96  conte ++ ;
97  }
98  }
99  while (pos.inc()) ;
100 
101  // If not found put to zero :
102  if (!found)
103  so.set_zero() ;
104 }
105 
106 void Domain_bispheric_eta_first::affecte_tau_one_coef (Tensor& tt, int dom, int cc, int& pos_cf) const {
107 
108  // Check right domain
109  assert (tt.get_space().get_domain(dom)==this) ;
110 
111  int val = tt.get_valence() ;
112  switch (val) {
113  case 0 :
114  affecte_tau_one_coef_val_domain (tt.set().set_domain(dom), cc, pos_cf) ;
115  break ;
116  case 1 : {
117  bool found = false ;
118  // Cartesian basis
119  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
120  affecte_tau_one_coef_val_domain (tt.set(1).set_domain(dom), cc, pos_cf) ;
121  affecte_tau_one_coef_val_domain (tt.set(2).set_domain(dom), cc, pos_cf) ;
122  affecte_tau_one_coef_val_domain (tt.set(3).set_domain(dom), cc, pos_cf) ;
123  found = true ;
124  }
125  if (!found) {
126  cerr << "Unknown type of vector Domain_bispheric_eta_first::affecte_tau_one_coef" << endl ;
127  abort() ;
128  }
129  }
130  break ;
131  case 2 : {
132  bool found = false ;
133  // Cartesian basis and symetric
134  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
135  affecte_tau_one_coef_val_domain (tt.set(1,1).set_domain(dom), cc, pos_cf) ;
136  affecte_tau_one_coef_val_domain (tt.set(1,2).set_domain(dom), cc, pos_cf) ;
137  affecte_tau_one_coef_val_domain (tt.set(1,3).set_domain(dom), cc, pos_cf) ;
138  affecte_tau_one_coef_val_domain (tt.set(2,2).set_domain(dom), cc, pos_cf) ;
139  affecte_tau_one_coef_val_domain (tt.set(2,3).set_domain(dom), cc, pos_cf) ;
140  affecte_tau_one_coef_val_domain (tt.set(3,3).set_domain(dom), cc, pos_cf) ;
141  found = true ;
142  }
143  // Cartesian basis and not symetric
144  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
145  affecte_tau_one_coef_val_domain (tt.set(1,1).set_domain(dom), cc, pos_cf) ;
146  affecte_tau_one_coef_val_domain (tt.set(1,2).set_domain(dom), cc, pos_cf) ;
147  affecte_tau_one_coef_val_domain (tt.set(1,3).set_domain(dom), cc, pos_cf) ;
148  affecte_tau_one_coef_val_domain (tt.set(2,1).set_domain(dom), cc, pos_cf) ;
149  affecte_tau_one_coef_val_domain (tt.set(2,2).set_domain(dom), cc, pos_cf) ;
150  affecte_tau_one_coef_val_domain (tt.set(2,3).set_domain(dom), cc, pos_cf) ;
151  affecte_tau_one_coef_val_domain (tt.set(3,1).set_domain(dom), cc, pos_cf) ;
152  affecte_tau_one_coef_val_domain (tt.set(3,2).set_domain(dom), cc, pos_cf) ;
153  affecte_tau_one_coef_val_domain (tt.set(3,3).set_domain(dom), cc, pos_cf) ;
154  found = true ;
155  }
156  if (!found) {
157  cerr << "Unknown type of 2-tensor Domain_bispheric_eta_first::affecte_tau_one_coef" << endl ;
158  abort() ;
159  }
160  }
161  break ;
162  default :
163  cerr << "Valence " << val << " not implemented in Domain_bispheric_eta_first::affecte_tau" << endl ;
164  break ;
165  }
166 }
167 }
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 affecte_tau_one_coef(Tensor &, int, int, int &) const
Sets at most one coefficient of a Tensor to 1.
void affecte_tau_one_coef_val_domain(Val_domain &so, int cc, int &pos_cf) const
Sets at most one coefficient of a Val_domain to 1.
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
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
Definition: scalar.hpp:555
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
Tensor handling.
Definition: tensor.hpp:149
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
Definition: tensor_impl.hpp:91
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
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
void set_zero()
Sets the Val_domain to zero (logical state to zero and arrays destroyed).
Definition: val_domain.cpp:223
void allocate_coef()
Allocates the values in the coefficient space and destroys the values in the configuration space.
Definition: val_domain.cpp:216
Array< double > * cf
Pointer on the Array of the values in the coefficients space.
Definition: val_domain.hpp:77
bool is_zero
Indicator used for null fields (for speed issues).
Definition: val_domain.hpp:74
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122