KADATH
domain_polar_compact_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_xm1_1d (int, Array<double>&) ;
29 int mult_xm1_1d (int, Array<double>&) ;
30 int div_xp1_1d (int, Array<double>&) ;
31 
33  so.coef() ;
34  Val_domain res(this) ;
35 
36  res.base = so.base ;
37 
38  res.cf = new Array<double> (so.base.ope_1d(mult_cos_1d, 1, *so.cf, res.base)) ;
39  res.in_coef = true ;
40  return res ;
41 }
42 
44  so.coef() ;
45  Val_domain res(this) ;
46 
47  res.base= so.base ;
48 
49  res.cf = new Array<double> (so.base.ope_1d(mult_sin_1d, 1, *so.cf, res.base)) ;
50  res.in_coef = true ;
51  return res ;
52 }
53 
55  so.coef() ;
56  Val_domain res(this) ;
57 
58  res.base = so.base ;
59 
60  res.cf = new Array<double> (so.base.ope_1d(div_sin_1d, 1, *so.cf, res.base)) ;
61  res.in_coef = true ;
62  return res ;
63 }
64 
65 
67  so.coef() ;
68  Val_domain res(this) ;
69 
70  res.base= so.base ;
71 
72  res.cf = new Array<double> (so.base.ope_1d(mult_xm1_1d, 0, *so.cf, res.base)) ;
73  res.in_coef = true ;
74  return res ;
75 }
76 
78  so.coef() ;
79  Val_domain res(this) ;
80 
81  res.base = so.base ;
82 
83  res.cf = new Array<double> (so.base.ope_1d(div_xm1_1d, 0, *so.cf, res.base)) ;
84  res.in_coef = true ;
85  return res ;
86 }
87 
89  so.coef() ;
90  Val_domain res(div_xm1(so)) ;
91  res /= alpha ;
92  return res ;
93 }
94 
96  so.coef() ;
97  Val_domain res(mult_xm1(so)) ;
98  res *= alpha ;
99  return res ;
100 }
101 
103  Val_domain derr (-alpha*so.der_var(1).mult_xm1().mult_xm1()) ;
104  Val_domain dderr (-alpha*derr.der_var(1).mult_xm1().mult_xm1()) ;
105  Val_domain dert (so.der_var(2)) ;
106  Val_domain res (dderr + div_r(2*derr + div_r(dert.der_var(2) + dert.mult_cos_theta().div_sin_theta()))) ;
107  if (m!=0)
108  res -= m * m * div_r(div_r(so.div_sin_theta().div_sin_theta())) ;
109  return res ;
110 }
111 
113  Val_domain derr (-alpha*so.der_var(1).mult_xm1().mult_xm1()) ;
114  Val_domain dderr (-alpha*derr.der_var(1).mult_xm1().mult_xm1()) ;
115  Val_domain dert (so.der_var(2)) ;
116  Val_domain res (dderr + div_r(derr + div_r(dert.der_var(2)))) ;
117  if (m!=0)
118  res -= m * m * div_r(div_r(so.div_sin_theta().div_sin_theta())) ;
119  return res ;
120 }
121 
123  return (-alpha*so.der_var(1).mult_xm1().mult_xm1()) ;
124 }
125 
126 
128  return (so.der_var(2)) ;
129 }
130 
132  return (-so.der_var(1)/alpha) ;
133 }
134 
135 
137  so.coef() ;
138  Val_domain res(this) ;
139 
140  res.base= so.base ;
141 
142  res.cf = new Array<double> (so.base.ope_1d(div_xp1_1d, 0, *so.cf, res.base)) ;
143  res.in_coef = true ;
144  return res ;
145 }
146 
147 double Domain_polar_compact::integrale (const Val_domain& so) const {
148  double res = 0 ;
149  Val_domain integrant (so) ;
150 
151  for (int i=0 ; i<3 ; i++) {
152  Val_domain auxi (integrant.div_xm1()) ;
153  auxi.coef_i() ;
154  set_val_inf(auxi, 0.) ; //Filtering
155  integrant = auxi ;
156  }
157 
158  integrant.coef() ;
159  integrant.get_coef() ;
160  Array<double> cf (integrant.get_coef()) ;
161 
162  int baset = (*integrant.get_base().bases_1d[1]) (0) ;
163  switch (baset) {
164  case COS_ODD :
165  break ;
166  case SIN_EVEN :
167  break ;
168  case COS_EVEN : {
169  // Only m=0 :
170  double facttheta = M_PI ;
171  int baser = (*integrant.get_base().bases_1d[0]) (0) ;
172  switch (baser) {
173  case CHEB : {
174  for (int i=0 ; i<nbr_coefs(0) ; i+=2) {
175  res += facttheta * (1./double(i+1) - 1./double(i-1)) *cf(i,0) ;
176  }
177  break ;
178  }
179  case LEG : {
180  res += facttheta*2*cf(0,0) ;
181  break ;
182  }
183  default :
184  cerr << "Case not yet implemented in Domain_polar_compact::integrale" << endl ;
185  abort() ;
186  }
187  break ;
188  }
189  case SIN_ODD : {
190  for (int j=0 ; j<nbr_coefs(1) ; j++) {
191  double facttheta = 2./double(2*j+1) ;
192  int baser = (*integrant.get_base().bases_1d[0]) (0) ;
193  switch (baser) {
194  case CHEB : {
195  for (int i=0 ; i<nbr_coefs(0) ; i+=2)
196  res += facttheta * (1./double(i+1) - 1./double(i-1)) *cf(i,j) ;
197  break ;
198  }
199  case LEG : {
200  res += facttheta*2*cf(0,j) ;
201  break ;
202  }
203  default :
204  cerr << "Case not yet implemented in Domain_polar_compact::integrale" << endl ;
205  abort() ;
206  }
207  }
208  break ;
209  }
210  default :
211  cerr << "Case not yet implemented in Domain_polar_compact::integrale" << endl ;
212  abort() ;
213  }
214 
215  // Phi contribution :
216  res *= -1./alpha/alpha ;
217  return res ;
218 }
219 
221  return integrale(so) ;
222 }
223 
224  }
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 mult_sin_theta(const Val_domain &) const
Multiplication by .
virtual void set_val_inf(Val_domain &so, double xx) const
Sets the value at infinity of a Val_domain : not implemented for this type of Domain.
virtual double integ_volume(const Val_domain &) const
Volume integral.
virtual Val_domain div_r(const Val_domain &) const
Division by .
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 der_r_rtwo(const Val_domain &) const
Compute the radial derivative multiplied by of a scalar field.
double alpha
Relates the numerical to the physical radii.
Definition: polar.hpp:411
virtual double integrale(const Val_domain &) const
Volume integral.
virtual Val_domain mult_cos_theta(const Val_domain &) const
Multiplication by .
virtual Val_domain div_xp1(const Val_domain &) const
Division by .
virtual Val_domain div_sin_theta(const Val_domain &) const
Division by .
virtual Val_domain div_xm1(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 dt(const Val_domain &) const
Compute the derivative with respect to of a scalar field.
virtual Val_domain mult_r(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_xm1(const Val_domain &) const
Multiplication by .
virtual Val_domain der_r(const Val_domain &) const
Compute the radial derivative of a scalar field.
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
Val_domain div_xm1() const
Division by .
Array< double > * cf
Pointer on the Array of the values in the coefficients space.
Definition: val_domain.hpp:77
void coef_i() const
Computes the values in the configuration space.
Definition: val_domain.cpp:637
Val_domain div_sin_theta() const
Division by .
Val_domain mult_cos_theta() const
Multiplication by .
Val_domain mult_xm1() 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