Spectral Integral Suite in C++
Ex_03.cpp
Go to the documentation of this file.
1 #include <fstream>
14 #include <iostream>
15 #include <sis.hpp>
16 using namespace std;
17 typedef complex<double> Cd_t;
18 typedef valarray<double> Vd_t;
19 int main() {
20  using namespace sis;
21  N = 63;
22  sis_setup();
23  ChebfunMat<Cd_t> forc(1,1); // 1 by 1 ChebfunMat
24  Linop<double> D2(2), D1(1), D0(0); // Linops with highest order 2, 1 and 0.
25 
26  D2.coef << 1.0, 0.0, 0.0; // for (1.0 * D2 + 0.0 * D1 + (0.0) )v
27  D1.coef << 1.0, 0.0;
28  D0.coef << 1.0;
29 
30  valarray<double> anal_sol;
31  Eigen::VectorXd analSol(N+1);
32  anal_sol = exp(-(atan(y) + atan(1.0)));
33  cout << "Anal sol: \n";
34  for (int i = 0; i < N + 1; i++) {
35  cout << anal_sol[i] << "\n";
36  analSol[i] = anal_sol[i];
37  }
38 
39  LinopMat<Cd_t> Lmat(1,1);
40 
41  Lmat << D1 + Vd_t(1.0 / (pow(y, 2.0) + 1.0)) * D0;
42 
43  BcMat<Cd_t> bcs(1,1);
44 
45  bcs.L << D0;
46  bcs.eval << -1.0;
47  bcs.vals << 1.0;
48 
49  forc << Cd_t(0.0,0.0);
50 
51 
52  // Replace forcing with the solution:
53  forc = linSolve(Lmat,bcs,forc);
54 
55  // Check boundaries:
56  std::cout << "lbc: \n" << forc(-1.0) << '\n';
57  std::cout << "rbc: \n" << forc(1.0) << '\n';
58  std::cout << "error from analytical solution ";
59  double err = abs(real(forc(0,0).v) - anal_sol).sum();
60  cout << err << endl;
61 
62  // Print to file:
63  Eigen::MatrixXd outMat(N+1,3);
64  outMat << yEigen,forc(0,0).evr(), analSol;
65 ofstream outfile;
66 outfile.open("data/Ex_03.txt");
67 outfile << outMat;
68 outfile.close();
69  return 0;
70 }
void sis_setup()
Definition: sis.hpp:954
complex< double > Cd_t
Definition: Ex_03.cpp:17
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
int main()
Definition: Ex_03.cpp:19
valarray< double > Vd_t
Definition: Ex_03.cpp:18
This class represents a block matrix operator. It is a matrix of operators.
Definition: sis.hpp:528
Definition: sis.hpp:461
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
LinopMat< T > L
Definition: sis.hpp:8831
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)
This class holds a matrix of Chebfuns.
Definition: sis.hpp:2004
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > vals
Definition: sis.hpp:8833