KADATH
domain_shell_log.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 
22 #include "utilities.hpp"
23 #include "spheric.hpp"
24 #include "val_domain.hpp"
25 namespace Kadath {
26 // Standard constructor
27 Domain_shell_log::Domain_shell_log (int num, int ttype, double rint, double rext, const Point& cr, const Dim_array& nbr) : Domain_shell(num, ttype, rint, rext, cr, nbr) {
28  alpha = (log(rext)-log(rint))/2. ;
29  beta = (log(rext)+log(rint))/2. ;
30  assert (nbr.get_ndim()==3) ;
31  assert (cr.get_ndim()==3) ; // Affectation de type_point :
32  do_coloc() ;
33 
34 }
35 
36 
37 // Constructor by copy
38 Domain_shell_log::Domain_shell_log (const Domain_shell_log& so) : Domain_shell(so) {
39 
40  // Update the alpha and beta
41  double rint = (beta - alpha) ;
42  double rext = (beta+alpha) ;
43  alpha = (log(rext)-log(rint))/2. ;
44  beta = (log(rext)+log(rint))/2. ;
45 }
46 
47 
48 
49 Domain_shell_log::Domain_shell_log (int num, FILE* fd) : Domain_shell(num, fd) {
50  do_coloc() ;
51 }
52 
53 // Destructor
54 Domain_shell_log::~Domain_shell_log() {}
55 
56 void Domain_shell_log::save (FILE* fd) const {
57  nbr_points.save(fd) ;
58  nbr_coefs.save(fd) ;
59  fwrite_be (&ndim, sizeof(int), 1, fd) ;
60  fwrite_be (&type_base, sizeof(int), 1, fd) ;
61  center.save(fd) ;
62  fwrite_be (&alpha, sizeof(double), 1, fd) ;
63  fwrite_be (&beta, sizeof(double), 1, fd) ;
64 }
65 
66 ostream& Domain_shell_log::print (ostream& o) const {
67  o << "Shell log" << endl ;
68  o << exp(beta-alpha) << " < r < " << exp(beta+alpha) << endl ;
69  o << "Center = " << center << endl ;
70  o << "Nbr pts = " << nbr_points << endl ;
71  o << endl ;
72  return o ;
73 }
74 
75 
76 
77 Val_domain Domain_shell_log::der_normal (const Val_domain& so, int bound) const {
78 
79  if ((bound!=OUTER_BC) && (bound!=INNER_BC)) {
80  cerr << "Unknown boundary case in Domain_shell_log::der_normal" << endl ;
81  abort() ;
82  }
83  return der_r (so) ;
84 }
85 
86 // Computes the Cartesian coordinates
88  for (int i=0 ; i<3 ; i++)
89  assert (coloc[i] != 0x0) ;
90  for (int i=0 ; i<3 ; i++)
91  assert (absol[i] == 0x0) ;
92  for (int i=0 ; i<3 ; i++) {
93  absol[i] = new Val_domain(this) ;
94  absol[i]->allocate_conf() ;
95  }
96  Index index (nbr_points) ;
97 
98  do {
99  absol[0]->set(index) = exp(alpha* ((*coloc[0])(index(0))) +beta)*
100  sin((*coloc[1])(index(1)))*cos((*coloc[2])(index(2))) + center(1) ;
101  absol[1]->set(index) = exp(alpha* ((*coloc[0])(index(0))) +beta) *
102  sin((*coloc[1])(index(1)))*sin((*coloc[2])(index(2))) + center(2) ;
103  absol[2]->set(index) = exp(alpha* ((*coloc[0])(index(0))) + beta) * cos((*coloc[1])(index(1))) + center(3) ;
104  }
105  while (index.inc()) ;
106 }
107 
108 // Computes the radius
110  for (int i=0 ; i<3 ; i++)
111  assert (coloc[i] != 0x0) ;
112  assert (radius == 0x0) ;
113  radius = new Val_domain(this) ;
114  radius->allocate_conf() ;
115  Index index (nbr_points) ;
116  do
117  radius->set(index) = exp(alpha* ((*coloc[0])(index(0))) + beta) ;
118  while (index.inc()) ;
119  radius->std_base() ;
120 }
121 
122 // Computes the Cartesian coordinates
124  for (int i=0 ; i<3 ; i++)
125  assert (coloc[i] != 0x0) ;
126  for (int i=0 ; i<3 ; i++)
127  assert (cart[i] == 0x0) ;
128  for (int i=0 ; i<3 ; i++) {
129  cart[i] = new Val_domain(this) ;
130  cart[i]->allocate_conf() ;
131  }
132  Index index (nbr_points) ;
133 
134  do {
135  cart[0]->set(index) = exp(alpha* ((*coloc[0])(index(0))) +beta)*
136  sin((*coloc[1])(index(1)))*cos((*coloc[2])(index(2))) + center(1) ;
137  cart[1]->set(index) = exp(alpha* ((*coloc[0])(index(0))) +beta) *
138  sin((*coloc[1])(index(1)))*sin((*coloc[2])(index(2))) + center(2) ;
139  cart[2]->set(index) = exp(alpha* ((*coloc[0])(index(0))) + beta) * cos((*coloc[1])(index(1))) + center(3) ;
140  }
141  while (index.inc()) ;
142 }
143 
144 // Check if a point is inside this domain
145 bool Domain_shell_log::is_in (const Point& xx, double prec) const {
146 
147  assert (xx.get_ndim()==3) ;
148 
149  double x_loc = xx(1) - center(1) ;
150  double y_loc = xx(2) - center(2) ;
151  double z_loc = xx(3) - center(3) ;
152  double air_loc = sqrt (x_loc*x_loc + y_loc*y_loc + z_loc*z_loc) ;
153 
154  bool res = ((air_loc/exp(alpha+beta) -1 <= +prec) && (air_loc/exp(beta-alpha) -1 >= -prec)) ? true : false ;
155  return res ;
156 }
157 
158 //Computes the numerical coordinates, as a function of the absolute ones.
159 const Point Domain_shell_log::absol_to_num(const Point& abs) const {
160 
161  assert (is_in(abs)) ;
162  Point num(3) ;
163 
164  double x_loc = abs(1) - center(1) ;
165  double y_loc = abs(2) - center(2) ;
166  double z_loc = abs(3) - center(3) ;
167  double air = sqrt(x_loc*x_loc+y_loc*y_loc+z_loc*z_loc) ;
168  num.set(1) = (log(air)-beta)/alpha ;
169  double rho = sqrt(x_loc*x_loc+y_loc*y_loc) ;
170 
171  if (rho==0) {
172  // On the axis ?
173  num.set(2) = (z_loc>=0) ? 0 : M_PI ;
174  num.set(3) = 0 ;
175  }
176  else {
177  num.set(2) = atan(rho/z_loc) ;
178  num.set(3) = atan2 (y_loc, x_loc) ;
179  }
180 
181  if (num(2) <0)
182  num.set(2) = M_PI + num(2) ;
183 
184  return num ;
185 }
186 
187 
188 // Convert absolute coordinates to numerical ones
189 const Point Domain_shell_log::absol_to_num_bound(const Point& abs, int bound) const {
190 
191  assert ((bound==OUTER_BC) || (bound==INNER_BC)) ;
192  assert (is_in(abs, 1e-3)) ;
193  Point num(3) ;
194 
195  double x_loc = abs(1) - center(1) ;
196  double y_loc = abs(2) - center(2) ;
197  double z_loc = abs(3) - center(3) ;
198 
199  switch (bound) {
200  case INNER_BC:
201  num.set(1) = -1 ;
202  break ;
203  case OUTER_BC:
204  num.set(1) = 1 ;
205  break ;
206  default:
207  cerr << "unknown boundary in Domain_shell::absol_to_num" << endl ;
208  abort() ;
209  }
210 
211  double rho = sqrt(x_loc*x_loc+y_loc*y_loc) ;
212 
213  if (rho==0) {
214  // Sur l'axe
215  num.set(2) = (z_loc>=0) ? 0 : M_PI ;
216  num.set(3) = 0 ;
217  }
218  else {
219  num.set(2) = atan(rho/z_loc) ;
220  num.set(3) = atan2 (y_loc, x_loc) ;
221  }
222 
223  if (num(2) <0)
224  num.set(2) = M_PI + num(2) ;
225 
226  return num ;
227 }
228 
229 // Computes the derivatives with respect to XYZ as a function of the numerical ones.
230 void Domain_shell_log::do_der_abs_from_der_var(const Val_domain *const *const der_var, Val_domain **const der_abs) const {
231 
232  // d/dx :
233  Val_domain sintdr (der_var[0]->mult_sin_theta()/alpha/get_radius()) ;
234  Val_domain dtsr (*der_var[1]/get_radius()) ;
235  dtsr.set_base() = der_var[1]->get_base() ;
236  Val_domain dpsr (*der_var[2]/get_radius()) ;
237  dpsr.set_base() = der_var[2]->get_base() ;
238  Val_domain costdtsr (dtsr.mult_cos_theta()) ;
239 
240  Val_domain dpsrssint (dpsr.div_sin_theta()) ;
241  der_abs[0] = new Val_domain ((sintdr+costdtsr).mult_cos_phi() - dpsrssint.mult_sin_phi()) ;
242 
243  // d/dy :
244  der_abs[1] = new Val_domain ((sintdr+costdtsr).mult_sin_phi() + dpsrssint.mult_cos_phi()) ;
245  // d/dz :
246  der_abs[2] = new Val_domain (der_var[0]->mult_cos_theta()/alpha/get_radius() - dtsr.mult_sin_theta()) ;
247 }
248 
249 
250 }
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
int get_ndim() const
Returns the number of dimensions.
Definition: dim_array.hpp:63
void save(FILE *) const
Save function.
Definition: dim_array.cpp:32
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:1507
virtual const Point absol_to_num_bound(const Point &, int) const
Computes the numerical coordinates from the physical ones for a point lying on a boundary.
virtual void do_absol() const
Computes the absolute coordinates.
virtual void do_der_abs_from_der_var(const Val_domain *const *const der_var, Val_domain **const der_abs) const
Computes the derivative with respect to the absolute Cartesian coordinates from the derivative with r...
virtual Val_domain der_normal(const Val_domain &, int) const
Normal derivative with respect to a given surface.
virtual void do_radius() const
Computes the generalized radius.
virtual Val_domain der_r(const Val_domain &) const
Compute the radial derivative of a scalar field.
virtual const Point absol_to_num(const Point &xxx) const
Computes the numerical coordinates from the physical ones.
virtual bool is_in(const Point &xx, double prec=1e-13) const
Check whether a point lies inside Domain.
virtual ostream & print(ostream &o) const
Delegate function to virtualize the << operator.
virtual void save(FILE *) const
Saving function.
virtual void do_cart() const
Computes the Cartesian coordinates.
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:555
virtual Val_domain mult_cos_theta(const Val_domain &) const
Multiplication by .
double beta
Relates the numerical to the physical radii.
Definition: spheric.hpp:559
double alpha
Relates the numerical to the physical radii.
Definition: spheric.hpp:558
virtual void do_coloc()
Computes the colocation points.
virtual Val_domain mult_cos_phi(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_sin_phi(const Val_domain &) const
Multiplication by .
Point center
Absolute coordinates of the center.
Definition: spheric.hpp:560
virtual Val_domain mult_sin_theta(const Val_domain &) const
Multiplication by .
Val_domain * radius
The generalized radius.
Definition: space.hpp:78
Memory_mapped_array< Val_domain * > cart
Cartesian coordinates.
Definition: space.hpp:77
Memory_mapped_array< Val_domain * > absol
Asbolute coordinates (if defined ; usually Cartesian-like)
Definition: space.hpp:76
int ndim
Number of dimensions.
Definition: space.hpp:64
Dim_array nbr_coefs
Number of coefficients.
Definition: space.hpp:66
Val_domain const & get_radius() const
Returns the generalized radius.
Definition: space.hpp:1465
Dim_array nbr_points
Number of colocation points.
Definition: space.hpp:65
int type_base
Type of colocation point :
Definition: space.hpp:73
Memory_mapped_array< Array< double > * > coloc
Colocation points in each dimension (stored in ndim 1d- arrays)
Definition: space.hpp:75
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
The class Point is used to store the coordinates of a point.
Definition: point.hpp:30
void save(FILE *) const
Saving function.
Definition: point.cpp:33
const int & get_ndim() const
Returns the number of dimensions.
Definition: point.hpp:51
double & set(int i)
Read/write of a coordinate.
Definition: point.hpp:47
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
Val_domain mult_sin_phi() const
Multiplication by .
Val_domain mult_sin_theta() const
Multiplication by .
Val_domain mult_cos_phi() const
Multiplication by .
double & set(const Index &pos)
Read/write the value of the field in the configuration space.
Definition: val_domain.cpp:171
void std_base()
Sets the standard basis of decomposition.
Definition: val_domain.cpp:246
Val_domain div_sin_theta() const
Division by .
Val_domain mult_cos_theta() const
Multiplication by .
Base_spectral & set_base()
Sets the basis of decomposition.
Definition: val_domain.hpp:126
void allocate_conf()
Allocates the values in the configuration space and destroys the values in the coefficients space.
Definition: val_domain.cpp:209
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122