KADATH
domain_polar_nucleus_ope.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 "val_domain.hpp"
23 #include "array_math.hpp"
24 namespace Kadath {
25 int mult_cos_1d (int, Array<double>&) ;
26 int mult_sin_1d (int, Array<double>&) ;
27 int div_sin_1d (int, Array<double>&) ;
28 int div_x_1d (int, Array<double>&) ;
29 int mult_x_1d (int, Array<double>&) ;
30 
32  so.coef() ;
33  Val_domain res(this) ;
34  res.base = so.base ;
35  res.cf = new Array<double> (so.base.ope_1d(mult_cos_1d, 1, *so.cf, res.base)) ;
36  res.in_coef = true ;
37  return res ;
38 }
39 
41 
42  so.coef() ;
43  Val_domain res(this) ;
44 
45  res.base= so.base ;
46  res.cf = new Array<double> (so.base.ope_1d(mult_sin_1d, 1, *so.cf, res.base)) ;
47  res.in_coef = true ;
48  return res ;
49 }
50 
52  so.coef() ;
53  Val_domain res(this) ;
54 
55  res.base = so.base ;
56 
57  res.cf = new Array<double> (so.base.ope_1d(div_sin_1d, 1, *so.cf, res.base)) ;
58  res.in_coef = true ;
59  return res ;
60 }
61 
63  so.coef() ;
64  Val_domain res(this) ;
65 
66  res.base= so.base ;
67 
68  res.cf = new Array<double> (so.base.ope_1d(div_x_1d, 0, *so.cf, res.base)) ;
69  res.in_coef = true ;
70  return res ;
71 }
72 
74  so.coef() ;
75  Val_domain res(this) ;
76 
77  res.base= so.base ;
78 
79  res.cf = new Array<double> (so.base.ope_1d(mult_x_1d, 0, *so.cf, res.base)) ;
80  *res.cf *= alpha ;
81  res.in_coef = true ;
82  return res ;
83 }
84 
86  so.coef() ;
87  Val_domain res(this) ;
88 
89  res.base= so.base ;
90 
91  res.cf = new Array<double> (so.base.ope_1d(div_x_1d, 0, *so.cf, res.base)) ;
92  *res.cf /= alpha ;
93  res.in_coef = true ;
94  return res ;
95 }
96 
98  return (div_x(so.der_var(1)) / alpha / alpha) ;
99 }
100 
102  Val_domain derr (so.der_var(1)/alpha) ;
103  Val_domain dert (so.der_var(2)) ;
104  Val_domain res (derr.der_var(1)/alpha + div_r(derr + div_r(dert.der_var(2)))) ;
105  if (m!=0)
106  res -= m * m * div_r(div_r(so.div_sin_theta().div_sin_theta())) ;
107  return res ;
108 }
109 
111  Val_domain derr (so.der_var(1)/alpha) ;
112  Val_domain dert (so.der_var(2)) ;
113  Val_domain res (derr.der_var(1)/alpha + div_r(2*derr + div_r(dert.der_var(2) + dert.mult_cos_theta().div_sin_theta()))) ;
114  if (m!=0)
115  res -= m * m * div_r(div_r(so.div_sin_theta().div_sin_theta())) ;
116  return res ;
117 }
118 
120  return (so.der_var(1)/alpha) ;
121 }
122 
124  return (so.der_var(2)) ;
125 }
126 
127 double Domain_polar_nucleus::integrale (const Val_domain& so) const {
128  double res = 0 ;
129  Val_domain integrant (mult_r(so)) ;
130  integrant.get_coef() ;
131  Array<double> cf (integrant.get_coef()) ;
132 
133  int baset = (*integrant.get_base().bases_1d[1]) (0) ;
134  switch (baset) {
135  case COS_ODD :
136  break ;
137  case SIN_EVEN :
138  break ;
139  case COS_EVEN : {
140  // Only m=0 :
141  double facttheta = M_PI ;
142  int baser = (*integrant.get_base().bases_1d[0]) (0) ;
143  switch (baser) {
144  case CHEB_EVEN : {
145  for (int i=0 ; i<nbr_coefs(0) ; i++)
146  res += -facttheta / (4*i*i-1)*cf(i,0) ;
147  break ;
148  }
149  case CHEB_ODD : {
150  for (int i=0 ; i<nbr_coefs(0)-1 ; i++)
151  res += (i%2==0) ? facttheta / double (2*i+2) *cf(i,0) : -facttheta/double (2*i) *cf(i,0) ;
152  break ;
153  }
154  case LEG_EVEN : {
155  res += facttheta*cf(0,0) ;
156  break ;
157  }
158  case LEG_ODD : {
159  double pm1 = 1 ;
160  double pp1 = -0.5 ;
161  for (int i=0 ; i<nbr_coefs(0)-1 ; i++) {
162  res += facttheta * (pm1 - pp1) / double(4*i+3) ;
163  pm1 = pp1 ;
164  pp1 *= -double(2*i+3)/double(2*i+4) ;
165  }
166  break ;
167  }
168  default :
169  cerr << "Case not yet implemented in Domain_polar_nucleus::integrale" << endl ;
170  abort() ;
171  }
172  break ;
173  }
174  case SIN_ODD : {
175  for (int j=0 ; j<nbr_coefs(1) ; j++) {
176  double facttheta = 2./double(2*j+1) ;
177  int baser = (*integrant.get_base().bases_1d[0]) (0) ;
178  switch (baser) {
179  case CHEB_EVEN : {
180  for (int i=0 ; i<nbr_coefs(0) ; i++) {
181  res += -facttheta / double(4*i*i-1) * cf(i,j) ;
182  }
183  break ;
184  }
185  case CHEB_ODD : {
186  res += facttheta/2. * cf(0,j);
187  int signe = -1 ;
188  for (int i=1 ; i<nbr_coefs(0)-1 ; i++) {
189  res += facttheta *(-1. + signe * double(2*i+1))/((2*i+1)*(2*i+1)-1) * cf(i,j) ;
190  signe *= -1 ;
191  }
192  break ;
193  }
194  case LEG_EVEN : {
195  res += facttheta*cf(0,j) ;
196  break ;
197  }
198  case LEG_ODD : {
199  double pm1 = 1 ;
200  double pp1 = -0.5 ;
201  for (int i=0 ; i<nbr_coefs(0)-1 ; i++) {
202  res += facttheta * (pm1 - pp1) / double(4*i+3)*cf(i,j) ;
203  pm1 = pp1 ;
204  pp1 *= -double(2*i+3)/double(2*i+4) ;
205  }
206  break ;
207  }
208  default :
209  cerr << "Case not yet implemented in Domain_polar_nucleus::integrale" << endl ;
210  abort() ;
211  }
212 
213  }
214  break ;
215  }
216  default :
217  cerr << "Case not yet implemented in Domain_polar_nucleus::integrale" << endl ;
218  abort() ;
219  }
220  // Phi contribution :
221  //res *= 2*M_PI*alpha ;
222  res *= alpha ;
223  return res ;
224 }
225 
227  return integrale(so) ;
228 }
229 
230 }
Bases_container bases_1d
Arrays containing the various basis of decomposition.
Array< double > ope_1d(int(*function)(int, Array< double > &), int var, const Array< double > &so, Base_spectral &base) const
One-dimensional operator acting in the coefficient space.
Definition: ope_1d.cpp:26
virtual Val_domain div_sin_theta(const Val_domain &) const
Division by .
virtual Val_domain der_r(const Val_domain &) const
Compute the radial derivative of a scalar field.
virtual Val_domain div_r(const Val_domain &) const
Division by .
virtual Val_domain laplacian2(const Val_domain &, int) const
Computes the ordinary flat 2dè- Laplacian for a scalar field with an harmonic index m.
virtual Val_domain laplacian(const Val_domain &, int) const
Computes the ordinary flat Laplacian for a scalar field with an harmonic index m.
virtual Val_domain div_x(const Val_domain &) const
Division by .
virtual double integrale(const Val_domain &) const
Volume integral.
virtual Val_domain mult_sin_theta(const Val_domain &) const
Multiplication by .
virtual double integ_volume(const Val_domain &) const
Volume integral.
virtual Val_domain mult_r(const Val_domain &) const
Multiplication by .
virtual Val_domain srdr(const Val_domain &) const
Compute the of a scalar field .
virtual Val_domain dt(const Val_domain &) const
Compute the derivative with respect to of a scalar field.
virtual Val_domain mult_cos_theta(const Val_domain &) const
Multiplication by .
double alpha
Relates the numerical to the physical radii.
Definition: polar.hpp:48
Dim_array nbr_coefs
Number of coefficients.
Definition: space.hpp:66
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
Base_spectral base
Spectral basis of the field.
Definition: val_domain.hpp:72
Array< double > * cf
Pointer on the Array of the values in the coefficients space.
Definition: val_domain.hpp:77
Val_domain div_sin_theta() const
Division by .
Val_domain mult_cos_theta() const
Multiplication by .
bool in_coef
Is the field known in the coefficient space ?
Definition: val_domain.hpp:79
void coef() const
Computes the coefficients.
Definition: val_domain.cpp:622
Val_domain der_var(int i) const
Computes the derivative with respect to a numerical coordinate.
Definition: val_domain.cpp:670
Array< double > get_coef() const
Definition: val_domain.hpp:136
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122