KADATH
domain_shell_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 
22 #include "spheric.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 namespace Kadath {
27 
28 void Domain_shell::affecte_tau_val_domain_mquant (Val_domain& so, int mquant, const Array<double>& values, int& conte) const {
29 
30  so.allocate_coef() ;
31  *so.cf = 0. ;
32 
33  Index pos_cf (nbr_coefs) ;
34  // True values
35  // Loop on theta
36  int baset = (*so.get_base().bases_1d[1]) (0) ;
37  for (int j=0 ; j<nbr_coefs(1) ; j++) {
38  pos_cf.set(1) = j ;
39  bool true_tet = true ;
40  switch (baset) {
41  case COS_EVEN:
42  if ((j==0) && (mquant!=0))
43  true_tet = false ;
44  break ;
45  case COS_ODD:
46  if ((j==nbr_coefs(1)-1) || ((j==0) && (mquant!=0)))
47  true_tet = false ;
48  break ;
49  case SIN_EVEN:
50  if (((j==1) && (mquant>1)) || (j==0) || (j==nbr_coefs(1)-1))
51  true_tet = false ;
52  break ;
53  case SIN_ODD:
54  if (((j==0) && (mquant>1)) || (j==nbr_coefs(1)-1))
55  true_tet = false ;
56  break ;
57  default:
58  cerr << "Unknow theta basis in Domain_shell::affecte_tau_val_domain_mquant" << endl ;
59  abort() ;
60  }
61 
62  if (true_tet)
63  for (int i=0 ; i<nbr_coefs(0) ; i++) {
64  pos_cf.set(0) = i ;
65  so.cf->set(pos_cf) += values(conte);
66  conte ++ ;
67  }
68  }
69 
70  // Regularity on the axis :
71  if (mquant>1) {
72  // Loop on r :
73  for (int i=0 ; i<nbr_coefs(0) ; i++) {
74  pos_cf.set(0) = i ;
75  double sum = 0. ;
76  switch (baset) {
77  case COS_EVEN:
78  for (int j=1 ; j<nbr_coefs(1) ; j++) {
79  pos_cf.set(1) = j ;
80  sum += (*so.cf)(pos_cf) ;
81  }
82  pos_cf.set(1) = 0 ;
83  so.cf->set(pos_cf) = -sum ;
84  break ;
85  case COS_ODD:
86  for (int j=1 ; j<nbr_coefs(1) ; j++) {
87  pos_cf.set(1) = j ;
88  sum += (*so.cf)(pos_cf) ;
89  }
90  pos_cf.set(1) = 0 ;
91  so.cf->set(pos_cf) = -sum ;
92  break ;
93  case SIN_EVEN:
94  for (int j=2 ; j<nbr_coefs(1) ; j++) {
95  pos_cf.set(1) = j ;
96  sum += j*(*so.cf)(pos_cf) ;
97  }
98  pos_cf.set(1) = 1 ;
99  so.cf->set(pos_cf) = -sum ;
100  break ;
101  case SIN_ODD:
102  for (int j=1 ; j<nbr_coefs(1) ; j++) {
103  pos_cf.set(1) = j ;
104  sum += (2*j+1)*(*so.cf)(pos_cf) ;
105  }
106  pos_cf.set(1) = 0 ;
107  so.cf->set(pos_cf) = -sum ;
108  break ;
109  default:
110  cerr << "Unknow theta basis in Domain_shell::affecte_tau_val_domain_mquant" << endl ;
111  abort() ;
112  }
113  }
114  }
115 }
116 
117 void Domain_shell::affecte_tau_val_domain (Val_domain& so, int mlim, const Array<double>& values, int& conte) const {
118 
119  int kmin = 2*mlim+2 ;
120 
121  so.allocate_coef() ;
122  *so.cf = 0. ;
123  Index pos_cf (nbr_coefs) ;
124 
125  // True values
126  // Loop on phi :
127  for (int k=0 ; k<nbr_coefs(2)-1 ; k++)
128  if (k!=1) {
129  pos_cf.set(2) = k ;
130  // Loop on theta
131  int baset = (*so.get_base().bases_1d[1]) (k) ;
132  for (int j=0 ; j<nbr_coefs(1) ; j++) {
133  pos_cf.set(1) = j ;
134  bool true_tet = true ;
135  switch (baset) {
136  case COS_EVEN:
137  if ((j==0) && (k>=kmin))
138  true_tet = false ;
139  break ;
140  case COS_ODD:
141  if ((j==nbr_coefs(1)-1) || ((j==0) && (k>=kmin)))
142  true_tet = false ;
143  break ;
144  case SIN_EVEN:
145  if (((j==1)&&(k>=kmin+2))||(j==0) || (j==nbr_coefs(1)-1))
146  true_tet = false ;
147  break ;
148  case SIN_ODD:
149  if (((j==0)&&(k>kmin+2)) || (j==nbr_coefs(1)-1))
150  true_tet = false ;
151  break ;
152  default:
153  cerr << "Unknow theta basis in Domain_shell::affecte_tau_val_domain" << endl ;
154  abort() ;
155  }
156 
157  if (true_tet)
158  for (int i=0 ; i<nbr_coefs(0) ; i++) {
159  pos_cf.set(0) = i ;
160  so.cf->set(pos_cf) += values(conte);
161  conte ++ ;
162  }
163  }
164  }
165 
166  // Appropriate regularisation
167  // Loop on phi :
168  for (int k=0 ; k<nbr_coefs(2)-1 ; k++) {
169  pos_cf.set(2) = k ;
170  int baset = (*so.get_base().bases_1d[1]) (k) ;
171  // Loop on r :
172  for (int i=0 ; i<nbr_coefs(0) ; i++) {
173  pos_cf.set(0) = i ;
174  double sum = 0. ;
175  switch (baset) {
176  case COS_EVEN:
177  if (k>=kmin) {
178  for (int j=1 ; j<nbr_coefs(1) ; j++) {
179  pos_cf.set(1) = j ;
180  sum += (*so.cf)(pos_cf) ;
181  }
182  pos_cf.set(1) = 0 ;
183  so.cf->set(pos_cf) = -sum ;
184  }
185  break ;
186  case COS_ODD:
187  if (k>=kmin) {
188  for (int j=1 ; j<nbr_coefs(1) ; j++) {
189  pos_cf.set(1) = j ;
190  sum += (*so.cf)(pos_cf) ;
191  }
192  pos_cf.set(1) = 0 ;
193  so.cf->set(pos_cf) = -sum ;
194  }
195  break ;
196  case SIN_EVEN:
197  if (k>=kmin+2) {
198  for (int j=2 ; j<nbr_coefs(1) ; j++) {
199  pos_cf.set(1) = j ;
200  sum += j*(*so.cf)(pos_cf) ;
201  }
202  pos_cf.set(1) = 1 ;
203  so.cf->set(pos_cf) = -sum ;
204  }
205  break ;
206  case SIN_ODD:
207  if (k>=kmin+2) {
208  for (int j=1 ; j<nbr_coefs(1) ; j++) {
209  pos_cf.set(1) = j ;
210  sum += (2*j+1)*(*so.cf)(pos_cf) ;
211  }
212  pos_cf.set(1) = 0 ;
213  so.cf->set(pos_cf) = -sum ;
214  }
215  break ;
216  default:
217  cerr << "Unknow theta basis in Domain_shell::affecte_tau_val_domain" << endl ;
218  abort() ;
219  }
220  }
221  }
222 }
223 
224 void Domain_shell::affecte_tau (Tensor& tt, int dom, const Array<double>& cf, int& pos_cf) const {
225 
226  // Check right domain
227  assert (tt.get_space().get_domain(dom)==this) ;
228 
229  int val = tt.get_valence() ;
230  switch (val) {
231  case 0 :
232  if (tt.is_m_quant_affected()) {
233  // Special case bosonic field
234  affecte_tau_val_domain_mquant (tt.set().set_domain(dom), tt.get_parameters().get_m_quant(), cf, pos_cf) ;
235  }
236  else
237  affecte_tau_val_domain (tt.set().set_domain(dom), 0, cf, pos_cf) ;
238  break ;
239  case 1 : {
240  bool found = false ;
241  // Cartesian basis
242  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
243  affecte_tau_val_domain (tt.set(1).set_domain(dom), 0, cf, pos_cf) ;
244  affecte_tau_val_domain (tt.set(2).set_domain(dom), 0, cf, pos_cf) ;
245  affecte_tau_val_domain (tt.set(3).set_domain(dom), 0, cf, pos_cf) ;
246  found = true ;
247  }
248  // Spherical coordinates
249  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
250  affecte_tau_val_domain (tt.set(1).set_domain(dom), 0, cf, pos_cf) ;
251  affecte_tau_val_domain (tt.set(2).set_domain(dom), 1, cf, pos_cf) ;
252  affecte_tau_val_domain (tt.set(3).set_domain(dom), 1, cf, pos_cf) ;
253  found = true ;
254  }
255  // MTZ coordinates
256  if (tt.get_basis().get_basis(dom)==MTZ_BASIS) {
257  affecte_tau_val_domain (tt.set(1).set_domain(dom), 0, cf, pos_cf) ;
258  affecte_tau_val_domain (tt.set(2).set_domain(dom), 1, cf, pos_cf) ;
259  affecte_tau_val_domain (tt.set(3).set_domain(dom), 1, cf, pos_cf) ;
260  found = true ;
261  }
262  if (!found) {
263  cerr << "Unknown type of vector Domain_shell::affecte_tau" << endl ;
264  abort() ;
265  }
266  }
267  break ;
268  case 2 : {
269  bool found = false ;
270  // Cartesian basis and symetric
271  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
272  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0, cf, pos_cf) ;
273  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 0, cf, pos_cf) ;
274  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 0, cf, pos_cf) ;
275  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 0, cf, pos_cf) ;
276  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 0, cf, pos_cf) ;
277  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 0, cf, pos_cf) ;
278  found = true ;
279  }
280  // Cartesian basis and not symetric
281  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
282  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0, cf, pos_cf) ;
283  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 0, cf, pos_cf) ;
284  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 0, cf, pos_cf) ;
285  affecte_tau_val_domain (tt.set(2,1).set_domain(dom), 0, cf, pos_cf) ;
286  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 0, cf, pos_cf) ;
287  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 0, cf, pos_cf) ;
288  affecte_tau_val_domain (tt.set(3,1).set_domain(dom), 0, cf, pos_cf) ;
289  affecte_tau_val_domain (tt.set(3,2).set_domain(dom), 0, cf, pos_cf) ;
290  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 0, cf, pos_cf) ;
291  found = true ;
292  }
293  // Spherical coordinates and symetric
294  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
295  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0,cf ,pos_cf) ;
296  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 1, cf, pos_cf) ;
297  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 1, cf, pos_cf) ;
298  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 2, cf, pos_cf) ;
299  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 2, cf, pos_cf) ;
300  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 2, cf, pos_cf) ;
301  found = true ;
302  }
303  // Spherical coordinates and not symetric
304  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
305  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0,cf ,pos_cf) ;
306  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 1, cf, pos_cf) ;
307  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 1, cf, pos_cf) ;
308  affecte_tau_val_domain (tt.set(2,1).set_domain(dom), 1, cf, pos_cf) ;
309  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 2, cf, pos_cf) ;
310  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 2, cf, pos_cf) ;
311  affecte_tau_val_domain (tt.set(3,1).set_domain(dom), 1, cf, pos_cf) ;
312  affecte_tau_val_domain (tt.set(3,2).set_domain(dom), 2, cf, pos_cf) ;
313  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 2, cf, pos_cf) ;
314  found = true ;
315  }
316  // MTZ coordinates and symetric
317  if ((tt.get_basis().get_basis(dom)==MTZ_BASIS) && (tt.get_n_comp()==6)) {
318  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0,cf ,pos_cf) ;
319  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 1, cf, pos_cf) ;
320  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 1, cf, pos_cf) ;
321  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 2, cf, pos_cf) ;
322  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 2, cf, pos_cf) ;
323  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 2, cf, pos_cf) ;
324  found = true ;
325  }
326  // MTZ coordinates and not symetric
327  if ((tt.get_basis().get_basis(dom)==MTZ_BASIS) && (tt.get_n_comp()==9)) {
328  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0,cf ,pos_cf) ;
329  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 1, cf, pos_cf) ;
330  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 1, cf, pos_cf) ;
331  affecte_tau_val_domain (tt.set(2,1).set_domain(dom), 1, cf, pos_cf) ;
332  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 2, cf, pos_cf) ;
333  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 2, cf, pos_cf) ;
334  affecte_tau_val_domain (tt.set(3,1).set_domain(dom), 1, cf, pos_cf) ;
335  affecte_tau_val_domain (tt.set(3,2).set_domain(dom), 2, cf, pos_cf) ;
336  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 2, cf, pos_cf) ;
337  found = true ;
338  }
339  if (!found) {
340  cerr << "Unknown type of 2-tensor Domain_shell::affecte_tau" << endl ;
341  abort() ;
342  }
343  }
344  break ;
345  default :
346  cerr << "Valence " << val << " not implemented in Domain_shell::affecte_tau" << endl ;
347  break ;
348  }
349 }}
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(Tensor &, int, const Array< double > &, int &) const
Affects some coefficients to a Tensor.
void affecte_tau_val_domain(Val_domain &so, int mlim, const Array< double > &cf, int &pos_cf) const
Affects some coefficients to a Val_domain.
void affecte_tau_val_domain_mquant(Val_domain &so, int mquant, 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
int get_m_quant() const
Returns .
Definition: tensor.hpp:747
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
const Param_tensor & get_parameters() const
Returns a pointer on the possible additional parameter.
Definition: tensor.hpp:311
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
bool is_m_quant_affected() const
Checks whether the additional parameter is affected (used for boson stars for instance).
Definition: tensor.hpp:326
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