KADATH
domain_compact_export_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 
27 namespace Kadath {
28 
29 void Domain_compact::export_tau_val_domain_mquant (const Val_domain& so, int mquant, int order, Array<double>& sec, int& pos_sec, int ncond) const {
30  if (so.check_if_zero())
31  pos_sec += ncond ;
32  else {
33 
34  so.coef() ;
35  Index pos_cf (nbr_coefs) ;
36  Index pos_galerkin (nbr_coefs) ;
37 
38  // Loop on theta
39  int baset = (*so.get_base().bases_1d[1]) (0) ;
40  for (int j=0 ; j<nbr_coefs(1) ; j++) {
41  pos_cf.set(1) = j ;
42  // Loop on r :
43  for (int i=0 ; i<nbr_coefs(0)-order ; i++) {
44  pos_cf.set(0) = i ;
45  switch (baset) {
46  case COS_EVEN:
47  if (mquant==0) {
48  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
49  pos_sec ++ ;
50  }
51  else if (j!=0) {
52  // Galerkin base
53  pos_galerkin = pos_cf ;
54  pos_galerkin.set(1) = 0 ;
55  sec.set(pos_sec) = (*so.cf)(pos_cf)
56  -2*(*so.cf)(pos_galerkin) ;
57  pos_sec ++ ;
58  }
59  break ;
60  case COS_ODD:
61  if (j!=nbr_coefs(1)-1) {
62  if (mquant==0) {
63  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
64  pos_sec ++ ;
65  }
66  else if (j!=0) {
67  // Galerkin base
68  pos_galerkin = pos_cf ;
69  pos_galerkin.set(1) = 0 ;
70  sec.set(pos_sec) = (*so.cf)(pos_cf)
71  -(*so.cf)(pos_galerkin) ;
72  pos_sec ++ ;
73  }
74  }
75  break ;
76  case SIN_EVEN:
77  if ((j!=0) && (j!=nbr_coefs(1)-1)) {
78  if (mquant<=1) {
79  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
80  pos_sec ++ ;
81  }
82  else if (j!=1) {
83  // Galerkin base
84  pos_galerkin = pos_cf ;
85  pos_galerkin.set(1) = 1 ;
86  sec.set(pos_sec) = (*so.cf)(pos_cf)
87  - j*(*so.cf)(pos_galerkin) ;
88  pos_sec ++ ;
89  }
90  }
91  break ;
92  case SIN_ODD:
93  if (j!=nbr_coefs(1)-1) {
94  if (mquant<=1) {
95  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
96  pos_sec ++ ;
97  }
98  else if (j!=0) {
99  // Galerkin base
100  pos_galerkin = pos_cf ;
101  pos_galerkin.set(1) = 0 ;
102  sec.set(pos_sec) = (*so.cf)(pos_cf)
103  - (2*j+1)*(*so.cf)(pos_galerkin) ;
104  pos_sec ++ ;
105  }
106  }
107  break ;
108  default:
109  cerr << "Unknow theta basis in Domain_compact::export_tau_val_domain_mquant" << endl ;
110  abort() ;
111  }
112  }
113  }
114  }
115 }
116 void Domain_compact::export_tau_val_domain (const Val_domain& so, int mlim, int order, Array<double>& sec, int& pos_sec, int ncond) const {
117 
118  if (so.check_if_zero())
119  pos_sec += ncond ;
120  else {
121 
122  so.coef() ;
123  int kmin = 2*mlim + 2 ;
124  Index pos_cf (nbr_coefs) ;
125  Index pos_galerkin (nbr_coefs) ;
126 
127  // Loop on phi :
128  for (int k=0 ; k<nbr_coefs(2)-1 ; k++)
129  if (k!=1) {
130  pos_cf.set(2) = k ;
131  // Loop on theta
132  int baset = (*so.get_base().bases_1d[1]) (k) ;
133  for (int j=0 ; j<nbr_coefs(1) ; j++) {
134  pos_cf.set(1) = j ;
135  // Loop on r :
136  for (int i=0 ; i<nbr_coefs(0)-order ; i++) {
137  pos_cf.set(0) = i ;
138  switch (baset) {
139  case COS_EVEN:
140  if (k<kmin) {
141  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
142  pos_sec ++ ;
143  }
144  else if (j!=0) {
145  // Galerkin base
146  pos_galerkin = pos_cf ;
147  pos_galerkin.set(1) = 0 ;
148  sec.set(pos_sec) = (*so.cf)(pos_cf)
149  -2*(*so.cf)(pos_galerkin) ;
150  pos_sec ++ ;
151  }
152  break ;
153  case COS_ODD:
154  if (j!=nbr_coefs(1)-1) {
155  if (k<kmin) {
156  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
157  pos_sec ++ ;
158  }
159  else if (j!=0) {
160  // Galerkin base
161  pos_galerkin = pos_cf ;
162  pos_galerkin.set(1) = 0 ;
163  sec.set(pos_sec) = (*so.cf)(pos_cf)
164  -(*so.cf)(pos_galerkin) ;
165  pos_sec ++ ;
166  }
167  }
168  break ;
169  case SIN_EVEN:
170  if ((j!=0) && (j!=nbr_coefs(1)-1)) {
171  if (k<kmin+2) {
172  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
173  pos_sec ++ ;
174  }
175  else if (j!=1) {
176  // Galerkin
177  pos_galerkin = pos_cf ;
178  pos_galerkin.set(1) = 1 ;
179  sec.set(pos_sec) = (*so.cf)(pos_cf)
180  -j*(*so.cf)(pos_galerkin) ;
181  pos_sec ++ ;
182  }
183  }
184  break ;
185  case SIN_ODD:
186  if (j!=nbr_coefs(1)-1) {
187  if (k<kmin+2) {
188  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
189  pos_sec ++ ;
190  }
191  else if (j!=0) {
192  // Galerkin
193  pos_galerkin = pos_cf ;
194  pos_galerkin.set(1) = 0 ;
195  sec.set(pos_sec) = (*so.cf)(pos_cf)
196  -(2*j+1)*(*so.cf)(pos_galerkin) ;
197  pos_sec ++ ;
198  }
199  }
200  break ;
201  default:
202  cerr << "Unknow theta basis in Domain_compact::export_tau_val_domain" << endl ;
203  abort() ;
204  }
205  }
206  }
207  }
208  }
209 }
210 
211 void Domain_compact::export_tau (const Tensor& tt, int dom, int order, Array<double>& res, int& pos_res, const Array<int>& ncond,
212  int n_cmp, Array<int>** p_cmp) const {
213  int val = tt.get_valence() ;
214  switch (val) {
215  case 0 :
216  if (tt.is_m_quant_affected()) {
217  // Special case for bosonic field
218  export_tau_val_domain_mquant (tt()(dom), tt.get_parameters().get_m_quant(), order, res, pos_res, ncond(0)) ;
219  }
220  else {
221  if (!tt.is_m_order_affected())
222  export_tau_val_domain (tt()(dom), 0, order, res, pos_res, ncond(0)) ;
223  else
224  export_tau_val_domain (tt()(dom), tt.get_parameters().get_m_order(), order, res, pos_res, ncond(0)) ;
225  }
226  break ;
227  case 1 : {
228  bool found = false ;
229  // Cartesian basis
230  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
231  if (n_cmp==-1) {
232  export_tau_val_domain (tt(1)(dom), 0, order, res, pos_res, ncond(0)) ;
233  export_tau_val_domain (tt(2)(dom), 0, order, res, pos_res, ncond(1)) ;
234  export_tau_val_domain (tt(3)(dom), 0, order, res, pos_res, ncond(2)) ;
235  }
236  else for (int i=0 ; i<n_cmp ; i++) {
237  if ((*p_cmp[i])(0)==1)
238  export_tau_val_domain (tt(1)(dom), 0, order, res, pos_res, ncond(i)) ;
239  if ((*p_cmp[i])(0)==2)
240  export_tau_val_domain (tt(2)(dom), 0, order, res, pos_res, ncond(i)) ;
241  if ((*p_cmp[i])(0)==3)
242  export_tau_val_domain (tt(3)(dom), 0, order, res, pos_res, ncond(i)) ;
243  }
244  found = true ;
245  }
246  // Spherical coordinates
247  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
248  if (n_cmp==-1) {
249  export_tau_val_domain (tt(1)(dom), 0, order, res, pos_res, ncond(0)) ;
250  export_tau_val_domain (tt(2)(dom), 1, order, res, pos_res, ncond(1)) ;
251  export_tau_val_domain (tt(3)(dom), 1, order, res, pos_res, ncond(2)) ;
252  }
253  else for (int i=0 ; i<n_cmp ; i++) {
254  if ((*p_cmp[i])(0)==1)
255  export_tau_val_domain (tt(1)(dom), 0, order, res, pos_res, ncond(i)) ;
256  if ((*p_cmp[i])(0)==2)
257  export_tau_val_domain (tt(2)(dom), 1, order, res, pos_res, ncond(i)) ;
258  if ((*p_cmp[i])(0)==3)
259  export_tau_val_domain (tt(3)(dom), 1, order, res, pos_res, ncond(i)) ;
260  }
261  found = true ;
262  }
263  if (!found) {
264  cerr << "Unknown type of vector Domain_compact::export_tau" << endl ;
265  abort() ;
266  }
267  }
268  break ;
269  case 2 : {
270  bool found = false ;
271  // Cartesian basis and symetric
272  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
273  if (n_cmp==-1) {
274  export_tau_val_domain (tt(1,1)(dom), 0, order, res, pos_res, ncond(0)) ;
275  export_tau_val_domain (tt(1,2)(dom), 0, order, res, pos_res, ncond(1)) ;
276  export_tau_val_domain (tt(1,3)(dom), 0, order, res, pos_res, ncond(2)) ;
277  export_tau_val_domain (tt(2,2)(dom), 0, order, res, pos_res, ncond(3)) ;
278  export_tau_val_domain (tt(2,3)(dom), 0, order, res, pos_res, ncond(4)) ;
279  export_tau_val_domain (tt(3,3)(dom), 0, order, res, pos_res, ncond(5)) ;
280  }
281  else for (int i=0 ; i<n_cmp ; i++) {
282  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
283  export_tau_val_domain (tt(1, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
284  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
285  export_tau_val_domain (tt(1, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
286  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
287  export_tau_val_domain (tt(1, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
288  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
289  export_tau_val_domain (tt(2, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
290  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
291  export_tau_val_domain (tt(2, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
292  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
293  export_tau_val_domain (tt(3, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
294  }
295  found = true ;
296  }
297  // Cartesian basis and not symetric
298  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
299  if (n_cmp==-1) {
300  export_tau_val_domain (tt(1,1)(dom), 0, order, res, pos_res, ncond(0)) ;
301  export_tau_val_domain (tt(1,2)(dom), 0, order, res, pos_res, ncond(1)) ;
302  export_tau_val_domain (tt(1,3)(dom), 0, order, res, pos_res, ncond(2)) ;
303  export_tau_val_domain (tt(2,1)(dom), 0, order, res, pos_res, ncond(3)) ;
304  export_tau_val_domain (tt(2,2)(dom), 0, order, res, pos_res, ncond(4)) ;
305  export_tau_val_domain (tt(2,3)(dom), 0, order, res, pos_res, ncond(5)) ;
306  export_tau_val_domain (tt(3,1)(dom), 0, order, res, pos_res, ncond(6)) ;
307  export_tau_val_domain (tt(3,2)(dom), 0, order, res, pos_res, ncond(7)) ;
308  export_tau_val_domain (tt(3,3)(dom), 0, order, res, pos_res, ncond(8)) ;
309  }
310  else for (int i=0 ; i<n_cmp ; i++) {
311  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
312  export_tau_val_domain (tt(1, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
313  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
314  export_tau_val_domain (tt(1, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
315  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
316  export_tau_val_domain (tt(1, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
317  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
318  export_tau_val_domain (tt(2, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
319  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
320  export_tau_val_domain (tt(2, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
321  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
322  export_tau_val_domain (tt(2, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
323  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
324  export_tau_val_domain (tt(3, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
325  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
326  export_tau_val_domain (tt(3, 2)(dom), 0, order, res, pos_res, ncond(i)) ;
327  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
328  export_tau_val_domain (tt(3, 3)(dom), 0, order, res, pos_res, ncond(i)) ;
329  }
330  found = true ;
331  }
332  // Spherical coordinates and not symetric
333  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
334  if (n_cmp==-1) {
335  export_tau_val_domain (tt(1,1)(dom), 0, order, res, pos_res, ncond(0)) ;
336  export_tau_val_domain (tt(1,2)(dom), 1, order, res, pos_res, ncond(1)) ;
337  export_tau_val_domain (tt(1,3)(dom), 1, order, res, pos_res, ncond(2)) ;
338  export_tau_val_domain (tt(2,1)(dom), 1, order, res, pos_res, ncond(3)) ;
339  export_tau_val_domain (tt(2,2)(dom), 2, order, res, pos_res, ncond(4)) ;
340  export_tau_val_domain (tt(2,3)(dom), 2, order, res, pos_res, ncond(5)) ;
341  export_tau_val_domain (tt(3,1)(dom), 1, order, res, pos_res, ncond(6)) ;
342  export_tau_val_domain (tt(3,2)(dom), 2, order, res, pos_res, ncond(7)) ;
343  export_tau_val_domain (tt(3,3)(dom), 2, order, res, pos_res, ncond(8)) ;
344  }
345  else for (int i=0 ; i<n_cmp ; i++) {
346  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
347  export_tau_val_domain (tt(1, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
348  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
349  export_tau_val_domain (tt(1, 2)(dom), 1, order, res, pos_res, ncond(i)) ;
350  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
351  export_tau_val_domain (tt(1, 3)(dom), 1, order, res, pos_res, ncond(i)) ;
352  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
353  export_tau_val_domain (tt(2, 1)(dom), 1, order, res, pos_res, ncond(i)) ;
354  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
355  export_tau_val_domain (tt(2, 2)(dom), 2, order, res, pos_res, ncond(i)) ;
356  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
357  export_tau_val_domain (tt(2, 3)(dom), 2, order, res, pos_res, ncond(i)) ;
358  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
359  export_tau_val_domain (tt(3, 1)(dom), 1, order, res, pos_res, ncond(i)) ;
360  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
361  export_tau_val_domain (tt(3, 2)(dom), 2, order, res, pos_res, ncond(i)) ;
362  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
363  export_tau_val_domain (tt(3, 3)(dom), 2, order, res, pos_res, ncond(i)) ;
364  }
365  found = true ;
366  }
367  // Spherical coordinates and not symetric
368  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
369  if (n_cmp==-1) {
370  export_tau_val_domain (tt(1,1)(dom), 0, order, res, pos_res, ncond(0)) ;
371  export_tau_val_domain (tt(1,2)(dom), 1, order, res, pos_res, ncond(1)) ;
372  export_tau_val_domain (tt(1,3)(dom), 1, order, res, pos_res, ncond(2)) ;
373  export_tau_val_domain (tt(2,2)(dom), 2, order, res, pos_res, ncond(3)) ;
374  export_tau_val_domain (tt(2,3)(dom), 2, order, res, pos_res, ncond(4)) ;
375  export_tau_val_domain (tt(3,3)(dom), 2, order, res, pos_res, ncond(5)) ;
376  }
377  else for (int i=0 ; i<n_cmp ; i++) {
378  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
379  export_tau_val_domain (tt(1, 1)(dom), 0, order, res, pos_res, ncond(i)) ;
380  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
381  export_tau_val_domain (tt(1, 2)(dom), 1, order, res, pos_res, ncond(i)) ;
382  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
383  export_tau_val_domain (tt(1, 3)(dom), 1, order, res, pos_res, ncond(i)) ;
384  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
385  export_tau_val_domain (tt(2, 2)(dom), 2, order, res, pos_res, ncond(i)) ;
386  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
387  export_tau_val_domain (tt(2, 3)(dom), 2, order, res, pos_res, ncond(i)) ;
388  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
389  export_tau_val_domain (tt(3, 3)(dom), 2, order, res, pos_res, ncond(i)) ;
390  }
391  found = true ;
392  }
393  if (!found) {
394  cerr << "Unknown type of 2-tensor Domain_compact::export_tau" << endl ;
395  abort() ;
396  }
397  }
398  break ;
399  default :
400  cerr << "Valence " << val << " not implemented in Domain_compact::export_tau" << endl ;
401  break ;
402  }
403 }}
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 export_tau_val_domain(const Val_domain &eq, int mlim, int order, Array< double > &res, int &pos_res, int ncond) const
Exports a residual equation in the bulk.
void export_tau_val_domain_mquant(const Val_domain &eq, int mquant, int order, Array< double > &res, int &pos_res, int ncond) const
Exports a residual equation in the bulk.
virtual void export_tau(const Tensor &, int, int, Array< double > &, int &, const Array< int > &, int n_cmp=-1, Array< int > **p_cmp=0x0) const
Exports all the residual equations corresponding to a tensorial one in the bulk.
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_order() const
Returns .
Definition: tensor.hpp:737
int get_m_quant() const
Returns .
Definition: tensor.hpp:747
Tensor handling.
Definition: tensor.hpp:149
bool is_m_order_affected() const
Checks whether the additional parameter order is affected (not very used).
Definition: tensor.hpp:323
const Param_tensor & get_parameters() const
Returns a pointer on the possible additional parameter.
Definition: tensor.hpp:311
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
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
bool check_if_zero() const
Check whether the logical state is zero or not.
Definition: val_domain.hpp:142
Array< double > * cf
Pointer on the Array of the values in the coefficients space.
Definition: val_domain.hpp:77
void coef() const
Computes the coefficients.
Definition: val_domain.cpp:622
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122