Spectral Integral Suite in C++
Ex_01.cpp
Go to the documentation of this file.
1 
20 #include <fstream> // To output data to files
21 #include <iostream>
22 #include <sis.hpp>
23 
24 using namespace std;
25 
26 int main() {
27  using namespace sis;
28  N = 63; // sis::N, Defined in sis.hpp. This specifies no. of Chebyshev
29  // coefficients
30  sis_setup();
31 
32  LinopMat<complex<double> > Lmat(1, 1);
33  Linop<double> D2(2), D1(1), D0(0); // Linops with highest order 2, 1 and 0.
34 
35  D2.coef << 1.0, 0.0, 0.0; // for (1.0 * D2 + 0.0 * D1 + (0.0) )v
36  D1.coef << 1.0, 0.0;
37  D0.coef << 1.0;
38 
39  //Chebfun<complex<double> > tempfun;
40  //tempfun.v = 0.0;
41  //tempfun.v[1] = complex<double>(1.0,1.0);
42  //tempfun.dct_flag = SIS_CHEB_SPACE;
43  //tempfun.c2p();
44  //cout << tempfun << endl;
45  //tempfun.p2c();
46  //cout << tempfun << endl;
47  //exit(1);
48 
49  // for operator D2v - 4 v
50  Lmat << D2 - 4.0 * D0;
51 
52  // Specify boundary conditions via BcMat:
53  BcMat<complex<double> > bcs(2, 1);
54  // Two boundary conditions in total, on one variable
55 
56  // Some mixed boundary condition:
57  bcs.L << D0 + 4.0*D1, // Operator
58  D0 - 5.0*D1;
59  bcs.eval << 1.0, // Evaluation points
60  -1.0;
61  bcs.vals << 2.0, // Values at end point
62  3.0;
63 
64  // Construct forcing, forc = 1 - y^2
65  ChebfunMat<complex<double> > forc(1, 1); // 1 by 1 ChebfunMat
66  forc << 1.0 - y * y; // y is defined in sis::y
67 
68  // Solve, by replacing the forcing as the solution.
69  forc = linSolve(Lmat, bcs, forc);
70 
71  // Write to file to plot, need only the real part:
72  ofstream outf;
73  outf.open("data/Ex_01.txt");
74  Eigen::MatrixXd temp(N + 1, 2);
75  temp << yEigen, forc(0,0).evr();
76  outf << temp;
77  // note that sis::yEigen is the same as y, but of type Eigen Matrix,
78  outf.close();
79  return 0;
80 }
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
Definition: sis.hpp:260
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
Definition: sis.hpp:461
int main()
Definition: Ex_01.cpp:26
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
std::valarray< SIS_TYPE > y(N+1)
This class holds a matrix of Chebfuns.
Definition: sis.hpp:2004
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > vals
Definition: sis.hpp:8833