KADATH
domain_compact_symphi_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 "array.hpp"
22 #include "spheric_symphi.hpp"
23 #include "val_domain.hpp"
24 #include "array_math.hpp"
25 namespace Kadath {
26 int mult_cos_1d (int, Array<double>&) ;
27 int mult_sin_1d (int, Array<double>&) ;
28 int div_sin_1d (int, Array<double>&) ;
29 int div_cos_1d (int, Array<double>&) ;
30 int mult_x_1d (int, Array<double>&) ;
31 int div_xp1_1d (int, Array<double>&) ;
32 int div_xm1_1d (int, Array<double>&) ;
33 int mult_xm1_1d (int, Array<double>&) ;
34 int div_1mx2_1d (int, Array<double>&) ;
35 
36 
38  so.coef() ;
39  Val_domain res(this) ;
40 
41  res.base= so.base ;
42 
43  res.cf = new Array<double> (so.base.ope_1d(mult_cos_1d, 2, *so.cf, res.base)) ;
44  res.in_coef = true ;
45  return res ;
46 }
47 
49  so.coef() ;
50  Val_domain res(this) ;
51 
52  res.base= so.base ;
53 
54  res.cf = new Array<double> (so.base.ope_1d(mult_sin_1d, 2, *so.cf, res.base)) ;
55  res.in_coef = true ;
56  return res ;
57 }
58 
60  so.coef() ;
61  Val_domain res(this) ;
62  res.base = so.base ;
63  res.cf = new Array<double> (so.base.ope_1d(mult_cos_1d, 1, *so.cf, res.base)) ;
64  res.in_coef = true ;
65  return res ;
66 }
67 
69 
70  so.coef() ;
71  Val_domain res(this) ;
72 
73  res.base= so.base ;
74  res.cf = new Array<double> (so.base.ope_1d(mult_sin_1d, 1, *so.cf, res.base)) ;
75  res.in_coef = true ;
76  return res ;
77 }
78 
80  so.coef() ;
81  Val_domain res(this) ;
82 
83  res.base = so.base ;
84 
85  res.cf = new Array<double> (so.base.ope_1d(div_sin_1d, 1, *so.cf, res.base)) ;
86  res.in_coef = true ;
87  return res ;
88 }
89 
91  so.coef() ;
92  Val_domain res(this) ;
93 
94  res.base = so.base ;
95 
96  res.cf = new Array<double> (so.base.ope_1d(div_cos_1d, 1, *so.cf, res.base)) ;
97  res.in_coef = true ;
98  return res ;
99 }
100 
102  so.coef() ;
103  Val_domain res(this) ;
104 
105  res.base = so.base ;
106 
107  res.cf = new Array<double> (so.base.ope_1d(div_xm1_1d, 0, *so.cf, res.base)) ;
108  res.in_coef = true ;
109  return res ;
110 }
111 
113  so.coef() ;
114  Val_domain res(this) ;
115 
116  res.base= so.base ;
117 
118  res.cf = new Array<double> (so.base.ope_1d(mult_xm1_1d, 0, *so.cf, res.base)) ;
119  res.in_coef = true ;
120  return res ;
121 }
122 
123 
125  so.coef() ;
126  Val_domain res(div_xm1(so)) ;
127  res /= alpha ;
128  return res ;
129 }
130 
132  so.coef() ;
133  Val_domain res(mult_xm1(so)) ;
134  res *= alpha ;
135  return res ;
136 }
137 
139  return (-alpha*so.der_var(1).mult_xm1().mult_xm1()) ;
140 }
141 
143  return (-so.der_var(1)/alpha) ;
144 }
145 
146 
148 
149  switch (which_var) {
150  case 0 :
151  return so.der_r() ;
152  break ;
153  case 1 :
154  return so.der_var(2) ;
155  break ;
156  case 2 :
157  return so.der_var(3) ;
158  default:
159  cerr << "Unknown variable in Domain_compact_symphi::der_partial_var" << endl ;
160  abort() ;
161  }
162 }
163 
164 
165 double integral_1d (int, const Array<double>&) ;
167 
168  if (so.check_if_zero())
169  return 0 ;
170  else {
171  Val_domain integrant (-mult_r(mult_r(mult_r(mult_r(mult_sin_theta(so)))))*alpha) ;
172  integrant.coef() ;
173 
174  double val = 0 ;
175  // Only k = 0
176  int baset = (*integrant.get_base().bases_1d[1]) (0) ;
177  assert(baset==SIN_ODD) ;
178  Index pos (nbr_coefs) ;
179  for (int j=0 ; j<nbr_coefs(1) ; j++) {
180  pos.set(1) = j ;
181  int baser = (*integrant.get_base().bases_1d[0]) (j, 0) ;
182  assert (baser==CHEB) ;
183 
184  Array<double> cf (nbr_coefs(0)) ;
185  for (int i=0 ; i<nbr_coefs(0) ; i++) {
186  pos.set(0) = i ;
187  cf.set(i) = integrant.get_coef(pos) ;
188  }
189  val += 2./(2.*j+1) * integral_1d(CHEB, cf) ;
190  }
191 
192  return val * 2*M_PI ;
193 }
194 }
195 
196 }
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.
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_cos_phi(const Val_domain &) const
Multiplication by .
double alpha
Relates the numerical to the physical radii.
virtual Val_domain div_xm1(const Val_domain &) const
Division by .
virtual Val_domain mult_sin_theta(const Val_domain &) const
Multiplication by .
virtual Val_domain div_cos_theta(const Val_domain &) const
Division by .
virtual Val_domain der_partial_var(const Val_domain &, int) const
Partial derivative with respect to a coordinate.
virtual Val_domain mult_cos_theta(const Val_domain &) const
Multiplication by .
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 double integ_volume(const Val_domain &so) const
Volume integral.
virtual Val_domain mult_xm1(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_r(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_sin_phi(const Val_domain &) const
Multiplication by .
virtual Val_domain div_r(const Val_domain &) const
Division by .
virtual Val_domain der_r_rtwo(const Val_domain &) const
Compute the radial derivative multiplied by of a scalar field.
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
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
bool check_if_zero() const
Check whether the logical state is zero or not.
Definition: val_domain.hpp:142
Val_domain der_r() const
Definition: val_domain.cpp:726
Array< double > * cf
Pointer on the Array of the values in the coefficients space.
Definition: val_domain.hpp:77
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