KADATH
domain_nucleus_symphi_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 "spheric_symphi.hpp"
22 #include "array_math.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
28 void Domain_nucleus_symphi::export_tau_val_domain (const Val_domain& so, int order, Array<double>& sec, int& pos_sec, int ncond) const {
29 
30  if (so.check_if_zero())
31  pos_sec += ncond ;
32  else {
33 
34  int rlim = 0 ;
35  switch (order) {
36  case 2 :
37  rlim = order ;
38  break ;
39  case 0 :
40  rlim = 1 ;
41  break ;
42  default :
43  cerr << "Unknown case in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
44  abort() ;
45  }
46 
47  so.coef() ;
48 
49  Index pos_cf (nbr_coefs) ;
50  // Positions of the Galerkin basis
51  Index pos_gal_t (nbr_coefs) ;
52  Index pos_gal_r (nbr_coefs) ;
53  Index pos_gal_rt (nbr_coefs) ;
54  double fact_t, fact_r, fact_rt ;
55 
56 
57  int mquant, kmin, kmax ;
58  // Base in phi
59  int basep = (*so.get_base().bases_1d[2]) (0) ;
60  switch (basep) {
61  case COS_EVEN:
62  kmin = 0 ;
63  kmax = nbr_coefs(2)-1 ;
64  break ;
65  case COS_ODD:
66  kmin = 0 ;
67  kmax = nbr_coefs(2)-2 ;
68  break ;
69  case SIN_EVEN:
70  kmin = 1 ;
71  kmax = nbr_coefs(2)-2 ;
72  break ;
73  case SIN_ODD:
74  kmin = 0 ;
75  kmax = nbr_coefs(2)-2 ;
76  break ;
77  default:
78  cerr << "Unknow phi basis in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
79  abort() ;
80  }
81 
82 
83 
84  int lquant ;
85  // Loop on phi :
86  for (int k=kmin ; k<=kmax ; k++) {
87 
88  switch (basep) {
89  case COS_EVEN:
90  mquant = 2*k ;
91  break ;
92  case COS_ODD:
93  mquant = 2*k+1 ;
94  break ;
95  case SIN_EVEN:
96  mquant = 2*k ;
97  break ;
98  case SIN_ODD:
99  mquant = 2*k+1 ;
100  break ;
101  default:
102  cerr << "Unknow phi basis in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
103  abort() ;
104  }
105 
106 
107 
108  pos_cf.set(2) = k ;
109  // Loop on theta
110  int baset = (*so.get_base().bases_1d[1]) (k) ;
111  for (int j=0 ; j<nbr_coefs(1) ; j++) {
112  int baser = (*so.get_base().bases_1d[0]) (j, k) ;
113  pos_cf.set(1) = j ;
114  // Loop on r :
115  for (int i=0 ; i<nbr_coefs(0) ; i++) {
116  pos_cf.set(0) = i ;
117  switch (baset) {
118  case COS_EVEN :
119  assert ((baser==LEG_EVEN) || (baser==CHEB_EVEN)) ;
120  lquant = 2*j ;
121  // No galerkin :
122  if ((mquant==0) && (lquant==0)) {
123  if (i!=nbr_coefs(0)-rlim+1) {
124  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
125  pos_sec ++ ;
126  }
127  }
128  else if (mquant==0) {
129  if ((i!=0) && (i!=nbr_coefs(0)-rlim+1)) {
130  // Galerkin base in r only
131  pos_gal_r = pos_cf ;
132  pos_gal_r.set(0) = 0 ;
133  switch (baser) {
134  case CHEB_EVEN :
135  fact_r = - 2 * pow(-1, i) ;
136  break ;
137  case LEG_EVEN : {
138  fact_r = -double(4*i+1) ;
139  for (int t=0 ; t<i ; t++)
140  fact_r *= -double(2*t+1)/double(2*t+2) ;
141  }
142  break ;
143  default :
144  cerr << "Strange base in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
145  abort() ;
146  }
147 
148  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) ;
149  pos_sec ++ ;
150  }
151  }
152  else if ((j!=0) && (i!=0) && (i!=nbr_coefs(0)-rlim+1)) {
153  // Need to use two_dimensional Galerkin basis (aouch !)
154  pos_gal_r = pos_cf ;
155  pos_gal_r.set(0) = 0 ;
156  pos_gal_t = pos_cf ;
157  pos_gal_t.set(1) = 0 ;
158  pos_gal_rt = pos_cf ;
159  pos_gal_rt.set(0) = 0 ;
160  pos_gal_rt.set(1) = 0 ;
161  switch (baser) {
162  case CHEB_EVEN :
163  fact_r = -2*pow(-1, i) ;
164  fact_t = -2 ;
165  fact_rt = 4*pow(-1, i) ;
166  break ;
167  case LEG_EVEN : {
168  double l0 = 1 ;
169  for (int t=0 ; t<i ; t++)
170  l0 *= -double(2*t+1)/double(2*t+2) ;
171  fact_r = - l0 * double(4*i+1) ;
172  fact_t = -2 ;
173  fact_rt = 2*double(4*i+1)*l0 ;
174  }
175  break ;
176  default :
177  cerr << "Strange base in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
178  abort() ;
179  }
180  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) +
181  fact_t*(*so.cf)(pos_gal_t) + fact_rt*(*so.cf)(pos_gal_rt) ;
182  pos_sec++ ;
183  }
184  break ;
185  case COS_ODD:
186  assert ((baser==CHEB_ODD) || (baser==LEG_ODD)) ;
187  lquant = 2*j+1 ;
188  // True coefs ?
189  if ((j!=nbr_coefs(1)-1) && (i!=nbr_coefs(0)-rlim+1) && (i!=nbr_coefs(0)-rlim)) {
190  if ((mquant==0) && (lquant<=1)) {
191  // No Galerkin :
192  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
193  pos_sec ++ ;
194  }
195  else {
196  if ((mquant==0) && (i!=0)) {
197  // Galerkin in r only :
198  pos_gal_r = pos_cf ;
199  pos_gal_r.set(0) = 0 ;
200  switch (baser) {
201  case CHEB_ODD :
202  fact_r = - (2*i+1) * pow(-1, i) ;
203  break ;
204  case LEG_ODD : {
205  fact_r = -double(4*i+3)/3. ;
206  for (int t=0 ; t<i ; t++)
207  fact_r *= -double(2*t+3)/double(2*t+2) ;
208  }
209  break ;
210  default :
211  cerr << "Strange base in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
212  abort() ;
213  }
214  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) ;
215  pos_sec ++ ;
216  }
217  else if ((j!=0) && (i!=0)) {
218  // Need to use two_dimensional Galerkin basis (aouch !)
219  pos_gal_r = pos_cf ;
220  pos_gal_r.set(0) = 0 ;
221  pos_gal_t = pos_cf ;
222  pos_gal_t.set(1) = 0 ;
223  pos_gal_rt = pos_cf ;
224  pos_gal_rt.set(0) = 0 ;
225  pos_gal_rt.set(1) = 0 ;
226  switch (baser) {
227  case CHEB_ODD :
228  fact_r = -pow(-1, i)*(2*i+1) ;
229  fact_t = -1. ;
230  fact_rt = pow(-1, i)*(2*i+1) ;
231  break ;
232  case LEG_ODD : {
233  double l0 = 1 ;
234  for (int t=0 ; t<i ; t++)
235  l0 *= -double(2*t+3)/double(2*t+2) ;
236  fact_r = - l0 * double(4*i+3)/3. ;
237  fact_t = -1. ;
238  fact_rt = l0*double(4*i+3)/3. ;
239  }
240  break ;
241  default :
242  cerr << "Strange base in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
243  abort() ;
244  }
245  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) +
246  fact_t*(*so.cf)(pos_gal_t) + fact_rt*(*so.cf)(pos_gal_rt) ;
247  pos_sec++ ;
248  }
249  }
250  }
251  break ;
252  case SIN_EVEN:
253  lquant = 2*j ;
254  if (j!=0) {
255  assert ((baser==CHEB_EVEN) || (baser==LEG_EVEN)) ;
256  if ((j!=nbr_coefs(1)-1) && (i!=nbr_coefs(0)-rlim+1)) {
257  if ((mquant<=1) && (lquant==0)) {
258  // No Galerkin
259  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
260  pos_sec ++ ;
261  }
262  else {
263  if ((mquant<=1) && (i!=0)) {
264  // Galerkin base in r only
265  pos_gal_r = pos_cf ;
266  pos_gal_r.set(0) = 0 ;
267  switch (baser) {
268  case CHEB_EVEN :
269  fact_r = - 2 * pow(-1, i) ;
270  break ;
271  case LEG_EVEN : {
272  fact_r = -double(4*i+1) ;
273  for (int t=0 ; t<i ; t++)
274  fact_r *= -double(2*t+1)/double(2*t+2) ;
275  }
276  break ;
277  default :
278  cerr << "Strange base in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
279  abort() ;
280  }
281  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) ;
282  pos_sec ++ ;
283  }
284  else {
285  if ((j!=1) && (i!=0)) {
286  // Double Galerkin
287  pos_gal_r = pos_cf ;
288  pos_gal_r.set(0) = 0 ;
289  pos_gal_t = pos_cf ;
290  pos_gal_t.set(1) = 1 ;
291  pos_gal_rt = pos_cf ;
292  pos_gal_rt.set(0) = 0 ;
293  pos_gal_rt.set(1) = 1 ;
294  switch (baser) {
295  case CHEB_EVEN :
296  fact_r = -pow(-1, i) ;
297  fact_t = -j ;
298  fact_rt = pow(-1, i)*j ;
299  break ;
300  case LEG_EVEN : {
301  double l0 = 1 ;
302  for (int t=0 ; t<i ; t++)
303  l0 *= -double(2*t+1)/double(2*t+2) ;
304  fact_r = - l0 ;
305  fact_t = -j ;
306  fact_rt = l0*j ;
307  }
308  break ;
309  default :
310  cerr << "Strange base in Domain_nucleus_symphi::affecte_tau_val_domain" << endl ;
311  abort() ;
312  }
313  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) +
314  fact_t*(*so.cf)(pos_gal_t) + fact_rt*(*so.cf)(pos_gal_rt) ;
315  pos_sec++ ;
316  }
317  }
318  }
319  }
320  }
321  break ;
322  case SIN_ODD:
323  lquant = 2*j+1 ;
324  assert ((baser==CHEB_ODD) || (baser==LEG_ODD)) ;
325  // True coefs ?
326  if ((j!=nbr_coefs(1)-1) && (i!=nbr_coefs(0)-rlim+1) && (i!=nbr_coefs(0)-rlim)) {
327  if ((mquant<=1) && (lquant<=1)) {
328  // No Galerkin :
329  sec.set(pos_sec) = (*so.cf)(pos_cf) ;
330  pos_sec ++ ;
331  }
332  else {
333  if ((mquant<=1) && (i!=0)) {
334  // Galerkin in r only :
335  pos_gal_r = pos_cf ;
336  pos_gal_r.set(0) = 0 ;
337  switch (baser) {
338  case CHEB_ODD :
339  fact_r = - (2*i+1) * pow(-1, i) ;
340  break ;
341  case LEG_ODD : {
342  fact_r = -double(4*i+3)/3. ;
343  for (int t=0 ; t<i ; t++)
344  fact_r *= -double(2*t+3)/double(2*t+2) ;
345  }
346  break ;
347  default :
348  cerr << "Strange base in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
349  abort() ;
350  }
351  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) ;
352  pos_sec ++ ;
353  }
354  else if ((j!=0) && (i!=0)) {
355  // Need to use two_dimensional Galerkin basis (aouch !)
356  pos_gal_r = pos_cf ;
357  pos_gal_r.set(0) = 0 ;
358  pos_gal_t = pos_cf ;
359  pos_gal_t.set(1) = 0 ;
360  pos_gal_rt = pos_cf ;
361  pos_gal_rt.set(0) = 0 ;
362  pos_gal_rt.set(1) = 0 ;
363  switch (baser) {
364  case CHEB_ODD :
365  fact_r = -pow(-1, i)*(2*i+1) ;
366  fact_t = -(2*j+1) ;
367  fact_rt = pow(-1, i)*(2*i+1)*(2*j+1) ;
368  break ;
369  case LEG_ODD : {
370  double l0 = 1 ;
371  for (int t=0 ; t<i ; t++)
372  l0 *= -double(2*t+3)/double(2*t+2) ;
373  fact_r = - l0 * double(4*i+3)/3. ;
374  fact_t = -(2*j+1) ;
375  fact_rt = l0*double(4*i+3)/3.*(2*j+1) ;
376  }
377  break ;
378  default :
379  cerr << "Strange base in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
380  abort() ;
381  }
382  sec.set(pos_sec) = (*so.cf)(pos_cf) + fact_r*(*so.cf)(pos_gal_r) +
383  fact_t*(*so.cf)(pos_gal_t) + fact_rt*(*so.cf)(pos_gal_rt) ;
384  pos_sec++ ;
385  }
386  }
387  }
388  break ;
389  default:
390  cerr << "Unknow theta basis in Domain_nucleus_symphi::export_tau_val_domain" << endl ;
391  abort() ;
392  }
393  }
394  }
395  }
396  }
397 }
398 
399 void Domain_nucleus_symphi::export_tau (const Tensor& tt, int dom, int order, Array<double>& res, int& pos_res, const Array<int>& ncond,
400  int n_cmp, Array<int>** p_cmp) const {
401  int val = tt.get_valence() ;
402  switch (val) {
403  case 0 :
404  export_tau_val_domain (tt()(dom), order, res, pos_res, ncond(0)) ;
405  break ;
406  case 1 : {
407  bool found = false ;
408  // Cartesian basis
409  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
410  if (n_cmp==-1) {
411  export_tau_val_domain (tt(1)(dom), order, res, pos_res, ncond(0)) ;
412  export_tau_val_domain (tt(2)(dom), order, res, pos_res, ncond(1)) ;
413  export_tau_val_domain (tt(3)(dom), order, res, pos_res, ncond(2)) ;
414  }
415  else for (int i=0 ; i<n_cmp ; i++) {
416  if ((*p_cmp[i])(0)==1)
417  export_tau_val_domain (tt(1)(dom), order, res, pos_res, ncond(i)) ;
418  if ((*p_cmp[i])(0)==2)
419  export_tau_val_domain (tt(2)(dom), order, res, pos_res, ncond(i)) ;
420  if ((*p_cmp[i])(0)==3)
421  export_tau_val_domain (tt(3)(dom), order, res, pos_res, ncond(i)) ;
422  }
423  found = true ;
424  }
425 
426  if (!found) {
427  cerr << "Unknown type of vector Domain_nucleus_symphi::export_tau" << endl ;
428  abort() ;
429  }
430  }
431  break ;
432  case 2 : {
433  bool found = false ;
434  // Cartesian basis and symetric
435  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
436  if (n_cmp==-1) {
437  export_tau_val_domain (tt(1,1)(dom), order, res, pos_res, ncond(0)) ;
438  export_tau_val_domain (tt(1,2)(dom), order, res, pos_res, ncond(1)) ;
439  export_tau_val_domain (tt(1,3)(dom), order, res, pos_res, ncond(2)) ;
440  export_tau_val_domain (tt(2,2)(dom), order, res, pos_res, ncond(3)) ;
441  export_tau_val_domain (tt(2,3)(dom), order, res, pos_res, ncond(4)) ;
442  export_tau_val_domain (tt(3,3)(dom), order, res, pos_res, ncond(5)) ;
443  }
444  else for (int i=0 ; i<n_cmp ; i++) {
445  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
446  export_tau_val_domain (tt(1, 1)(dom), order, res, pos_res, ncond(i)) ;
447  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
448  export_tau_val_domain (tt(1, 2)(dom), order, res, pos_res, ncond(i)) ;
449  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
450  export_tau_val_domain (tt(1, 3)(dom), order, res, pos_res, ncond(i)) ;
451  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
452  export_tau_val_domain (tt(2, 2)(dom), order, res, pos_res, ncond(i)) ;
453  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
454  export_tau_val_domain (tt(2, 3)(dom), order, res, pos_res, ncond(i)) ;
455  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
456  export_tau_val_domain (tt(3, 3)(dom), order, res, pos_res, ncond(i)) ;
457  }
458  found = true ;
459  }
460  // Cartesian basis and not symetric
461  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
462  if (n_cmp==-1) {
463  export_tau_val_domain (tt(1,1)(dom), order, res, pos_res, ncond(0)) ;
464  export_tau_val_domain (tt(1,2)(dom), order, res, pos_res, ncond(1)) ;
465  export_tau_val_domain (tt(1,3)(dom), order, res, pos_res, ncond(2)) ;
466  export_tau_val_domain (tt(2,1)(dom), order, res, pos_res, ncond(3)) ;
467  export_tau_val_domain (tt(2,2)(dom), order, res, pos_res, ncond(4)) ;
468  export_tau_val_domain (tt(2,3)(dom), order, res, pos_res, ncond(5)) ;
469  export_tau_val_domain (tt(3,1)(dom), order, res, pos_res, ncond(6)) ;
470  export_tau_val_domain (tt(3,2)(dom), order, res, pos_res, ncond(7)) ;
471  export_tau_val_domain (tt(3,3)(dom), order, res, pos_res, ncond(8)) ;
472  }
473  else for (int i=0 ; i<n_cmp ; i++) {
474  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
475  export_tau_val_domain (tt(1, 1)(dom), order, res, pos_res, ncond(i)) ;
476  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
477  export_tau_val_domain (tt(1, 2)(dom), order, res, pos_res, ncond(i)) ;
478  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
479  export_tau_val_domain (tt(1, 3)(dom), order, res, pos_res, ncond(i)) ;
480  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
481  export_tau_val_domain (tt(2, 1)(dom), order, res, pos_res, ncond(i)) ;
482  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
483  export_tau_val_domain (tt(2, 2)(dom), order, res, pos_res, ncond(i)) ;
484  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
485  export_tau_val_domain (tt(2, 3)(dom), order, res, pos_res, ncond(i)) ;
486  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
487  export_tau_val_domain (tt(3, 1)(dom), order, res, pos_res, ncond(i)) ;
488  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
489  export_tau_val_domain (tt(3, 2)(dom), order, res, pos_res, ncond(i)) ;
490  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
491  export_tau_val_domain (tt(3, 3)(dom), order, res, pos_res, ncond(i)) ;
492  }
493  found = true ;
494  }
495  if (!found) {
496  cerr << "Unknown type of 2-tensor Domain_nucleus_symphi::export_tau" << endl ;
497  abort() ;
498  }
499  }
500  break ;
501  default :
502  cerr << "Valence " << val << " not implemented in Domain_nucleus_symphi::export_tau" << endl ;
503  break ;
504  }
505 }
506 }
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 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
Tensor handling.
Definition: tensor.hpp:149
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
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