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