KADATH
domain_polar_nucleus_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 #include "polar.hpp"
22 #include "point.hpp"
23 #include "array_math.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "tensor.hpp"
27 
28 namespace Kadath {
29 void Domain_polar_nucleus::export_tau_val_domain (const Val_domain& so, int mquant, int llim, int order, Array<double>& sec, int& pos_sec, int ncond) const {
30 
31  if (so.check_if_zero())
32  pos_sec += ncond ;
33  else {
34 
35  so.coef() ;
36  int rlim = 0 ;
37  switch (order) {
38  case 2 :
39  rlim = order ;
40  break ;
41  case 1 :
42  rlim = 2 ;
43  break ;
44  case 0 :
45  rlim = 1 ;
46  break ;
47  default :
48  cerr << "Unknown case in Domain_polar_nucleus_export_tau_val_domain" << endl ;
49  abort() ;
50  }
51 
52 
53  Index pos_cf (nbr_coefs) ;
54  // Positions of the Galerkin basis
55  Index pos_gal_t (nbr_coefs) ;
56  Index pos_gal_r (nbr_coefs) ;
57  Index pos_gal_rt (nbr_coefs) ;
58  double fact_t, fact_r, fact_rt ;
59 
60  int lquant ;
61  // Loop on theta
62  int baset = (*so.get_base().bases_1d[1]) (0) ;
63  for (int j=0 ; j<nbr_coefs(1) ; j++) {
64  int baser = (*so.get_base().bases_1d[0]) (j) ;
65  pos_cf.set(1) = j ;
66  // Loop on r :
67  for (int i=0 ; i<nbr_coefs(0) ; i++) {
68  pos_cf.set(0) = i ;
69  switch (baset) {
70  case COS_EVEN :
71  assert ((baser==LEG_EVEN) || (baser==CHEB_EVEN)) ;
72  lquant = 2*j ;
73  // No galerkin :
74  if ((mquant==0) && (lquant<=llim)) {
75  if (i!=nbr_coefs(0)-rlim+1) {
76  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
77  pos_sec ++ ;
78  }
79  }
80  else if (mquant==0) {
81  if ((i!=0) && (i!=nbr_coefs(0)-rlim+1)) {
82  // Galerkin base in r only
83  pos_gal_r = pos_cf ;
84  pos_gal_r.set(0) = 0 ;
85  switch (baser) {
86  case CHEB_EVEN :
87  fact_r = - 2 * pow(-1, i) ;
88  break ;
89  case LEG_EVEN : {
90  fact_r = -double(4*i+1) ;
91  for (int t=0 ; t<i ; t++)
92  fact_r *= -double(2*t+1)/double(2*t+2) ;
93  }
94  break ;
95  default :
96  cerr << "Strange base in Domain_polar_nucleus:export_tau_inside" << endl ;
97  abort() ;
98  }
99 
100  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) ;
101  pos_sec ++ ;
102  }
103  }
104  else if ((j!=0) && (i!=0) && (i!=nbr_coefs(0)-rlim+1)) {
105  // Need to use two_dimensional Galerkin basis (aouch !)
106  pos_gal_r = pos_cf ;
107  pos_gal_r.set(0) = 0 ;
108  pos_gal_t = pos_cf ;
109  pos_gal_t.set(1) = 0 ;
110  pos_gal_rt = pos_cf ;
111  pos_gal_rt.set(0) = 0 ;
112  pos_gal_rt.set(1) = 0 ;
113  switch (baser) {
114  case CHEB_EVEN :
115  fact_r = -2*pow(-1, i) ;
116  fact_t = -2 ;
117  fact_rt = 4*pow(-1, i) ;
118  break ;
119  case LEG_EVEN : {
120  double l0 = 1 ;
121  for (int t=0 ; t<i ; t++)
122  l0 *= -double(2*t+1)/double(2*t+2) ;
123  fact_r = - l0 * double(4*i+1) ;
124  fact_t = -2 ;
125  fact_rt = 2*double(4*i+1)*l0 ;
126  }
127  break ;
128  default :
129  cerr << "Strange base in Domain_polar_nucleus:export_tau_inside" << endl ;
130  abort() ;
131  }
132  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) +
133  fact_t*(*so.cf)(pos_gal_t) + fact_rt*(*so.cf)(pos_gal_rt) ;
134  pos_sec++ ;
135  }
136  break ;
137  case COS_ODD:
138  assert ((baser==CHEB_ODD) || (baser==LEG_ODD)) ;
139  lquant = 2*j+1 ;
140  // True coefs ?
141  if ((j!=nbr_coefs(1)-1) && (i!=nbr_coefs(0)-rlim+1) && (i!=nbr_coefs(0)-rlim)) {
142  if ((mquant==0) && (lquant<=llim+1)) {
143  // No Galerkin :
144  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
145  pos_sec ++ ;
146  }
147  else {
148  if ((mquant==0) && (i!=0)) {
149  // Galerkin in r only :
150  pos_gal_r = pos_cf ;
151  pos_gal_r.set(0) = 0 ;
152  switch (baser) {
153  case CHEB_ODD :
154  fact_r = - (2*i+1) * pow(-1, i) ;
155  break ;
156  case LEG_ODD : {
157  fact_r = -double(4*i+3)/3. ;
158  for (int t=0 ; t<i ; t++)
159  fact_r *= -double(2*t+3)/double(2*t+2) ;
160  }
161  break ;
162  default :
163  cerr << "Strange base in Domain_polar_nucleus:export_tau_inside" << endl ;
164  abort() ;
165  }
166  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) ;
167  pos_sec ++ ;
168  }
169  else if ((j!=0) && (i!=0)) {
170  // Need to use two_dimensional Galerkin basis (aouch !)
171  pos_gal_r = pos_cf ;
172  pos_gal_r.set(0) = 0 ;
173  pos_gal_t = pos_cf ;
174  pos_gal_t.set(1) = 0 ;
175  pos_gal_rt = pos_cf ;
176  pos_gal_rt.set(0) = 0 ;
177  pos_gal_rt.set(1) = 0 ;
178  switch (baser) {
179  case CHEB_ODD :
180  fact_r = -pow(-1, i)*(2*i+1) ;
181  fact_t = -1. ;
182  fact_rt = pow(-1, i)*(2*i+1) ;
183  break ;
184  case LEG_ODD : {
185  double l0 = 1 ;
186  for (int t=0 ; t<i ; t++)
187  l0 *= -double(2*t+3)/double(2*t+2) ;
188  fact_r = - l0 * double(4*i+3)/3. ;
189  fact_t = -1. ;
190  fact_rt = l0*double(4*i+3)/3. ;
191  }
192  break ;
193  default :
194  cerr << "Strange base in Domain_polar_nucleus:export_tau_inside" << endl ;
195  abort() ;
196  }
197  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) +
198  fact_t*(*so.cf)(pos_gal_t) + fact_rt*(*so.cf)(pos_gal_rt) ;
199  pos_sec++ ;
200  }
201  }
202  }
203  break ;
204  case SIN_EVEN:
205  lquant = 2*j ;
206  if (j!=0) {
207  assert ((baser==CHEB_EVEN) || (baser==LEG_EVEN)) ;
208  if ((j!=0) && (j!=nbr_coefs(1)-1) && (i!=nbr_coefs(0)-rlim+1)) {
209  if ((mquant<=1) && (lquant<=llim)) {
210  // No Galerkin
211  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
212  pos_sec ++ ;
213  }
214  else {
215  if ((mquant<=1) && (i!=0)) {
216  // Galerkin base in r only
217  pos_gal_r = pos_cf ;
218  pos_gal_r.set(0) = 0 ;
219  switch (baser) {
220  case CHEB_EVEN :
221  fact_r = - 2 * pow(-1, i) ;
222  break ;
223  case LEG_EVEN : {
224  fact_r = -double(4*i+1) ;
225  for (int t=0 ; t<i ; t++)
226  fact_r *= -double(2*t+1)/double(2*t+2) ;
227  }
228  break ;
229  default :
230  cerr << "Strange base in Domain_polar_nucleus::export_tau_val_domain" << endl ;
231  abort() ;
232  }
233  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) ;
234  pos_sec ++ ;
235  }
236  else {
237  if ((j!=1) && (i!=0)) {
238  // Double Galerkin
239  pos_gal_r = pos_cf ;
240  pos_gal_r.set(0) = 0 ;
241  pos_gal_t = pos_cf ;
242  pos_gal_t.set(1) = 1 ;
243  pos_gal_rt = pos_cf ;
244  pos_gal_rt.set(0) = 0 ;
245  pos_gal_rt.set(1) = 1 ;
246  switch (baser) {
247  case CHEB_EVEN :
248  fact_r = -pow(-1, i) ;
249  fact_t = -j ;
250  fact_rt = pow(-1, i)*j ;
251  break ;
252  case LEG_EVEN : {
253  double l0 = 1 ;
254  for (int t=0 ; t<i ; t++)
255  l0 *= -double(2*t+1)/double(2*t+2) ;
256  fact_r = - l0 ;
257  fact_t = -j ;
258  fact_rt = l0*j ;
259  }
260  break ;
261  default :
262  cerr << "Strange base in Domain_polar_nucleus::affecte_tau_val_domain" << endl ;
263  abort() ;
264  }
265  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) +
266  fact_t*(*so.cf)(pos_gal_t) + fact_rt*(*so.cf)(pos_gal_rt) ;
267  pos_sec++ ;
268  }
269  }
270  }
271  }
272  }
273  break ;
274  case SIN_ODD:
275  lquant = 2*j+1 ;
276  assert ((baser==CHEB_ODD) || (baser==LEG_ODD)) ;
277  // True coefs ?
278  if ((j!=nbr_coefs(1)-1) && (i!=nbr_coefs(0)-rlim+1) && (i!=nbr_coefs(0)-rlim)) {
279  if ((mquant<=1) && (lquant<=llim+1)) {
280  // No Galerkin :
281  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
282  pos_sec ++ ;
283  }
284  else {
285  if ((mquant<=1) && (i!=0)) {
286  // Galerkin in r only :
287  pos_gal_r = pos_cf ;
288  pos_gal_r.set(0) = 0 ;
289  switch (baser) {
290  case CHEB_ODD :
291  fact_r = - (2*i+1) * pow(-1, i) ;
292  break ;
293  case LEG_ODD : {
294  fact_r = -double(4*i+3)/3. ;
295  for (int t=0 ; t<i ; t++)
296  fact_r *= -double(2*t+3)/double(2*t+2) ;
297  }
298  break ;
299  default :
300  cerr << "Strange base in Domain_polar_nucleus::export_tau_val_domain" << endl ;
301  abort() ;
302  }
303  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) ;
304  pos_sec ++ ;
305  }
306  else if ((j!=0) && (i!=0)) {
307  // Need to use two_dimensional Galerkin basis (aouch !)
308  pos_gal_r = pos_cf ;
309  pos_gal_r.set(0) = 0 ;
310  pos_gal_t = pos_cf ;
311  pos_gal_t.set(1) = 0 ;
312  pos_gal_rt = pos_cf ;
313  pos_gal_rt.set(0) = 0 ;
314  pos_gal_rt.set(1) = 0 ;
315  switch (baser) {
316  case CHEB_ODD :
317  fact_r = -pow(-1, i)*(2*i+1) ;
318  fact_t = -(2*j+1) ;
319  fact_rt = pow(-1, i)*(2*i+1)*(2*j+1) ;
320  break ;
321  case LEG_ODD : {
322  double l0 = 1 ;
323  for (int t=0 ; t<i ; t++)
324  l0 *= -double(2*t+3)/double(2*t+2) ;
325  fact_r = - l0 * double(4*i+3)/3. ;
326  fact_t = -(2*j+1) ;
327  fact_rt = l0*double(4*i+3)/3.*(2*j+1) ;
328  }
329  break ;
330  default :
331  cerr << "Strange base in Domain_polar_nucleus::export_tau_val_domain" << endl ;
332  abort() ;
333  }
334  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) +
335  fact_t*(*so.cf)(pos_gal_t) + fact_rt*(*so.cf)(pos_gal_rt) ;
336  pos_sec++ ;
337  }
338  }
339  }
340  break ;
341  default:
342  cerr << "Unknow theta basis in Domain_polar_nucleus::export_tau_inside" << endl ;
343  abort() ;
344  }
345  }
346  if (order==1)
347  rlim = 1 ;
348  }
349  }
350 }
351 
352 void Domain_polar_nucleus::export_tau (const Tensor& tt, int dom, int order, Array<double>& res, int& pos_res, const Array<int>& ncond,
353  int, Array<int>**) const {
354  int val = tt.get_valence() ;
355  switch (val) {
356  case 0 :
357  if (!tt.is_m_quant_affected())
358  export_tau_val_domain (tt()(dom), 0, 0, order, res, pos_res, ncond(0)) ;
359  else
360  export_tau_val_domain (tt()(dom), tt.get_parameters().get_m_quant(), 0, order, res, pos_res, ncond(0)) ;
361  break ;
362  default :
363  cerr << "Valence " << val << " not implemented in Domain_polar_nucleus::export_tau" << endl ;
364  break ;
365  }
366 }}
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 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.
void export_tau_val_domain(const Val_domain &eq, int mquant, int llim, int order, Array< double > &res, int &pos_res, int ncond) const
Exports a residual equation 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_quant() const
Returns .
Definition: tensor.hpp:747
Tensor handling.
Definition: tensor.hpp:149
const Param_tensor & get_parameters() const
Returns a pointer on the possible additional parameter.
Definition: tensor.hpp:311
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