SPI
SLEPc PETSc Interface is used for rapid development and intuitive matrix operations similar to MatLab or NumPy style of operations
SPIgrid.hpp
Go to the documentation of this file.
1 #ifndef SPIGRID_H
2 #define SPIGRID_H
3 #include "SPIVec.hpp"
4 #include "SPIMat.hpp"
5 #include "SPIprint.hpp"
6 #include <string>
7 
8 namespace SPI{
9  PetscInt factorial(PetscInt n); // compute and return the factorial of n
10  SPIVec get_D_Coeffs( SPIVec &s, PetscInt d ); // get the coefficients of the given stencil s
11  SPIMat map_D(SPIMat D, SPIVec y, PetscInt d, PetscInt order=4); // map the derivative operator to the proper y grid
12  SPIMat set_D(SPIVec &y, PetscInt d, PetscInt order=4, PetscBool uniform=PETSC_FALSE); // get derivative operator using finite difference stencils
13  SPIMat set_D_periodic(SPIVec &y, PetscInt d, PetscInt order=4); // get derivative operator using finite difference stencils for uniform periodic grid
14  SPIVec set_FD_stretched_y(PetscScalar y_max,PetscInt ny,PetscScalar delta=2.0001); // set stretched grid from [0,y_max] using tanh stretching
15  SPIMat set_D_Chebyshev(SPIVec &x, PetscInt d=1, PetscBool need_map=PETSC_FALSE); // set a chebyshev operator acting on the collocated grid
16  SPIMat map_D_Chebyshev(SPIVec &x, PetscInt d=1); // map the chebyshev operator to the proper x grid
17  SPIVec set_Cheby_stretched_y(PetscScalar y_max, PetscInt ny, PetscScalar yi=10.); // create chebyshev stretched grid from [0, y_max]
18  SPIVec set_Cheby_mapped_y(PetscScalar a, PetscScalar b, PetscInt ny); // create a mapped Chebyshev grid on domain from [a,b]
19  SPIVec set_Cheby_y(PetscInt ny); // create Chebyshev collocated grid on [-1,1]
20  SPIVec set_Fourier_t(PetscScalar T, PetscInt ny); // create Fourier collocated grid on [0,T]
21  SPIMat set_D_Fourier(SPIVec t, PetscInt d=1); // create Fourier collocated grid derivative operator acting on t
22  std::tuple<SPIMat,SPIMat> set_D_UltraS(SPIVec &x, PetscInt d=1); // set a UltraSpherical operators S_(d-1) and D_d
23  std::tuple<SPIMat,SPIMat> set_T_That(PetscInt n); // set a Chebyshev operators T and That
25  enum gridtype {
26  FD,
31  };
35  struct SPIgrid1D {
36  SPIgrid1D(); // constructor with no arguments
37  SPIgrid1D(SPIVec &y, std::string name="SPIgrid1D", gridtype _gridtype=FD); // constructor with set_grid arguments (set default values and derivatives)
38  ~SPIgrid1D(); // destructor
39  PetscInt ny; // number of points in wall-normal coordinate
40  void print(); // print all members of the class
41  void set_grid( SPIVec &y ); // function to save grid to internal grid
42  void set_derivatives(PetscInt order=4); // function to create derivatives on internal grid
43  void set_operators(); // function to create zero and identity operators on internal grid
44  // vars
45  std::string name;
46  // grid
49 
50  // derivatives
52  Dyy;
54  S1,
59  That,
60  FT,
65  I;
66  // flags
67  PetscBool flag_set_grid=PETSC_FALSE,
68  flag_set_derivatives=PETSC_FALSE,
69  flag_set_operators=PETSC_FALSE;
70 
71  };
72  struct SPIgrid2D{
73  SPIgrid2D(SPIVec &y, SPIVec &t, std::string name="SPIgrid2D", gridtype y_gridtype=FD, gridtype t_gridtype=Fourier); // constructor with set_grid arguments (set default values and derivatives)
74  ~SPIgrid2D(); // destructor
75  PetscInt ny,nt; // number of points in wall-normal coordinate
76  void print(); // print all members of the class
77  void set_grid( SPIVec &y, SPIVec &t ); // function to save grid to internal grid
78  void set_derivatives(PetscInt order=4); // function to create derivatives on internal grid
79  void set_operators(); // function to create zero and identity operators on internal grid
80  // vars
81  std::string name;
82  // grid
84  t;
86  That,
89  FT,
93  FT4,
99 
100  // derivatives
101  // 2D derivatives
102  //SPIMat Dy2D, ///< 1st derivative operator with respect to y of size nyxny
103  //Dyy2D, ///< 2nd derivative operator with respect to y of size nyxny
104  //Dt2D; ///< 1st derivative operator with respect to t of size ntxnt
106  // 3D derivatives
108  Dyy,
109  Dt;
110  // other helper operators
112  I,
114  // flags
115  PetscBool flag_set_grid=PETSC_FALSE,
116  flag_set_derivatives=PETSC_FALSE,
117  flag_set_operators=PETSC_FALSE;
118 
119  };
120  SPIVec SPIVec1Dto2D(SPIgrid2D &grid2D, SPIVec &u); // function to inflate a vector u from a 2D grid to a 3D grid
121  PetscScalar integrate(const SPIVec &a, SPIgrid1D &grid); // integrate a vector of Chebyshev Coefficients on physical grid
122  PetscScalar integrate(const SPIVec &a, SPIgrid2D &grid); // integrate a vector of Chebyshev Coefficients on physical grid
123  SPIVec proj(SPIVec &u, SPIVec &v, SPIgrid1D &grid); // project using inner product for Gram-Schmidt process
124  SPIVec proj(SPIVec &u, SPIVec &v, SPIgrid2D &grid); // project using inner product for Gram-Schmidt process
125  std::vector<SPIVec> orthogonalize(std::vector<SPIVec> &x,SPIgrid1D &grid); // create orthonormal basis from array of vectors
126  std::vector<SPIVec> orthogonalize(std::vector<SPIVec> &x,SPIgrid2D &grid); // create orthonormal basis from array of vectors
127  SPIMat interp1D_Mat(SPIgrid1D &grid1, SPIgrid1D &grid2); // create an interpolation routine to interpolate grid1.y -> grid2.y (i.e. create out matrix such that u(grid2.y) = out*u(grid1.y)
128  SPIMat interp1D_Mat(SPIVec &y1, SPIVec &y2); // create an interpolation routine to interpolate y1 -> y2 (i.e. create out matrix such that u(y2) = out*u(y1)
129  SPIMat dft(PetscInt nt); // create a discrete Fourier transform operator matrix (scale is default to 1/nt)
130  std::tuple<SPIMat,SPIMat,SPIMat,SPIMat> dft_dftinv_Ihalf_Ihalfn(PetscInt nt); // create a discrete Fourier transform operator matrix (scale with 1./nt) and output the associated inverse operator and associated identity operators to take the positive and negative wavenumbers. i.e. Ihalf+Ihalfn = eye(nt)
131 
132 }
133 #endif // SPIGRID_H
SPIprint.hpp
SPI::SPIgrid2D::FTinv
SPIMat FTinv
inverse Fourier Transform from wavenumber space to physical space for time
Definition: SPIgrid.hpp:90
SPI::SPIgrid2D::S0invS1inv
SPIMat S0invS1inv
inverse of S0^-1 * S1^-1
Definition: SPIgrid.hpp:88
SPI::FDperiodic
@ FDperiodic
finite difference grid on periodic grid
Definition: SPIgrid.hpp:27
SPI::get_D_Coeffs
SPIVec get_D_Coeffs(SPIVec &s, PetscInt d)
get the coefficients of the given stencil.
Definition: SPIgrid.cpp:15
SPI::SPIgrid2D::Ihalf
SPIMat Ihalf
positive wavenumbers from FT
Definition: SPIgrid.hpp:91
SPI::SPIgrid1D::FT
SPIMat FT
Fourier Transform operator.
Definition: SPIgrid.hpp:60
SPI::SPIgrid2D::FT
SPIMat FT
Fourier Transform operator from physical space to wavenumber space for time.
Definition: SPIgrid.hpp:89
SPI::SPIgrid1D::Ihalfn
SPIMat Ihalfn
negative wavenumbers from FT
Definition: SPIgrid.hpp:63
SPI::SPIgrid1D::Dyy
SPIMat Dyy
2nd derivative operator with respect to y
Definition: SPIgrid.hpp:52
SPI::integrate
PetscScalar integrate(const SPIVec &a, SPIgrid1D &grid)
integrate a vector of chebyshev Coefficients on a physical grid
Definition: SPIgrid.cpp:873
SPI::SPIgrid2D::flag_set_operators
PetscBool flag_set_operators
flag if set_operators has been executed
Definition: SPIgrid.hpp:117
SPI::SPIgrid1D::flag_set_grid
PetscBool flag_set_grid
flag if set_grid has been executed
Definition: SPIgrid.hpp:67
SPI::SPIgrid1D
Class to contain various grid parameters.
Definition: SPIgrid.hpp:35
SPI::SPIgrid1D::T
SPIMat T
Chebyshev operator taking it from Chebyshev coefficients to physical space.
Definition: SPIgrid.hpp:58
SPI::SPIgrid2D::~SPIgrid2D
~SPIgrid2D()
destructor of saved SPIVec and SPIMat
Definition: SPIgrid.cpp:809
SPI::SPIgrid1D::SPIgrid1D
SPIgrid1D()
constructor with at no arguments
Definition: SPIgrid.cpp:448
SPI::SPIgrid1D::y
SPIVec y
grid
Definition: SPIgrid.hpp:47
SPI::SPIgrid1D::Dy
SPIMat Dy
1st derivative operator with respect to y
Definition: SPIgrid.hpp:51
SPI::Chebyshev
@ Chebyshev
Chebyshev collocated grid.
Definition: SPIgrid.hpp:29
SPI::FD
@ FD
finite difference grid
Definition: SPIgrid.hpp:26
SPI::SPIVec
Definition: SPIVec.hpp:13
SPI::SPIgrid2D::flag_set_derivatives
PetscBool flag_set_derivatives
flag if set_derivatives has been executed
Definition: SPIgrid.hpp:116
SPI::Fourier
@ Fourier
Fourier transform collocated grid.
Definition: SPIgrid.hpp:28
SPI::SPIgrid2D::O
SPIMat O
zero matrix same size as derivative operators of size ny*nt x ny*nt
Definition: SPIgrid.hpp:111
SPI::set_D_periodic
SPIMat set_D_periodic(SPIVec &y, PetscInt d, PetscInt order=4)
set the derivative operator for the proper periodic grid assuming uniform discretization.
Definition: SPIgrid.cpp:172
SPI
Definition: SPIbaseflow.hpp:16
SPI::SPIgrid2D::y
SPIVec y
grid for wall-normal dimension
Definition: SPIgrid.hpp:83
SPI::SPIgrid2D::print
void print()
saves grid to internal grid
Definition: SPIgrid.cpp:654
SPI::set_D
SPIMat set_D(SPIVec &y, PetscInt d, PetscInt order=4, PetscBool uniform=PETSC_FALSE)
set the derivative operator for the proper y grid if uniform=false. Uses map_D function
Definition: SPIgrid.cpp:82
SPI::SPIgrid1D::set_derivatives
void set_derivatives(PetscInt order=4)
sets derivatives Dy and Dyy using saved grid
Definition: SPIgrid.cpp:503
SPI::SPIgrid2D::ny
PetscInt ny
Definition: SPIgrid.hpp:75
SPI::dft_dftinv_Ihalf_Ihalfn
std::tuple< SPIMat, SPIMat, SPIMat, SPIMat > dft_dftinv_Ihalf_Ihalfn(PetscInt nt)
Definition: SPIgrid.cpp:1589
SPI::UltraS
@ UltraS
UltraSpherical grid and derivatives.
Definition: SPIgrid.hpp:30
SPI::set_Cheby_mapped_y
SPIVec set_Cheby_mapped_y(PetscScalar a, PetscScalar b, PetscInt ny)
create a stretched Chebyshev grid from [a,b] using default Chebfun like mapping
Definition: SPIgrid.cpp:318
SPI::SPIgrid2D::ttype
gridtype ttype
type of grid for time dimension
Definition: SPIgrid.hpp:98
SPI::SPIgrid2D::set_derivatives
void set_derivatives(PetscInt order=4)
sets derivatives Dy and Dyy using saved grid
Definition: SPIgrid.cpp:692
SPI::set_D_UltraS
std::tuple< SPIMat, SPIMat > set_D_UltraS(SPIVec &x, PetscInt d=1)
set a UltraSpherical operator acting with respect to the collocated grid (keeps everything in UltraSp...
Definition: SPIgrid.cpp:338
SPI::SPIgrid1D::That
SPIMat That
Chebyshev operator taking it from physical space to Chebyshev coefficients.
Definition: SPIgrid.hpp:59
SPI::SPIgrid1D::set_grid
void set_grid(SPIVec &y)
saves grid to internal grid
Definition: SPIgrid.cpp:493
SPI::SPIgrid2D::I
SPIMat I
identity matrix same size as derivative operators of size ny*nt x ny*nt
Definition: SPIgrid.hpp:112
SPI::SPIgrid2D::Ihalfn
SPIMat Ihalfn
negative wavenumbers from FT
Definition: SPIgrid.hpp:92
SPI::SPIgrid2D::Dyy
SPIMat Dyy
2nd derivative operator with respect to y of size ny*nt x ny*nt
Definition: SPIgrid.hpp:108
SPI::SPIgrid2D::Dt
SPIMat Dt
1st derivative operator with respect to t of size ny*nt x ny*nt
Definition: SPIgrid.hpp:109
SPI::map_D_Chebyshev
SPIMat map_D_Chebyshev(SPIVec &x, PetscInt d=1)
map a Chebyshev collocated operator acting with respect to the stretched collocated grid
Definition: SPIgrid.cpp:278
SPI::SPIgrid1D::~SPIgrid1D
~SPIgrid1D()
destructor of saved SPIVec and SPIMat
Definition: SPIgrid.cpp:602
SPI::orthogonalize
std::vector< SPIVec > orthogonalize(std::vector< SPIVec > &x, SPIgrid1D &grid)
Definition: SPIgrid.cpp:1323
SPI::SPIgrid2D::FT4
SPIMat FT4
Fourier Transform operator from physical space to wavenumber space for time. For 4 variable state vec...
Definition: SPIgrid.hpp:93
SPI::SPIgrid1D::S0invS1inv
SPIMat S0invS1inv
[in] inverse of S0^-1 * S1^-1
Definition: SPIgrid.hpp:56
SPI::SPIgrid2D::grid1Dt
SPIgrid1D grid1Dt
Definition: SPIgrid.hpp:105
SPI::dft
SPIMat dft(PetscInt nt)
Definition: SPIgrid.cpp:1573
SPI::set_Fourier_t
SPIVec set_Fourier_t(PetscScalar T, PetscInt ny)
create a Fourier grid from [0,T]
Definition: SPIgrid.cpp:392
SPI::SPIVec1Dto2D
SPIVec SPIVec1Dto2D(SPIgrid2D &grid2D, SPIVec &u)
expand a 1D vector to a 2D vector copying data along time dimension
Definition: SPIgrid.cpp:850
SPI::SPIgrid1D::Ihalf
SPIMat Ihalf
positive wavenumbers from FT
Definition: SPIgrid.hpp:62
SPI::SPIgrid2D::set_operators
void set_operators()
sets zero and identity operators for grid
Definition: SPIgrid.cpp:772
SPI::SPIgrid2D::FTinv4
SPIMat FTinv4
inverse Fourier Transform from wavenumber space to physical space for time. For 4 variable state vect...
Definition: SPIgrid.hpp:94
SPI::factorial
PetscInt factorial(PetscInt n)
compute the factorial of n. This is needed for get_D_Coeffs function
Definition: SPIgrid.cpp:6
SPI::SPIgrid1D::ny
PetscInt ny
Definition: SPIgrid.hpp:39
SPI::SPIgrid2D::SPIgrid2D
SPIgrid2D(SPIVec &y, SPIVec &t, std::string name="SPIgrid2D", gridtype y_gridtype=FD, gridtype t_gridtype=Fourier)
constructor with no arguments (set default values)
Definition: SPIgrid.cpp:633
SPI::SPIgrid1D::O
SPIMat O
zero matrix same size as derivative operators
Definition: SPIgrid.hpp:64
SPIMat.hpp
SPI::SPIgrid2D::Ihalfn4
SPIMat Ihalfn4
negative wavenumbers from FT. For 4 variable state vector
Definition: SPIgrid.hpp:96
SPIVec.hpp
SPI::set_Cheby_stretched_y
SPIVec set_Cheby_stretched_y(PetscScalar y_max, PetscInt ny, PetscScalar yi=10.)
create a stretched Chebyshev grid from [0,y_max] with yi being the midpoint location for the number o...
Definition: SPIgrid.cpp:305
SPI::SPIgrid2D::Dy
SPIMat Dy
1st derivative operator with respect to y of size ny*nt x ny*nt
Definition: SPIgrid.hpp:107
SPI::map_D
SPIMat map_D(SPIMat D, SPIVec y, PetscInt d, PetscInt order=4)
map the derivative operator to the proper y grid
Definition: SPIgrid.cpp:52
SPI::SPIgrid1D::P
SPIMat P
row permutation matrix for UltraSpherical operators to shift rows from bottom to top to reduce LU fac...
Definition: SPIgrid.hpp:57
SPI::set_FD_stretched_y
SPIVec set_FD_stretched_y(PetscScalar y_max, PetscInt ny, PetscScalar delta=2.0001)
set stretched grid from [0,y_max] using tanh stretching for use with finite difference operators
Definition: SPIgrid.cpp:214
SPI::SPIgrid2D::avgt
SPIMat avgt
average in time operator
Definition: SPIgrid.hpp:113
SPI::set_Cheby_y
SPIVec set_Cheby_y(PetscInt ny)
create a Chebyshev grid from [-1,1]
Definition: SPIgrid.cpp:329
SPI::SPIgrid2D::That
SPIMat That
transform from physical to chebyshev
Definition: SPIgrid.hpp:86
SPI::SPIgrid2D
Definition: SPIgrid.hpp:72
SPI::SPIgrid1D::ytype
gridtype ytype
type of grid
Definition: SPIgrid.hpp:48
SPI::SPIgrid2D::name
std::string name
name of grid
Definition: SPIgrid.hpp:81
SPI::SPIgrid2D::Ihalf4
SPIMat Ihalf4
positive wavenumbers from FT. For 4 variable state vector
Definition: SPIgrid.hpp:95
SPI::SPIgrid1D::S1S0That
SPIMat S1S0That
UltraSpherical helper matrix S1*S0*That for baseflow.
Definition: SPIgrid.hpp:55
SPI::SPIgrid1D::flag_set_operators
PetscBool flag_set_operators
flag if set_operators has been executed
Definition: SPIgrid.hpp:69
SPI::SPIgrid1D::print
void print()
saves grid to internal grid
Definition: SPIgrid.cpp:468
SPI::gridtype
gridtype
enumeration of grid types
Definition: SPIgrid.hpp:25
SPI::SPIMat
Definition: SPIMat.hpp:17
SPI::SPIgrid1D::S0
SPIMat S0
UltraSpherical helper matrix S_0 takes chebyshev coefficients and outputs C^(1) coefficients.
Definition: SPIgrid.hpp:53
SPI::SPIgrid1D::flag_set_derivatives
PetscBool flag_set_derivatives
flag if set_derivatives has been executed
Definition: SPIgrid.hpp:68
SPI::SPIgrid2D::t
SPIVec t
grid for time dimension
Definition: SPIgrid.hpp:84
SPI::proj
SPIVec proj(SPIVec &u, SPIVec &v, SPIgrid1D &grid)
Definition: SPIgrid.cpp:1220
SPI::SPIgrid2D::set_grid
void set_grid(SPIVec &y, SPIVec &t)
saves grid to internal grid
Definition: SPIgrid.cpp:676
SPI::SPIgrid1D::FTinv
SPIMat FTinv
inverse Fourier Transform
Definition: SPIgrid.hpp:61
SPI::SPIgrid2D::grid1Dy
SPIgrid1D grid1Dy
Definition: SPIgrid.hpp:105
SPI::SPIgrid1D::set_operators
void set_operators()
sets zero and identity operators for grid
Definition: SPIgrid.cpp:574
SPI::SPIgrid2D::ytype
gridtype ytype
type of grid for wall-normal dimension
Definition: SPIgrid.hpp:97
SPI::set_D_Fourier
SPIMat set_D_Fourier(SPIVec t, PetscInt d=1)
create a Fourier derivative operator acting on grid t
Definition: SPIgrid.cpp:407
SPI::SPIgrid2D::nt
PetscInt nt
Definition: SPIgrid.hpp:75
SPI::SPIgrid2D::flag_set_grid
PetscBool flag_set_grid
flag if set_grid has been executed
Definition: SPIgrid.hpp:115
SPI::SPIgrid1D::name
std::string name
name of grid
Definition: SPIgrid.hpp:45
SPI::SPIgrid1D::S1
SPIMat S1
UltraSpherical helper matrices S_1 takes C^(1) coefficients and outputs C^(2) coefficients.
Definition: SPIgrid.hpp:54
SPI::SPIgrid2D::S1S0That
SPIMat S1S0That
UltraSpherical helper matrix S1*S0*That for baseflow.
Definition: SPIgrid.hpp:87
SPI::SPIgrid2D::T
SPIMat T
transform from chebyshev to physical
Definition: SPIgrid.hpp:85
SPI::SPIgrid1D::I
SPIMat I
identity matrix same size as derivative operators
Definition: SPIgrid.hpp:65
SPI::interp1D_Mat
SPIMat interp1D_Mat(SPIgrid1D &grid1, SPIgrid1D &grid2)
Definition: SPIgrid.cpp:1506
SPI::set_D_Chebyshev
SPIMat set_D_Chebyshev(SPIVec &x, PetscInt d=1, PetscBool need_map=PETSC_FALSE)
set a Chebyshev collocated operator acting with respect to the collocated grid
Definition: SPIgrid.cpp:225
SPI::set_T_That
std::tuple< SPIMat, SPIMat > set_T_That(PetscInt n)
set a T and That operators acting with respect to the Chebyshev collocated grid, That: physical -> Ch...
Definition: SPIgrid.cpp:367