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