Spectral Integral Suite in C++
Ex_13.cpp
Go to the documentation of this file.
1 
4 #define EIGEN_USE_MKL_ALL
5 // Use this if you want to use openmp in the main loop
6 //#define EIGEN_DONT_PARALLELIZE
7 #define EIGEN_FAST_MATH 0
8 
9 #include <fstream>
10 #include <iostream>
11 #include <omp.h>
12 #include <sis.hpp>
13 #include <string>
14 
15 
16 using namespace std;
17 typedef complex<double> Cd_t;
18 typedef valarray<double> Vd_t;
19 typedef valarray<complex<double> > Vcd_t;
20 int main() {
21  using namespace sis;
22  int bre;
23  valarray<double> Wes(20);
24  Eigen::VectorXd psd(20);
25  // Number of Chebyshev polynomials
26  for (int i = 0; i < 20; i++) {
27  Wes[i] = double(i + 1);
28  }
29 
30  N = 255;
31  sis_setup();
32  Vcd_t U(N + 1), Uy(N + 1), Uyy(N + 1);
33  string flowType("Couette");
34 
35  if (flowType.compare("Poiseuille") == 0) {
36  U = Cd_t(1.0, 0.0) - yc * yc;
37  Uy = Cd_t(-2.0, 0.0) * yc;
38  Uyy = Cd_t(-2.0, 0.0);
39  } else if (flowType.compare("Couette") == 0) {
40  U = yc;
41  Uy = Cd_t(1.0, 0.0);
42  Uyy = Cd_t(0.0, 0.0);
43  } else {
44  std::cout << "Unknown flow type, in line " << __LINE__ << '\n'
45  << "Exiting...\n";
46  exit(1);
47  }
48 
49  Eigen::MatrixXd valsS(10, 2);
50  Eigen::MatrixXd valsV(10, 2);
51 
52  //#pragma omp parallel for
53  for (int i = 0; i < 10; i++) {
54  Cd_t Re = 0.0;
55  Cd_t We = Wes[i];
56  Cd_t kx = 1.0;
57  Cd_t beta = 0.5;
58  Cd_t ii(0.0, 1.0);
59 
60  Linop<Cd_t> Dyyyy(4), Dyyy(3), Dyy(2), Dy(1);
61  Vcd_t c(N + 1), cy(N + 1), cyy(N + 1), a0(N + 1), a1(N + 1), a2(N + 1),
62  a3(N + 1), a4(N + 1);
63 
64  Dyyyy.coef << 1.0, 0.0, 0.0, 0.0, 0.0;
65  Dyyy.coef << 1.0, 0.0, 0.0, 0.0;
66  Dyy.coef << 1.0, 0.0, 0.0;
67  Dy.coef << 1.0, 0.0;
68  // Set in cheb-point
69  Cd_t omega = 0.0;
70  c = (ii * omega + 1.0 + (ii * kx * We * U));
71  cy = ii * kx * We * Uy;
72  cyy = ii * kx * We * Uyy;
73 
74  a4 = -beta + (-1.0 + beta)/c;
75 
76  a3 = (-2.0*(-1.0 + beta)*(cy - Cd_t(0.0,1.0)*c*kx*Uy*We))/pow(c,2.0);
77 
78  a2 = 2.0*beta*pow(kx,2.0) - ((-1.0 + beta)*(-2.0*pow(cy,2.0) - 4.0*kx*Uy*We*(Cd_t(0.0,1.0)*cy + kx*Uy*We) +
79  pow(c,2.0)*kx*(2.0*kx - Cd_t(0.0,3.0)*Uyy*We + 2.0*kx*pow(Uy,2.0)*pow(We,2.0)) + c*(cyy + Cd_t(0.0,2.0)*kx*We*(Uyy + Uy*(cy + Cd_t(0.0,1.0)*kx*Uy*We)))))/
80  pow(c,3.0);
81 
82  a1 = (Cd_t(0.0,-2.0)*(-1.0 + beta)*kx*(6.0*cy*Uy*We*(cy - Cd_t(0.0,1.0)*kx*Uy*We) + pow(c,3.0)*kx*Uy*We*(kx - Cd_t(0.0,2.0)*Uyy*We) +
83  pow(c,2.0)*(Uyy*We*(cy + Cd_t(0.0,3.0)*kx*Uy*We) + kx*(Cd_t(0.0,1.0)*cy - 2.0*kx*pow(Uy,3.0)*pow(We,3.0))) -
84  2.0*c*We*(2.0*cy*(Uyy + Cd_t(0.0,1.0)*kx*pow(Uy,2.0)*We) + Uy*(cyy + kx*We*(Cd_t(0.0,-2.0)*Uyy + kx*pow(Uy,2.0)*We)))))/pow(c,4.0);
85 
86  a0 = (kx*(-(beta*pow(c,4.0)*pow(kx,3.0)) + 12.0*(-1.0 + beta)*cy*kx*pow(Uy,2.0)*pow(We,2.0)*(cy - Cd_t(0.0,1.0)*kx*Uy*We) +
87  (-1.0 + beta)*pow(c,3.0)*pow(kx,2.0)*(kx - Cd_t(0.0,1.0)*Uyy*We + 2.0*kx*pow(Uy,2.0)*pow(We,2.0)) +
88  (-1.0 + beta)*pow(c,2.0)*(-(cyy*kx) + Cd_t(0.0,1.0)*(-cyy + 2.0*pow(kx,2.0))*Uyy*We + 2.0*kx*pow(Uyy,2.0)*pow(We,2.0) +
89  Cd_t(0.0,2.0)*cy*kx*Uy*We*(kx + Cd_t(0.0,2.0)*Uyy*We) + 2.0*kx*pow(Uy,2.0)*pow(We,2.0)*(-cyy + pow(kx,2.0) + Cd_t(0.0,6.0)*kx*Uyy*We)) +
90  2.0*(-1.0 + beta)*c*(-2.0*cyy*kx*pow(Uy,2.0)*pow(We,2.0) + cy*kx*(cy - Cd_t(0.0,2.0)*kx*Uy*We)*(1.0 + 2.0*pow(Uy,2.0)*pow(We,2.0)) +
91  Cd_t(0.0,1.0)*Uyy*We*(pow(cy,2.0) + Cd_t(0.0,6.0)*cy*kx*Uy*We + 6.0*pow(kx,2.0)*pow(Uy,2.0)*pow(We,2.0)))))/pow(c,4.0);
92 
93  LinopMat<Cd_t> Amat(1, 1), B(1, 2), C(2, 1), Ctau(3, 1), Cpsi(1,1), Ctauxx(1,1), Ctauxy(1,1), Ctauyy(1,1);
94  Amat << ((a4*Dyyyy) + (a3 * Dyyy) + (a2 * Dyy) + (a1 * Dy) + a0);
95 
96  BcMat<Cd_t> lbc(2, 1), rbc(2, 1);
97  lbc.L << 1.0, //
98  Dy;
99  rbc.L << 1.0, //
100  Dy;
101  lbc.eval.setConstant(-1.0);
102  rbc.eval.setConstant(1.0);
103  Linop<Cd_t> tau22Tov, tau12Tov, tau11Tov;
104 tau22Tov =
105  Vcd_t((Cd_t(0.0,-2.0)*kx)/c)*Dy + Vcd_t((2.0*pow(kx,2.0)*Uy*We)/c);
106 
107 tau12Tov = Vcd_t(Cd_t(1.0,0.0)/c)*Dyy + Vcd_t((Cd_t(0.0,-2.0)*kx*Uy*We)/pow(c,2.0))*Dy +
108  Vcd_t((kx*(Cd_t(0.0,1.0)*c*Uyy*We + kx*(c + 2.0*(1.0 + c)*pow(Uy,2.0)*pow(We,2.0))))/pow(c,2.0));
109 
110 tau11Tov = Vcd_t((2.0*(1.0 + c)*Uy*We)/pow(c,2.0))*Dyy + Vcd_t((Cd_t(0.0,2.0)*pow(c,2.0)*kx + Cd_t(0.0,4.0)*(-1.0 + pow(c,2.0))*kx*pow(Uy,2.0)*pow(We,2.0))/pow(c,3.0))*Dy +
111 Vcd_t((2.0*kx*Uy*We*(Cd_t(0.0,1.0)*c*(1.0 + 2.0*c)*Uyy*We + kx*(c + 2.0*(1.0 + c)*pow(Uy,2.0)*pow(We,2.0))))/pow(c,3.0));
112 
113 
114  Ctau << tau11Tov, //
115  tau12Tov, //
116  tau22Tov;
117  C << Dy, //
118  -ii*kx;
119  B << Dy,-ii*kx;
120  Cpsi << 1.0;
121  Ctauxx << tau11Tov;
122  Ctauxy << tau12Tov;
123  Ctauyy << tau22Tov;
125  // Velocity-output singular values
126  svd.compute(Amat, B, C, lbc, rbc,10);
127  valsV(i, 0) = svd.eigenvalues[0].real();
128  valsV(i, 1) = svd.eigenvalues[0].imag();
129 
130  // Stress-output singular values
131  svd.compute(Amat, B, Ctauxx, lbc, rbc, 10);
132  valsS(i, 0) = svd.eigenvalues[0].real();
133  valsS(i, 1) = svd.eigenvalues[0].imag();
134  std::cout << "i = " << i << '\n';
135 
136  }
137 
138  ofstream outfile;
139  outfile.open("data/Ex_13_Vel.txt");
140  outfile << valsV;
141  outfile.close();
142  outfile.open("data/Ex_13_Stress.txt");
143  outfile << valsS;
144  outfile.close();
145  return 0;
146 }
void sis_setup()
Definition: sis.hpp:954
BcMat will hold general Boundary conditions as LinopMats at evealuation points, as given by operator ...
Definition: sis.hpp:529
valarray< complex< double > > Vcd_t
Definition: Ex_13.cpp:19
valarray< complex< double > > Vcd_t
Definition: Ex_11.cpp:16
Linop This class creates a Linear operator to solve TPBVPs.
Definition: sis.hpp:2560
valarray< double > Vd_t
Definition: Ex_13.cpp:18
Definition: sis.hpp:260
complex< double > ii(0.0, 1.0)
int main()
Definition: Ex_13.cpp:20
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
std::valarray< std::complex< SIS_TYPE > > yc(N+1)
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
valarray< complex< T > > pow(valarray< complex< T > > base, T power)
Definition: sis.hpp:453
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
complex< double > Cd_t
Definition: Ex_13.cpp:17
complex< double > Cd_t
Definition: Ex_05.cpp:17