KADATH
base_spectral.hpp
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 #ifndef __BASE_SPECTRAL_HPP_
21 #define __BASE_SPECTRAL_HPP_
22 
23 #include "dim_array.hpp"
24 #include "array.hpp"
25 
26 enum : int {
27  NBR_MAX_BASE = 30,
28  CHEB = 1,
29  CHEB_EVEN = 2,
30  CHEB_ODD = 3,
31  COSSIN = 4,
32  COS = 5,
33  COS_EVEN = 6,
34  COS_ODD = 7,
35  SIN = 8,
36  SIN_EVEN = 9,
37  SIN_ODD = 10,
38  LEG = 11,
39  LEG_EVEN = 12,
40  LEG_ODD = 13,
41  COSSIN_EVEN = 14,
42  COSSIN_ODD = 15
43 };
44 
45 namespace Kadath {
46  class Point ;
47 
69  class Base_spectral : public Memory_mapped {
70  public:
72  using Bases_container = Memory_mapped_array<Array<int>*,int>;
73 
74  protected:
75  bool def;
76  int ndim;
81  // Array<int>** bases_1d ;
83 
84  public:
89  explicit Base_spectral(int dimensions) : def{false}, ndim{dimensions}, bases_1d{ndim} {
90  for (int i = 0; i < ndim; i++) bases_1d[i] = nullptr;
91  }
92 
93  Base_spectral(const Base_spectral &so);
94  Base_spectral(FILE *);
97 
98  public:
99  ~Base_spectral() {for (int l = 0; l < ndim; l++) if (bases_1d[l] != nullptr) delete bases_1d[l];}
100  void save(FILE*) const ;
101  public:
105  void swap(Base_spectral & so) ;
109  bool is_def () const {return def;} ;
110 
114  void set_non_def() ;
115 
117 
119  const Array<int>* get_base_1d (int i) const {return bases_1d[i] ;} ;
124  void allocate (const Dim_array& nbr_coefs) ;
133  void set(Dim_array const& nbr_coefs, int basephi, int basetheta, int baser);
134 
141  void coef_dim (int var, int nbr, Array<double> *& tab) const ;
148  Array<double> coef (const Dim_array& nbr_coefs, const Array<double> & so) const ;
155  void coef_i_dim (int var, int nbr, Array<double> *& tab) const ;
162  Array<double> coef_i (const Dim_array& nbr_points, const Array<double> & so) const ;
169  double summation (const Point& num, const Array<double>& tab) const ;
180  Array<double> ope_1d (int (*function) (int, Array<double>&),
181  int var , const Array<double>& so, Base_spectral& base) const ;
182 
183  friend bool operator== (const Base_spectral&, const Base_spectral&) ;
184  friend ostream& operator<< (ostream& o, const Base_spectral&) ;
185  friend class Space ;
186  friend class Space_spheric ;
187  friend class Scalar ;
188  friend class Domain_nucleus ;
189  friend class Domain_shell ;
190  friend class Domain_shell_log ;
191  friend class Domain_compact ;
192  friend class Domain_bispheric_rect ;
193  friend class Domain_bispheric_chi_first ;
194  friend class Domain_bispheric_eta_first ;
195  friend class Domain_critic_inner ;
196  friend class Domain_critic_outer ;
197  friend class Domain_polar_nucleus ;
198  friend class Domain_polar_shell ;
199  friend class Domain_polar_shell_inner_adapted ;
200  friend class Domain_polar_shell_outer_adapted ;
201  friend class Domain_polar_compact ;
202  friend class Domain_oned_ori ;
203  friend class Domain_oned_qcq ;
204  friend class Domain_oned_inf ;
205  friend class Domain_spheric_periodic_nucleus ;
206  friend class Domain_spheric_periodic_shell ;
207  friend class Domain_spheric_periodic_compact ;
208  friend class Domain_spheric_time_nucleus ;
209  friend class Domain_spheric_time_shell ;
210  friend class Domain_spheric_time_compact ;
211  friend class Domain_shell_inner_adapted ;
212  friend class Domain_shell_outer_adapted ;
213  friend class Domain_shell_inner_homothetic ;
214  friend class Domain_shell_outer_homothetic ;
215  friend class Domain_nucleus_symphi ;
216  friend class Domain_shell_symphi ;
217  friend class Domain_compact_symphi ;
218  friend class Domain_polar_periodic_nucleus ;
219  friend class Domain_polar_periodic_shell ;
220  friend class Domain_fourD_periodic_nucleus ;
221  friend class Domain_fourD_periodic_shell ;
222  } ;
223 
224  inline Base_spectral::Base_spectral(const Base_spectral &so) : def{so.def}, ndim{so.ndim}, bases_1d{ndim} {
225  for (int l = 0; l < ndim; l++)
226  bases_1d[l] = (so.bases_1d[l] == nullptr) ? nullptr : new Array<int>(*so.bases_1d[l]);
227  }
228 
229  inline Base_spectral::Base_spectral(Base_spectral &&so) : def{so.def}, ndim{0}, bases_1d{} {
230  std::swap(ndim, so.ndim);
231  std::swap(bases_1d, so.bases_1d);
232  so.def = false;
233  }
234 
236  std::swap(def,so.def);
237  ndim = so.ndim;
238  std::swap(bases_1d,so.bases_1d);
239  return *this;
240  }
241 
243  for (int l=0 ; l<ndim ; l++)
244  if (bases_1d[l] !=0x0) {
245  delete bases_1d[l] ;
246  bases_1d[l] = 0x0 ;
247  }
248  def = false ;
249  }
250 
252  assert (ndim==so.ndim) ;
253  def = so.def ;
254  for (int i=0 ; i<ndim ; i++) {
255  if (bases_1d[i] != nullptr) delete bases_1d[i] ;
256  if ((so.def) && (so.bases_1d[i] != nullptr))
257  bases_1d[i] = new Array<int>(*so.bases_1d[i]) ;
258  else
259  bases_1d[i] = nullptr ;
260  }
261  return *this;
262  }
263 
264  inline void Base_spectral::swap(Base_spectral & so) {
265  std::swap(def,so.def);
266  std::swap(ndim,so.ndim);
267  bases_1d.swap(so.bases_1d);
268  }
269 
270  inline bool operator== (const Base_spectral& a, const Base_spectral& b) {
271  bool res {(a.def) && (b.def) && (a.ndim == b.ndim)} ;
272  for (int i=0 ; i<a.ndim ; i++) {
273  Array_iterator index (a.bases_1d[i]->get_dimensions()) ;
274  do
275  res = ((*a.bases_1d[i])(index) == (*b.bases_1d[i])(index)) ;
276  while (index.inc() && res) ;
277  }
278  return res ;
279  }
280 }
281 #endif
Version of the Index class optimized for incremental access to Array components.
bool inc(int increm, int var=0)
Increments the position of the Array_iterator.
Class for storing the basis of decompositions of a field.
Base_spectral(int dimensions)
Standard constructor, the Base_spectral is not defined.
void save(FILE *) const
Saving function.
void coef_i_dim(int var, int nbr, Array< double > *&tab) const
Performs the inverse coefficient transformation for one particular variable.
Definition: coef_i.cpp:28
Array< double > coef(const Dim_array &nbr_coefs, const Array< double > &so) const
Definition: coef.cpp:96
friend bool operator==(const Base_spectral &, const Base_spectral &)
Comparison operator.
Base_spectral & operator=(Base_spectral &&so)
Move assignment operator.
friend ostream & operator<<(ostream &o, const Base_spectral &)
Display.
Array< double > coef_i(const Dim_array &nbr_points, const Array< double > &so) const
Definition: coef_i.cpp:96
Bases_container bases_1d
Arrays containing the various basis of decomposition.
Memory_mapped_array< Array< int > *, int > Bases_container
Sylvain'stuff.
void coef_dim(int var, int nbr, Array< double > *&tab) const
Definition: coef.cpp:28
void set(Dim_array const &nbr_coefs, int basephi, int basetheta, int baser)
Allocates the various arrays, for a given number of coefficients and sets basis to some values (same ...
double summation(const Point &num, const Array< double > &tab) const
Computes the spectral summation.
const Array< int > * get_base_1d(int i) const
Returns one of the 1d base array.
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.
void set_non_def()
Sets all the basis to the undefined state.
~Base_spectral()
Destructor.
void swap(Base_spectral &so)
Swaps data between the source and this.
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
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
Class for bispherical coordinates with a symmetry with respect to the plane .
Definition: bispheric.hpp:460
Class for bispherical coordinates with a symmetry with respect to the plane .
Definition: bispheric.hpp:878
Class for bispherical coordinates with a symmetry with respect to the plane .
Definition: bispheric.hpp:64
Class for a spherical compactified domain and a symmetry with respect to the plane and a quadrant sy...
Class for a spherical compactified domain and a symmetry with respect to the plane .
Definition: spheric.hpp:1007
Class for a 2-dimensional cylindrical type domain.
Definition: critic.hpp:45
Class for a 2-dimensional cylindrical type domain.
Definition: critic.hpp:197
Class for a spherical nucleus.
Class for a spherical shell.
Class for a spherical domain containing the origin a symmetry with respect to the plane and an quadr...
Class for a spherical domain containing the origin and a symmetry with respect to the plane .
Definition: spheric.hpp:66
Class for a 1-dimensional compactified spherical domain.
Definition: oned.hpp:319
Class for a 1-dimensional spherical domain containing the origin.
Definition: oned.hpp:40
Class for a 1-dimensional spherical domain bounded between two raii.
Definition: oned.hpp:179
Class for a 2-dimensional spherical shell and a symmetry with respect to the plane .
Definition: polar.hpp:408
Class for a 2-dimensional spherical domain containing the origin and a symetry with respect to the pl...
Definition: polar.hpp:45
Class for a spherical nucleus with a symmetry in .
Class for a spherical shell with a symmetry in .
Class for a spherical-like domain, having a symmetry with respect to the plane .
Class for a spherical-like domain, having a symmetry with respect to the plane .
Class for a 2-dimensional spherical shell and a symmetry with respect to the plane .
Definition: polar.hpp:221
Class for a spherical-like domain, having a symmetry with respect to the plane .
Definition: adapted.hpp:51
Class for a spherical-like domain, having a symmetry with respect to the plane .
Definition: homothetic.hpp:45
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:1507
Class for a spherical-like domain, having a symmetry with respect to the plane .
Definition: adapted.hpp:367
Class for a spherical-like domain, having a symmetry with respect to the plane .
Definition: homothetic.hpp:105
Class for a spherical shell and a symmetry with respect to the plane and an quadrant symmetry wrt .
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:555
Class for a 2-dimensional compactified spherical domain and a symetry with respect to the plane .
Class for a 2-dimensional spherical domain containing the origin and a symetry with respect to the pl...
Class for a 2-dimensional spherical domain bounded between two fixed radii and a symetry with respect...
Class for a 2-dimensional compactified spherical domain and a symetry with respect to the plane .
Class for a 2-dimensional spherical domain containing the origin and a symetry with respect to the pl...
Class for a 2-dimensional spherical domain bounded between two finite radii and a symetry with respec...
The class Point is used to store the coordinates of a point.
Definition: point.hpp:30
The class Scalar does not really implements scalars in the mathematical sense but rather tensorial co...
Definition: scalar.hpp:67
The Space_spheric class fills the space with one nucleus, several shells and a compactified domain,...
Definition: spheric.hpp:1350
The Space class is an ensemble of domains describing the whole space of the computation.
Definition: space.hpp:1362