KADATH
domain_polar_periodic_nucleus_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 "polar_periodic.hpp"
22 #include "point.hpp"
23 #include "array_math.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "tensor.hpp"
27 namespace Kadath {
28 void Domain_polar_periodic_nucleus::affecte_tau_one_coef_val_domain (Val_domain& so, int llim, int cc, int& conte) const {
29 
30  int lquant ;
31 
32  so.is_zero = false ;
33  so.allocate_coef() ;
34  *so.cf=0. ;
35  Index pos_cf(nbr_coefs) ;
36 
37  bool found = false ;
38 
39  // Positions of the Galerkin basis
40  Index pos_gal_r (nbr_coefs) ;
41  double fact_r ;
42  int basetime = (*so.get_base().bases_1d[2]) (0) ;
43 int mink, maxk ;
44  switch (basetime) {
45  case COS :
46  mink=0 ;
47  maxk=nbr_coefs(2) ;
48  break ;
49  case SIN :
50  mink=1 ;
51  maxk=nbr_coefs(2)-1 ;
52  break ;
53  default :
54  cerr << "Unknown basis in Domain_polar_periodic_nucleus_affecte_tau_val_domain" << endl ;
55  abort() ;
56  }
57  // Loop on time
58  for (int k=mink ; k<maxk ; k++) {
59 
60  pos_cf.set(2) = k ;
61  // Loop on theta
62  int baset = (*so.get_base().bases_1d[1]) (k) ;
63  int minj, maxj ;
64  switch (baset) {
65  case COS_EVEN :
66  minj=0 ;
67  maxj=nbr_coefs(1) ;
68  break ;
69  case COS_ODD :
70  minj=0 ;
71  maxj=nbr_coefs(1)-1 ;
72  break ;
73  case SIN_EVEN :
74  minj=1 ;
75  maxj=nbr_coefs(1)-1 ;
76  break ;
77  case SIN_ODD :
78  minj=0 ;
79  maxj=nbr_coefs(1)-1 ;
80  break ;
81 
82  default :
83  cerr << "Unknown theta basis in Domain_polar_periodic_nucleus_affecte_tau_val_domain" << endl ;
84  abort() ;
85  }
86 
87  for (int j=minj ; j<maxj ; j++) {
88  int baser = (*so.get_base().bases_1d[0]) (j,k) ;
89 
90  // Compute lquant :
91  switch (baset) {
92  case COS_EVEN :
93  lquant = 2*j ;
94  break ;
95  case COS_ODD :
96  lquant = 2*j+1 ;
97  break ;
98  case SIN_EVEN :
99  lquant = 2*j ;
100  break ;
101  case SIN_ODD :
102  lquant = 2*j+1 ;
103  break ;
104 
105  default :
106  cerr << "Unknown theta basis in Domain_polar_periodic_nucleus_affecte_tau_val_domain" << endl ;
107  abort() ;
108  }
109 
110  pos_cf.set(1) = j ;
111 
112  int minr, maxr ;
113  switch (baser) {
114  case CHEB_EVEN :
115  minr=(lquant<=llim) ? 0 : 1 ;
116  maxr=nbr_coefs(0) ;
117  break ;
118  case CHEB_ODD :
119  minr= (lquant<=llim) ? 0 : 1;
120  maxr=nbr_coefs(0)-1 ;
121  break ;
122  case LEG_EVEN :
123  minr=(lquant<=llim) ? 0 : 1 ;
124  maxr=nbr_coefs(0) ;
125  break ;
126  case LEG_ODD :
127  minr=(lquant<=llim) ? 0 : 1 ;
128  maxr=nbr_coefs(0)-1 ;
129  break ;
130  default :
131  cerr << "Unknown r basis in Domain_polar_periodic_nucleus_affecte_tau_val_domain" << endl ;
132  abort() ;
133  }
134 
135  // Loop on r :
136  for (int i=minr ; i<maxr ; i++) {
137  pos_cf.set(0) = i ;
138  // No garlekin
139  if (lquant<=llim) {
140  if (conte==cc) {
141  found = true ;
142  so.cf->set(pos_cf) = 1. ;
143  }
144  conte ++ ;
145  }
146  else { if (conte==cc) {
147  found = true ;
148  // Galerkin en r
149  pos_gal_r = pos_cf ;
150  pos_gal_r.set(0) = 0 ;
151  switch (baser) {
152  case CHEB_EVEN :
153  fact_r = - pow(-1, i) ;
154  break ;
155  case LEG_EVEN : {
156  fact_r = -1. ;
157  for (int t=0 ; t<i ; t++)
158  fact_r *= -double(2*t+1)/double(2*t+2) ;
159  }
160  break ;
161  case CHEB_ODD :
162  fact_r = - (2*i+1) * pow(-1, i) ;
163  break ;
164  case LEG_ODD : {
165  fact_r = -1. ;
166  for (int t=0 ; t<i ; t++)
167  fact_r *= -double(2*t+3)/double(2*t+2) ;
168  }
169  break ;
170 
171  default :
172  cerr << "Strange base in Domain_polar_periodic_nucleus::affecte_tau_val_domain" << endl ;
173  abort() ;
174  }
175  so.cf->set(pos_cf) = 1 ;
176  so.cf->set(pos_gal_r) += fact_r ;
177  }
178  conte ++ ;
179  }
180  } // end loop i
181  } // end loop j
182  } // end loop k
183  // If not found put to zero :
184  if (!found)
185  so.set_zero() ;
186 }
187 
188 
189 void Domain_polar_periodic_nucleus::affecte_tau_one_coef (Tensor& tt, int dom, int cc, int& pos_cf) const {
190 
191  // Check right domain
192  assert (tt.get_space().get_domain(dom)==this) ;
193 
194  int val = tt.get_valence() ;
195  switch (val) {
196  case 0 :
197  affecte_tau_one_coef_val_domain (tt.set().set_domain(dom), 0, cc, pos_cf) ;
198  break ;
199  case 1 :
200  affecte_tau_one_coef_val_domain (tt.set(1).set_domain(dom), 2, cc, pos_cf) ;
201  affecte_tau_one_coef_val_domain (tt.set(2).set_domain(dom), 2, cc, pos_cf) ;
202  affecte_tau_one_coef_val_domain (tt.set(3).set_domain(dom), 2, cc, pos_cf) ;
203  break ;
204  case 2 :
205  // symetric
206  if (tt.get_n_comp()==6) {
207  affecte_tau_one_coef_val_domain (tt.set(1,1).set_domain(dom), 2, cc, pos_cf) ;
208  affecte_tau_one_coef_val_domain (tt.set(1,2).set_domain(dom), 2, cc, pos_cf) ;
209  affecte_tau_one_coef_val_domain (tt.set(1,3).set_domain(dom), 2, cc, pos_cf) ;
210  affecte_tau_one_coef_val_domain (tt.set(2,2).set_domain(dom), 2, cc, pos_cf) ;
211  affecte_tau_one_coef_val_domain (tt.set(2,3).set_domain(dom), 2, cc, pos_cf) ;
212  affecte_tau_one_coef_val_domain (tt.set(3,3).set_domain(dom), 2, cc, pos_cf) ;
213  }
214  // not symetric
215  if (tt.get_n_comp()==9) {
216  affecte_tau_one_coef_val_domain (tt.set(1,1).set_domain(dom), 2, cc, pos_cf) ;
217  affecte_tau_one_coef_val_domain (tt.set(1,2).set_domain(dom), 2, cc, pos_cf) ;
218  affecte_tau_one_coef_val_domain (tt.set(1,3).set_domain(dom), 2, cc, pos_cf) ;
219  affecte_tau_one_coef_val_domain (tt.set(2,1).set_domain(dom), 2, cc, pos_cf) ;
220  affecte_tau_one_coef_val_domain (tt.set(2,2).set_domain(dom), 2, cc, pos_cf) ;
221  affecte_tau_one_coef_val_domain (tt.set(2,3).set_domain(dom), 2, cc, pos_cf) ;
222  affecte_tau_one_coef_val_domain (tt.set(3,1).set_domain(dom), 2, cc, pos_cf) ;
223  affecte_tau_one_coef_val_domain (tt.set(3,2).set_domain(dom), 2, cc, pos_cf) ;
224  affecte_tau_one_coef_val_domain (tt.set(3,3).set_domain(dom), 2, cc, pos_cf) ;
225  }
226  break ;
227  default :
228  cerr << "Valence " << val << " not implemented in Domain_polar_nucleus::affecte_tau" << endl ;
229  abort() ;
230  break ;
231  }
232 }}
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.
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 llim, 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
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
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