KADATH
domain_critic_outer.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 "utilities.hpp"
22 #include "critic.hpp"
23 #include "point.hpp"
24 #include "array_math.hpp"
25 #include "val_domain.hpp"
26 namespace Kadath {
27 // Standard constructor
28 Domain_critic_outer::Domain_critic_outer (int num, int ttype, const Dim_array& nbr, double xx) : Domain(num, ttype, nbr), p_X(nullptr), p_T(nullptr), xlim(xx) {
29  do_coloc() ;
30 }
31 
32 
33 // Constructor by copy
35  p_X = (so.p_X!=nullptr) ? new Val_domain(*so.p_X) : nullptr ;
36  p_T = (so.p_T!=nullptr) ? new Val_domain(*so.p_T) : nullptr ;
37  xlim = so.xlim ;
38 }
39 
40 
41 Domain_critic_outer::Domain_critic_outer (int num, FILE* fd) : Domain(num, fd) {
42  do_coloc() ;
43  p_X = nullptr ;
44  p_T = nullptr ;
45  fread_be (&xlim, sizeof(double), 1, fd) ;
46 }
47 
48 // Destructor
49 Domain_critic_outer::~Domain_critic_outer() {
50  del_deriv() ;
51 }
52 
54  for (int l=0 ; l<ndim ; l++) safe_delete(coloc[l]);
55  safe_delete(p_X);
56  safe_delete(p_T);
57 }
58 
59 void Domain_critic_outer::save (FILE* fd) const {
60  nbr_points.save(fd) ;
61  nbr_coefs.save(fd) ;
62  fwrite_be (&ndim, sizeof(int), 1, fd) ;
63  fwrite_be (&type_base, sizeof(int), 1, fd) ;
64  fwrite_be (&xlim, sizeof(double), 1, fd) ;
65 }
66 
67 ostream& Domain_critic_outer::print (ostream& o) const {
68  o << "Outer critic domain (cylindric)" << endl ;
69  o << "Nbr pts = " << nbr_points << endl ;
70  o << "X max = " << xlim << endl ;
71  o << endl ;
72  return o ;
73 }
74 
75 double coloc_leg_parity (int, int) ;
77 
78  switch (type_base) {
79  case CHEB_TYPE:
81  nbr_coefs.set(1) += 2 ;
82  del_deriv() ;
83  for (int i=0 ; i<ndim ; i++)
84  coloc[i] = new Array<double> (nbr_points(i)) ;
85  for (int i=0 ; i<nbr_points(0) ; i++)
86  coloc[0]->set(i) = (1.-xlim)/2.*(-cos(M_PI*i/(nbr_points(0)-1))) + (1.+xlim)/2. ;
87  for (int j=0 ; j<nbr_points(1) ; j++)
88  coloc[1]->set(j) = M_PI*j/nbr_points(1) ;
89  break ;
90  case LEG_TYPE:
92  nbr_coefs.set(1) += 2 ;
93  del_deriv() ;
94  for (int i=0 ; i<ndim ; i++)
95  coloc[i] = new Array<double> (nbr_points(i)) ;
96  for (int i=0 ; i<nbr_points(0) ; i++)
97  coloc[0]->set(i) = (1.-xlim)/2.*coloc_leg_parity(i, nbr_points(0)) + (1.+xlim)/2. ;
98  for (int j=0 ; j<nbr_points(1) ; j++)
99  coloc[1]->set(j) = M_PI*j/nbr_points(1) ;
100  break ;
101  default :
102  cerr << "Unknown type of basis in Domain_critic_outer::do_coloc" << endl ;
103  abort() ;
104  }
105 }
106 
108  for (int i=0 ; i<2 ; i++)
109  assert (coloc[i] != nullptr) ;
110  assert (p_X==nullptr) ;
111  p_X= new Val_domain(this) ;
112  p_X->allocate_conf() ;
113  Index index (nbr_points) ;
114  do
115  p_X->set(index) = (*coloc[0])(index(0)) ;
116  while (index.inc()) ;
117 }
118 
120  for (int i=0 ; i<2 ; i++)
121  assert (coloc[i] != nullptr) ;
122  assert (p_T==nullptr) ;
123  p_T= new Val_domain(this) ;
124  p_T->allocate_conf() ;
125  Index index (nbr_points) ;
126  do
127  p_T->set(index) = (*coloc[1])(index(1)) ;
128  while (index.inc()) ;
129 }
130 
131 
132 
134  if (p_X==nullptr)
135  do_X() ;
136  return *p_X ;
137 }
138 
140  if (p_T==nullptr)
141  do_T() ;
142  return *p_T ;
143 }
144 
145 bool Domain_critic_outer::is_in (const Point& xx, double prec) const {
146 
147  assert (xx.get_ndim()==2) ;
148  bool res = true ;
149  if ((xx(1)<xlim-prec) || (xx(1)>1.+prec))
150  res = false ;
151  if ((xx(2)<-prec) || (xx(2)>M_PI+prec))
152  res = false ;
153  return res ;
154 }
155 
157  for (int i=0 ; i<2 ; i++)
158  assert (coloc[i] != nullptr) ;
159  for (int i=0 ; i<2 ; i++)
160  assert (absol[i] == nullptr) ;
161  for (int i=0 ; i<2 ; i++) {
162  absol[i] = new Val_domain(this) ;
163  absol[i]->allocate_conf() ;
164  }
165  Index index (nbr_points) ;
166 
167  do {
168  absol[0]->set(index) = (*coloc[0])(index(0)) ;
169  absol[1]->set(index) = (*coloc[1])(index(1)) ;
170  }
171  while (index.inc()) ;
172 }
173 
175 
176  Point res(2) ;
177  res.set(1) = (so(1) - (1.+xlim)/2.) * 2. / (1.-xlim) ;
178  res.set(2) = so(2) ;
179  return res ;
180 }
181 
182 // standard base
184  assert (type_base == CHEB_TYPE) ;
185 
186  base.allocate(nbr_coefs) ;
187  base.def =true ;
188  base.bases_1d[1]->set(0) = COSSIN_EVEN ;
189  for (int k=0 ; k<nbr_coefs(1) ; k++)
190  base.bases_1d[0]->set(k) = CHEB ;
191 }
192 
193 // standard base
195  assert (type_base == CHEB_TYPE) ;
196 
197  base.allocate(nbr_coefs) ;
198  base.def =true ;
199  base.bases_1d[1]->set(0) = COSSIN_EVEN ;
200  for (int k=0 ; k<nbr_coefs(1) ; k++)
201  base.bases_1d[0]->set(k) = LEG ;
202 }
203 
204 
205 // standard base
207 
208  assert (type_base == CHEB_TYPE) ;
209 
210  base.allocate(nbr_coefs) ;
211  base.def =true ;
212  base.bases_1d[1]->set(0) = COSSIN_ODD ;
213  for (int k=0 ; k<nbr_coefs(1) ; k++)
214  base.bases_1d[0]->set(k) = CHEB ;
215 }
216 
217 // standard base
219  assert (type_base == LEG_TYPE) ;
220 
221  base.allocate(nbr_coefs) ;
222  base.def =true ;
223  base.bases_1d[1]->set(0) = COSSIN_ODD ;
224  for (int k=0 ; k<nbr_coefs(1) ; k++)
225  base.bases_1d[0]->set(k) = LEG ;
226 }
227 
228 // Rules for the multiplication of two basis.
230 
231  assert (a.ndim==2) ;
232  assert (b.ndim==2) ;
233 
234  Base_spectral res(2) ;
235  bool res_def = true ;
236 
237  if (!a.def)
238  res_def=false ;
239  if (!b.def)
240  res_def=false ;
241 
242  if (res_def) {
243 
244  // Base in phi :
245  res.bases_1d[1] = new Array<int> (a.bases_1d[1]->get_dimensions()) ;
246  switch ((*a.bases_1d[1])(0)) {
247  case COSSIN_EVEN:
248  switch ((*b.bases_1d[1])(0)) {
249  case COSSIN_EVEN:
250  res.bases_1d[1]->set(0) = COSSIN_EVEN ;
251  break ;
252  case COSSIN_ODD:
253  res.bases_1d[1]->set(0) = COSSIN_ODD ;
254  break ;
255  default:
256  res_def = false ;
257  break ;
258  }
259  break ;
260  case COSSIN_ODD:
261  switch ((*b.bases_1d[1])(0)) {
262  case COSSIN_EVEN:
263  res.bases_1d[1]->set(0) = COSSIN_ODD ;
264  break ;
265  case COSSIN_ODD:
266  res.bases_1d[1]->set(0) = COSSIN_EVEN ;
267  break ;
268  default:
269  res_def = false ;
270  break ;
271  }
272  break ;
273  default:
274  res_def = false ;
275  break ;
276  }
277 
278  res.bases_1d[0] = new Array<int> (a.bases_1d[0]->get_dimensions()) ;
279  for (int k=0 ; k<nbr_coefs(1) ; k++) {
280  switch ((*a.bases_1d[0])(k)) {
281  case CHEB :
282  switch ((*b.bases_1d[0])(k)) {
283  case CHEB :
284  res.bases_1d[0]->set(k) = CHEB ;
285  break ;
286  default :
287  res_def = false ;
288  break ;
289  }
290  break ;
291  case LEG :
292  switch ((*b.bases_1d[0])(k)) {
293  case LEG :
294  res.bases_1d[0]->set(k) = LEG ;
295  break ;
296  default :
297  res_def = false ;
298  break ;
299  }
300  break ;
301  default :
302  res_def = false ;
303  break ;
304  }
305  }
306  }
307 
308  if (!res_def)
309  for (int dim=0 ; dim<a.ndim ; dim++)
310  if (res.bases_1d[dim]!= nullptr) {
311  delete res.bases_1d[dim] ;
312  res.bases_1d[dim] = nullptr ;
313  }
314  res.def = res_def ;
315  return res ;
316 }
317 
319  int res = -1 ;
320  if (strcmp(p,"X ")==0)
321  res = 0 ;
322  if (strcmp(p,"T ")==0)
323  res = 1 ;
324  return res ;
325 }}
Class for storing the basis of decompositions of a field.
Bases_container bases_1d
Arrays containing the various basis of decomposition.
void allocate(const Dim_array &nbr_coefs)
Allocates the various arrays, for a given number of coefficients.
bool def
true if the Base_spectral is defined and false otherwise.
int ndim
Number of dimensions.
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
int & set(int i)
Read/write of the size of a given dimension.
Definition: dim_array.hpp:54
void save(FILE *) const
Save function.
Definition: dim_array.cpp:32
Class for a 2-dimensional cylindrical type domain.
Definition: critic.hpp:197
virtual void set_legendre_todd_base(Base_spectral &) const
Gives the base using Legendre polynomials, for odd functions in (critic space case)
virtual void set_legendre_base(Base_spectral &) const
Gives the standard base for Legendre polynomials.
virtual const Point absol_to_num(const Point &xxx) const
Computes the numerical coordinates from the physical ones.
Domain_critic_outer(int num, int ttype, const Dim_array &nbr, double xl)
Standard constructor :
virtual void save(FILE *) const
Saving function.
virtual void set_cheb_base(Base_spectral &so) const
Gives the standard base for Chebyshev polynomials.
virtual const Val_domain & get_X() const
Returns the variable .
virtual void set_cheb_todd_base(Base_spectral &so) const
Gives the base using Chebyshev polynomials, for odd functions in (critic space case)
virtual Base_spectral mult(const Base_spectral &, const Base_spectral &) const
Method for the multiplication of two Base_spectral.
double xlim
Relates the numerical to the variable.
Definition: critic.hpp:202
virtual const Val_domain & get_T() const
Returns the variable .
virtual int give_place_var(char *) const
Translates a name of a coordinate into its corresponding numerical name.
virtual void do_absol() const
Computes the absolute coordinates.
virtual bool is_in(const Point &xx, double prec=1e-13) const
Check whether a point lies inside Domain.
virtual void do_coloc()
Computes the colocation points.
void del_deriv() override
Destroys the derivated members (like coloc, cart and radius), when changing the type of colocation po...
virtual ostream & print(ostream &o) const
Delegate function to virtualize the << operator.
Val_domain * p_T
Pointer on the variable.
Definition: critic.hpp:201
Val_domain * p_X
Pointer on the variable.
Definition: critic.hpp:200
Abstract class that implements the fonctionnalities common to all the type of domains.
Definition: space.hpp:60
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
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
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
double & set(const Index &pos)
Read/write the value of the field in the configuration space.
Definition: val_domain.cpp:171
void allocate_conf()
Allocates the values in the configuration space and destroys the values in the coefficients space.
Definition: val_domain.cpp:209