KADATH
domain_compact_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_compact::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_compact::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  // Regularity on the axis :
70  if (mquant>1) {
71  // Loop on r :
72  for (int i=0 ; i<nbr_coefs(0) ; i++) {
73  pos_cf.set(0) = i ;
74  double sum = 0. ;
75  switch (baset) {
76  case COS_EVEN:
77  for (int j=1 ; j<nbr_coefs(1) ; j++) {
78  pos_cf.set(1) = j ;
79  sum += (*so.cf)(pos_cf) ;
80  }
81  pos_cf.set(1) = 0 ;
82  so.cf->set(pos_cf) = -sum ;
83  break ;
84  case COS_ODD:
85  for (int j=1 ; j<nbr_coefs(1) ; j++) {
86  pos_cf.set(1) = j ;
87  sum += (*so.cf)(pos_cf) ;
88  }
89  pos_cf.set(1) = 0 ;
90  so.cf->set(pos_cf) = -sum ;
91  break ;
92  case SIN_EVEN:
93  for (int j=2 ; j<nbr_coefs(1) ; j++) {
94  pos_cf.set(1) = j ;
95  sum += j*(*so.cf)(pos_cf) ;
96  }
97  pos_cf.set(1) = 1 ;
98  so.cf->set(pos_cf) = -sum ;
99  break ;
100  case SIN_ODD:
101  for (int j=1 ; j<nbr_coefs(1) ; j++) {
102  pos_cf.set(1) = j ;
103  sum += (2*j+1)*(*so.cf)(pos_cf) ;
104  }
105  pos_cf.set(1) = 0 ;
106  so.cf->set(pos_cf) = -sum ;
107  break ;
108  default:
109  cerr << "Unknow theta basis in Domain_compact::affecte_tau_val_domain_mquant" << endl ;
110  abort() ;
111  }
112  }
113  }
114 }
115 
116 void Domain_compact::affecte_tau_val_domain (Val_domain& so, int mlim, const Array<double>& values, int& conte) const {
117 
118  int kmin = 2*mlim+2 ;
119 
120  so.allocate_coef() ;
121  *so.cf = 0. ;
122  Index pos_cf (nbr_coefs) ;
123 
124  // True values
125  // Loop on phi :
126  for (int k=0 ; k<nbr_coefs(2)-1 ; k++)
127  if (k!=1) {
128  pos_cf.set(2) = k ;
129  // Loop on theta
130  int baset = (*so.get_base().bases_1d[1]) (k) ;
131  for (int j=0 ; j<nbr_coefs(1) ; j++) {
132  pos_cf.set(1) = j ;
133  bool true_tet = true ;
134  switch (baset) {
135  case COS_EVEN:
136  if ((j==0) && (k>=kmin))
137  true_tet = false ;
138  break ;
139  case COS_ODD:
140  if ((j==nbr_coefs(1)-1) || ((j==0) && (k>=kmin)))
141  true_tet = false ;
142  break ;
143  case SIN_EVEN:
144  if (((j==1)&&(k>=kmin+2))||(j==0) || (j==nbr_coefs(1)-1))
145  true_tet = false ;
146  break ;
147  case SIN_ODD:
148  if (((j==0)&&(k>kmin+2)) || (j==nbr_coefs(1)-1))
149  true_tet = false ;
150  break ;
151  default:
152  cerr << "Unknow theta basis in Domain_compact::affecte_tau_val_domain" << endl ;
153  abort() ;
154  }
155 
156  if (true_tet)
157  for (int i=0 ; i<nbr_coefs(0) ; i++) {
158  pos_cf.set(0) = i ;
159  so.cf->set(pos_cf) += values(conte);
160  conte ++ ;
161  }
162  }
163  }
164 
165  // Appropriate regularisation
166  // Loop on phi :
167  for (int k=0 ; k<nbr_coefs(2)-1 ; k++) {
168  pos_cf.set(2) = k ;
169  int baset = (*so.get_base().bases_1d[1]) (k) ;
170  // Loop on r :
171  for (int i=0 ; i<nbr_coefs(0) ; i++) {
172  pos_cf.set(0) = i ;
173  double sum = 0. ;
174  switch (baset) {
175  case COS_EVEN:
176  if (k>=kmin) {
177  for (int j=1 ; j<nbr_coefs(1) ; j++) {
178  pos_cf.set(1) = j ;
179  sum += (*so.cf)(pos_cf) ;
180  }
181  pos_cf.set(1) = 0 ;
182  so.cf->set(pos_cf) = -sum ;
183  }
184  break ;
185  case COS_ODD:
186  if (k>=kmin) {
187  for (int j=1 ; j<nbr_coefs(1) ; j++) {
188  pos_cf.set(1) = j ;
189  sum += (*so.cf)(pos_cf) ;
190  }
191  pos_cf.set(1) = 0 ;
192  so.cf->set(pos_cf) = -sum ;
193  }
194  break ;
195  case SIN_EVEN:
196  if (k>=kmin+2) {
197  for (int j=2 ; j<nbr_coefs(1) ; j++) {
198  pos_cf.set(1) = j ;
199  sum += j*(*so.cf)(pos_cf) ;
200  }
201  pos_cf.set(1) = 1 ;
202  so.cf->set(pos_cf) = -sum ;
203  }
204  break ;
205  case SIN_ODD:
206  if (k>=kmin+2) {
207  for (int j=1 ; j<nbr_coefs(1) ; j++) {
208  pos_cf.set(1) = j ;
209  sum += (2*j+1)*(*so.cf)(pos_cf) ;
210  }
211  pos_cf.set(1) = 0 ;
212  so.cf->set(pos_cf) = -sum ;
213  }
214  break ;
215  default:
216  cerr << "Unknow theta basis in Domain_compact::affecte_tau_val_domain" << endl ;
217  abort() ;
218  }
219  }
220  }
221 }
222 
223 void Domain_compact::affecte_tau (Tensor& tt, int dom, const Array<double>& cf, int& pos_cf) const {
224 
225  // Check right domain
226  assert (tt.get_space().get_domain(dom)==this) ;
227 
228  int val = tt.get_valence() ;
229  switch (val) {
230  case 0 :
231  if (tt.is_m_quant_affected()) {
232  // Special case bosonic field
233  affecte_tau_val_domain_mquant (tt.set().set_domain(dom), tt.get_parameters().get_m_quant(), cf, pos_cf) ;
234  }
235  else
236  affecte_tau_val_domain (tt.set().set_domain(dom), 0, cf, pos_cf) ;
237  break ;
238  case 1 : {
239  bool found = false ;
240  // Cartesian basis
241  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
242  affecte_tau_val_domain (tt.set(1).set_domain(dom), 0, cf, pos_cf) ;
243  affecte_tau_val_domain (tt.set(2).set_domain(dom), 0, cf, pos_cf) ;
244  affecte_tau_val_domain (tt.set(3).set_domain(dom), 0, cf, pos_cf) ;
245  found = true ;
246  }
247  // Spherical coordinates
248  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
249  affecte_tau_val_domain (tt.set(1).set_domain(dom), 0, cf, pos_cf) ;
250  affecte_tau_val_domain (tt.set(2).set_domain(dom), 1, cf, pos_cf) ;
251  affecte_tau_val_domain (tt.set(3).set_domain(dom), 1, cf, pos_cf) ;
252  found = true ;
253  }
254  if (!found) {
255  cerr << "Unknown type of vector Domain_compact::affecte_tau" << endl ;
256  abort() ;
257  }
258  }
259  break ;
260  case 2 : {
261  bool found = false ;
262  // Cartesian basis and symetric
263  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
264  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0, cf, pos_cf) ;
265  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 0, cf, pos_cf) ;
266  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 0, cf, pos_cf) ;
267  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 0, cf, pos_cf) ;
268  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 0, cf, pos_cf) ;
269  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 0, cf, pos_cf) ;
270  found = true ;
271  }
272  // Cartesian basis and not symetric
273  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
274  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0, cf, pos_cf) ;
275  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 0, cf, pos_cf) ;
276  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 0, cf, pos_cf) ;
277  affecte_tau_val_domain (tt.set(2,1).set_domain(dom), 0, cf, pos_cf) ;
278  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 0, cf, pos_cf) ;
279  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 0, cf, pos_cf) ;
280  affecte_tau_val_domain (tt.set(3,1).set_domain(dom), 0, cf, pos_cf) ;
281  affecte_tau_val_domain (tt.set(3,2).set_domain(dom), 0, cf, pos_cf) ;
282  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 0, cf, pos_cf) ;
283  found = true ;
284  }
285  // Spherical coordinates and symetric
286  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
287  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0,cf ,pos_cf) ;
288  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 1, cf, pos_cf) ;
289  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 1, cf, pos_cf) ;
290  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 2, cf, pos_cf) ;
291  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 2, cf, pos_cf) ;
292  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 2, cf, pos_cf) ;
293  found = true ;
294  }
295  // Spherical coordinates and not symetric
296  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
297  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), 0,cf ,pos_cf) ;
298  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), 1, cf, pos_cf) ;
299  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), 1, cf, pos_cf) ;
300  affecte_tau_val_domain (tt.set(2,1).set_domain(dom), 1, cf, pos_cf) ;
301  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), 2, cf, pos_cf) ;
302  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), 2, cf, pos_cf) ;
303  affecte_tau_val_domain (tt.set(3,1).set_domain(dom), 1, cf, pos_cf) ;
304  affecte_tau_val_domain (tt.set(3,2).set_domain(dom), 2, cf, pos_cf) ;
305  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), 2, cf, pos_cf) ;
306  found = true ;
307  }
308  if (!found) {
309  cerr << "Unknown type of 2-tensor Domain_compact::affecte_tau" << endl ;
310  abort() ;
311  }
312  }
313  break ;
314  default :
315  cerr << "Valence " << val << " not implemented in Domain_compact::affecte_tau" << endl ;
316  break ;
317  }
318 }}
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_val_domain_mquant(Val_domain &so, int mquant, const Array< double > &cf, int &pos_cf) const
Affects some coefficients to a Val_domain.
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.
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