Spectral Integral Suite in C++
Ex_02.cpp
Go to the documentation of this file.
1 
21 #include <fstream> // To output data to files
22 #include <iostream>
23 #include <sis.hpp>
24 
25 using namespace std;
26 
27 typedef complex<double> Cd_t;
28 typedef valarray<double> Vd_t;
29 
30 int main() {
31  using namespace sis;
32  N = 63; // sis::N, Defined in sis.hpp. This specifies no. of Chebyshev
33  // coefficients
34  sis_setup();
35  ChebfunMat<complex<double> > forc(1,1);
36 
37  Linop<double> D0(0), D1(1), D2(2), D3(3), D4(4);
38  D4.coef << 1.0, 0.0, 0.0, 0.0, 0.0;
39  D3.coef << 1.0, 0.0, 0.0, 0.0;
40  D2.coef << 1.0, 0.0, 0.0; // for (1.0 * D2 + 0.0 * D1 + (0.0) )v
41  D1.coef << 1.0, 0.0;
42  D0.coef << 1.0;
43 
44  LinopMat<Cd_t> Lmat(1,1);
45  Lmat << D4 - (4.0 * D2) + (8.0 * D0);
46 
47  BcMat<Cd_t> bcs(4,1);
48  bcs.L << D0,//
49  D1,//
50  D0,//
51  D1;
52  bcs.eval << -1.0,//
53  -1.0,//
54  1.0,//
55  1.0;
56  bcs.vals << 0.0,//
57  0.0,//
58  0.0,//
59  0.0;
60 
61 
62  // Set the forcing:
63  forc << (Cd_t(1.0,0.0) - (yc * yc) + (yc * yc * yc));
64 
65 
66  // Solve and replace forcing with the boundary conditions:
67  forc = linSolve(Lmat, bcs, forc);
68 
69 
70  // Check boundaries
71  cout << "lbc: " << forc(-1.0) << endl;
72  cout << "rbc: " << forc(1.0) << endl;
73 
74  // Write to file to plot, need only the real part:
75  ofstream outf;
76  outf.open("data/Ex_02.txt");
77  Eigen::MatrixXd temp(N + 1, 2);
78  temp << yEigen, forc(0,0).evr();
79  outf << temp;
80  // note that sis::yEigen is the same as y, but of type Eigen Matrix,
81  outf.close();
82  return 0;
83 }
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
ChebfunMat< std::complex< T > > linSolve(const LinopMat< std::complex< T > > &Lmat_, const BcMat< std::complex< T > > &bcmat_, const ChebfunMat< std::complex< T > > &forc_)
Linear equation solver.
Definition: sis.hpp:13282
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
valarray< double > Vd_t
Definition: Ex_02.cpp:28
Definition: sis.hpp:260
complex< double > Cd_t
Definition: Ex_02.cpp:27
Eigen::Matrix< SIS_TYPE, Eigen::Dynamic, Eigen::Dynamic > yEigen
Definition: sis.hpp:542
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
int main()
Definition: Ex_02.cpp:30
Eigen::Matrix< T, Eigen::Dynamic, 1 > coef
Stores the coefficients in the differential equation.
Definition: sis.hpp:2569
LinopMat< T > L
Definition: sis.hpp:8831
int N
Specifies number of Chebyshev polynomials, default N = 31.
Definition: sis.hpp:472
This class holds a matrix of Chebfuns.
Definition: sis.hpp:2004
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > vals
Definition: sis.hpp:8833