SPI
SLEPc PETSc Interface is used for rapid development and intuitive matrix operations similar to MatLab or NumPy style of operations
src
SPImain.cpp
Go to the documentation of this file.
1
#include "
SPImain.hpp
"
2
// include tests.hpp if running the tests function that tests all the functionality of the SPI classes
3
#include "
tests.hpp
"
4
5
static
char
help[] =
"SPI class to wrap PETSc Mat variables \n\n"
;
6
7
8
int
main
(
int
argc,
char
**args){
9
PetscErrorCode ierr;
10
std::cout<<
"-----------------Petsc Slepc Init Starting---------------"
<<std::endl;
11
ierr = PetscInitialize(&argc,&args,(
char
*)0,help);
if
(ierr)
return
ierr;
12
ierr = SlepcInitialize(&argc,&args,(
char
*)0,help);
if
(ierr)
return
ierr;
13
//SPI::printf("\n\n\n");
14
SPI::printf
(
"-----------------Petsc Slepc Init Complete---------------"
);
15
16
if
(1){
// set to 1 if wanting to test SPI Mat and Vec and other operations found in tests.cpp
17
tests
();
18
}
19
else
{
// started working on derivative operators, but it didn't quite work yet
20
// get_D_Coeffs
21
//SPI::SPIVec s(SPI::arange(-2,3,1.),"s");
22
//get_D_Coeffs(s,d).print();
23
// set_D
24
PetscInt n=64;
25
//PetscScalar y_max=21.;
26
//SPI::SPIVec ytmp(SPI::linspace(0.,y_max,n),"y");
27
//PetscScalar delta=2.0001;
28
//SPI::SPIVec y(y_max*(1.+(SPI::tanh(delta*((ytmp/y_max) - 1.))/tanh(delta))),"y");
29
//y.print();
30
//SPI::SPIVec ytmp;
31
//ytmp.Init(4,"tmp");
32
//ytmp.print();
33
//SPI::SPIVec y(SPI::set_FD_stretched_y(y_max,n),"y");
34
//SPI::SPIVec y(SPI::linspace(-1.,1.,n),"y"); // for finite difference grid
35
//SPI::SPIVec y(SPI::set_Cheby_mapped_y(0.,61.,n),"yCheby");
36
//SPI::SPIVec y(SPI::set_Cheby_mapped_y(-1,1,n),"yCheby");
37
SPI::SPIVec
y(
SPI::set_Cheby_y
(n),
"yCheby"
);
38
//SPI::SPIMat D(SPI::set_D(y,d,order));
39
//D.print();
40
//(D*(y^2)-2*y).print(); // near zero
41
SPI::SPIgrid1D
grid(y,
"grid"
,
SPI::Chebyshev
);
42
//grid.Dy.print();
43
44
// channel flow Orr-Sommerfeld solution
45
SPI::SPIMat
U(
SPI::diag
(1.0-((grid.
y
)^2)),
"U"
);
46
SPI::SPIMat
Uy(
SPI::diag
(-2.*grid.
y
),
"Uy"
);
47
//SPI::SPIMat Uyy(SPI::diag(-2.*SPI::ones(grid.y.rows)),"Uyy");
48
49
//PetscScalar Re=2000.0;
50
//PetscScalar omega=0.3;
51
//PetscScalar beta=0.0;
52
SPI::SPIparams
params(
"channel parameter"
);
53
params.
Re
= 2000.0;
54
params.
omega
= 0.3;
55
params.
alpha
= 0.97875+0.044394*PETSC_i;
56
params.
beta
= 0.0;
57
58
SPI::SPIVec
eigenfunction(grid.
y
.
rows
*6,
"q"
);
59
PetscScalar eigenvalue;
60
// std::tie(eigenvalue,eigenfunction) = SPI::eig(L,M,0.3-0.0001*i); // doesn't work because M is singular
61
//std::tie(eigenvalue,eigenfunction) = SPI::eig(M,L,1./(0.3-0.0001*i));
62
//SPI::printfc("eigenvalue is: %g+%gi",1./eigenvalue);
63
//(1./eigenvalue*SPI::ones(1)).print();
64
65
eigenfunction.
name
=
"eigenfunction"
;
66
//SPI::load(eigenfunction,"eigenfunction_saved.hdf5");
67
68
//std::tie(eigenvalue,eigenfunction) = SPI::eig_init(M,L,1.0/(0.3121-0.0197987*i),eigenfunction);
69
//std::tie(eigenvalue,eigenfunction) = SPI::eig(M,L,1.0/(0.3121-0.0197987*i));
70
//std::cout<<1./eigenvalue<<std::endl;
71
//SPI::printfc("eigenvalue is: %.10f+%.10fi",1./eigenvalue);
72
73
SPI::SPIVec
o(U.
diag
()*0.0,
"o"
);
74
SPI::SPIbaseflow
channel
(U.
diag
(),o,o,o,Uy.
diag
(),o,o,o,o,o,o,o,o,o);
75
//channel.print();
76
77
//params.print();
78
79
//std::tie(eigenvalue,eigenfunction) = SPI::LST_temporal(params,grid,channel);
80
//SPI::printfc("eigenvalue is: %.10f+%.10fi",eigenvalue);
81
//SPI::printfc("eigenvalue is: %.10f+%.10fi",params.omega);
82
//params.omega += 0.00001;
83
84
SPI::printfc
(
"alpha is: %.10f+%.10fi"
,params.
alpha
);
85
std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial
(params,grid,
channel
);
86
SPI::printfc
(
"eigenvalue is: %.10f+%.10fi"
,eigenvalue);
87
SPI::printfc
(
"eigenvalue is: %.10f+%.10fi"
,params.
alpha
);
88
std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial
(params,grid,
channel
,eigenfunction);
89
SPI::printfc
(
" eigenvalue is: %.10f+%.10fi"
,params.
alpha
);
90
params.
alpha
= 0.34312+0.049677*PETSC_i;
91
std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial
(params,grid,
channel
,eigenfunction);
92
SPI::printfc
(
" eigenvalue is: %.10f+%.10fi"
,params.
alpha
);
93
params.
alpha
= 0.61+0.1*PETSC_i;
94
std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial
(params,grid,
channel
,eigenfunction);
95
SPI::printfc
(
" eigenvalue is: %.10f+%.10fi"
,params.
alpha
);
96
//SPI::save(eigenfunction,"eigenfunction_saved.hdf5");
97
//SPI::draw(eigenfunction);
98
99
}
100
101
ierr = PetscFinalize();CHKERRQ(ierr);
102
ierr = SlepcFinalize();CHKERRQ(ierr);
103
104
return
0;
105
}
SPI::SPIparams::Re
PetscScalar Re
Reynolds number.
Definition:
SPIparams.hpp:13
SPI::SPIparams::alpha
PetscScalar alpha
alpha streamwise wavenumber
Definition:
SPIparams.hpp:15
SPI::SPIgrid1D
Class to contain various grid parameters.
Definition:
SPIgrid.hpp:35
SPImain.hpp
SPI::SPIparams::omega
PetscScalar omega
omega, temporal frequency (rad/s)
Definition:
SPIparams.hpp:16
SPI::SPIgrid1D::y
SPIVec y
grid
Definition:
SPIgrid.hpp:47
SPI::Chebyshev
@ Chebyshev
Chebyshev collocated grid.
Definition:
SPIgrid.hpp:29
main
int main(int argc, char **args)
Definition:
SPImain.cpp:8
SPI::SPIVec
Definition:
SPIVec.hpp:13
SPI::printf
PetscInt printf(std::string msg,...)
Definition:
SPIprint.cpp:5
SPI::SPIMat::diag
SPIVec diag()
get diagonal of matrix
Definition:
SPIMat.cpp:445
SPI::SPIVec::name
std::string name
Vec name (important for hdf5 i/o)
Definition:
SPIVec.hpp:26
SPI::LST_spatial
std::tuple< PetscScalar, SPIVec > LST_spatial(SPIparams ¶ms, SPIgrid1D &grid, SPIbaseflow &baseflow, SPIVec q=SPIVec())
solve the local stability theory problem for the linearized Navier-Stokes equations using parallel ba...
Definition:
SPILST.cpp:147
SPI::diag
SPIMat diag(const SPIVec &diag, const PetscInt k=0)
set diagonal of matrix
Definition:
SPIMat.cpp:728
SPI::printfc
PetscInt printfc(std::string msg, const PetscScalar val)
Definition:
SPIprint.cpp:29
SPI::channel
SPIbaseflow channel(SPIparams ¶ms, SPIgrid1D &grid)
Definition:
SPIbaseflow.cpp:253
SPI::set_Cheby_y
SPIVec set_Cheby_y(PetscInt ny)
create a Chebyshev grid from [-1,1]
Definition:
SPIgrid.cpp:329
SPI::SPIparams
Definition:
SPIparams.hpp:8
SPI::SPIMat
Definition:
SPIMat.hpp:17
SPI::SPIparams::beta
PetscScalar beta
beta spanwise wavenumber
Definition:
SPIparams.hpp:14
tests.hpp
SPI::SPIVec::rows
PetscInt rows
number of rows in vec
Definition:
SPIVec.hpp:14
tests
int tests()
Definition:
tests.cpp:24
SPI::SPIbaseflow
Definition:
SPIbaseflow.hpp:17
Generated by
1.8.17