Spectral Integral Suite in C++
Ex_12.cpp
Go to the documentation of this file.
1 
14 
15 #define EIGEN_USE_BLAS
16 #define SIS_USE_LAPACK
17 #include <fstream>
18 #include <iostream>
19 #include <sis.hpp>
20 #include <string>
21 
22 using namespace std;
23 typedef complex<double> Cd_t;
24 typedef valarray<complex<double> > Vcd_t;
25 complex<double> ii(0.0, 1.0);
26 
27 int main()
28 {
29  using namespace sis;
30  int bre;
31  // Number of Chebyshev polynomials
32  N = 31;
33  sis_setup();
34 
35  // Length of domain:
36  double kz = 1;
37  double kx = 1;
38  Eigen::VectorXd omval(20);
39  Eigen::MatrixXd data(20,3);
40  Eigen::MatrixXd data2(20,2);
41  omval = Eigen::VectorXd::LinSpaced(20, -2, 0);
42 
43  valarray<double> y, Uy, U, Uyy(N + 1);
44  // Set in cheb-point
45  setChebPts(y);
46 
47  // Velocity and derivative for PP flow
48  U = 1.0 - pow(y, 2.0);
49  Uy = -2.0 * y;
50  Uyy = -2.0;
51  double Re = 2000.0;
52 
53  Linop<double> Dy(1);
54  Dy.coef << 1.0, 0.0;
55 
56  LinopMat<std::complex<double> > A, B(2, 3), C(3, 2);
57  BcMat<std::complex<double> > Lbc(4, 4), Rbc(4, 4), bc(8, 4);
58 
59  Lbc.resize(4, 4);
60  Rbc.resize(4, 4);
61  Lbc.L << 1.0, 0.0, 0.0, 0.0, //
62  0.0, 1.0, 0.0, 0.0, //
63  0.0, 0.0, 1.0, 0.0, //
64  0.0, Dy, 0.0, 0.0;
65  Rbc.L << 1.0, 0.0, 0.0, 0.0, //
66  0.0, 1.0, 0.0, 0.0, //
67  0.0, 0.0, 1.0, 0.0, //
68  0.0, Dy, 0.0, 0.0;
69  Lbc.eval.setConstant(-1.0);
70  Rbc.eval.setConstant(1.0);
71  bc.L << Lbc.L, //
72  Rbc.L;
73  bc.eval << Lbc.eval, //
74  Rbc.eval;
75 
77 
78  B.resize(4, 3);
79  C.resize(3, 4);
80  B << 1.0, 0.0, 0.0, //
81  0.0, 1.0, 0.0, //
82  0.0, 0.0, 1.0, //
83  0.0, 0.0, 0.0;
84  C << 1.0, 0.0, 0.0, 0.0, //
85  0.0, 1.0, 0.0, 0.0, //
86  0.0, 0.0, 1.0, 0.0; //
87 
88  for (int k = 0; k < 20; k++)
89  {
90  complex<double> iiomega = ii * omval(k);
91  double k2 = kx * kx + kz * kz;
92  double k4 = k2 * k2;
93  Linop<double> Delta(2), Delta2(4);
94  LinopMat<complex<double> > Lmat(4, 4), Mmat(4, 4);
95 
96  Delta.coef << 1.0, 0.0, -k2;
97  Delta2.coef << 1.0, 0.0, -2 * k2, 0.0, k4;
98 
99  Mmat << 1.0, 0.0, 0.0, 0.0, //
100  0.0, 1.0, 0.0, 0.0, //
101  0.0, 0.0, 1.0, 0.0, //
102  0.0, 0.0, 0.0, 0.0 * Delta;
103 
104  Lmat << (-ii * kx * U) + (Delta / Re), -Uy, 0.0, -ii * kx, //
105  0.0, (-ii * kx * U) + (Delta / Re), 0.0, -Dy, //
106  0.0, 0.0, (-ii * kx * U) + (Delta / Re), -ii * kz, //
107  ii * kx, Dy, ii * kz, 0.0;
108 
109  A.resize(4, 4);
110  A = ((iiomega * Mmat) - Lmat);
111 
112  svd.compute(A, B, C, Lbc, Rbc, Lbc, Rbc, 15 * (N + 1));
113 
114  // Store first two eigenvalues.
115  cout << "First two singular values: " << svd.eigenvalues[0] << " "
116  << svd.eigenvalues[1] << "\n";
117 
118  data(k,0) = omval(k);
119  data(k,1) = svd.eigenvalues[0].real();
120  data(k,2) = svd.eigenvalues[1].real();
121 
122  // Compute power spectral density:
123  data2(k,0) = omval(k);
124  Cd_t psd;
125  psd = sqrt(svd.PowerSpectralDensity(A, B, C, Lbc, Rbc, Lbc, Rbc));
126  cout << "Power spectral density for omega = " << omval(k) << " is " << real(psd) << endl;
127  data2(k,1) = real(psd);
128  }
129  // Export to a file:
130  ofstream outfile("data/Ex12.txt");
131  outfile << data;
132  outfile.close();
133 
134  outfile.open("data/Ex_12_2.txt");
135  outfile << data2;
136  outfile.close();
137 
138  return 0;
139 }
void sis_setup()
Definition: sis.hpp:954
complex< double > Cd_t
Definition: Ex_12.cpp:23
BcMat will hold general Boundary conditions as LinopMats at evealuation points, as given by operator ...
Definition: sis.hpp:529
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > eval
Definition: sis.hpp:8832
Linop This class creates a Linear operator to solve TPBVPs.
Definition: sis.hpp:2560
Definition: sis.hpp:260
valarray< complex< double > > Vcd_t
Definition: Ex_12.cpp:24
Eigen::Matrix< std::complex< T >, Eigen::Dynamic, 1 > eigenvalues
Definition: sis.hpp:3257
This class represents a block matrix operator. It is a matrix of operators.
Definition: sis.hpp:528
complex< double > ii(0.0, 1.0)
Definition: sis.hpp:461
void compute(const LinopMat< T > &A_, const BcMat< T > &Lbc_, const BcMat< T > &Rbc_, int num_vals)
Computes the singular values/functions of a Linear block matrix operator.
Definition: sis.hpp:9139
Eigen::Matrix< T, Eigen::Dynamic, 1 > coef
Stores the coefficients in the differential equation.
Definition: sis.hpp:2569
void setChebPts(std::valarray< T > &in)
This function sets points to evaluate a function so that a DCT will give represent the same function ...
Definition: sis.hpp:920
int main()
Definition: Ex_12.cpp:27
valarray< complex< T > > pow(valarray< complex< T > > base, T power)
Definition: sis.hpp:453
LinopMat< T > L
Definition: sis.hpp:8831
This class computes various SingularValues of a differential block matrix operator using using it&#39;s a...
Definition: sis.hpp:531
int N
Specifies number of Chebyshev polynomials, default N = 31.
Definition: sis.hpp:472
valarray< T > real(const valarray< complex< T > > &in)
real part of a complex valarray
Definition: sis.hpp:280
std::valarray< SIS_TYPE > y(N+1)
void resize(int r_, int c_)
This clears all contents in the LinopMat, and then creates a fresh LinopMat of size r_ x c_...
Definition: sis.hpp:8214
complex< double > Cd_t
Definition: Ex_05.cpp:17