#include "PDE.h" using namespace std; /* * Constructor for the PDE class. You should: * - calculate dx from a, b and N. * - allocate memory for x. * - set sensible default values for ts, t, build and rebuild. * - fill x with the gridpoints. */ PDE::PDE(int N, double dt, double a, double b, double theta) : N(N), dt(dt), a(a), b(b), theta(theta), u(N+1), lhs(N+1), rhs(N+1), le(N+1), li(N+1) { // You need to fill in this method. } /* * Destructor for the PDE class. * You should delete any memory you allocated in the constructor. */ PDE::~PDE() { // You need to fill in this method. } /* * Timestepper for the PDE class. You should: * * - Build the timestepping matrices by calling construct() if they need to be * constructed (as determined by the rebuild and built flags). * - Calculate the current time, and solve the equation: * * lhs*u^{n+1} = rhs*u^n * * Remember to impose boundary conditions once you have calculate rhs*u^n. */ void PDE::timestep() { // You need to fill in this method. } /** * Construct the left-hand side and right-hand side tri-diagonal matrices * this->lhs and this->rhs which are used to solve the discretised system. To * do this, you will need to use this->le and this->li, which are the explicit * and implicit discretised differential operators respectively. */ void PDE::construct() { // You need to fill in this method. } /** * Prints out the solution field. */ void PDE::print() { // This method is complete. int i; for (i = 0; i <= N; i++) { cout << setw(10) << x[i] << setw(15) << u[i] << endl; } } /** * This function allows you to output the solution field (at any time) to any * stream. For example; if one has: * * PDE obj = new PDE(); * ofstream outfile("outfile.txt"); * cout << obj; * outfile << obj; * * Note that the first line will obviously not compile since PDE is an * abstract base class. */ ostream &operator<<(ostream &stream, PDE &obj) { // This method is complete. int i; for (i = 0; i <= obj.N; i++) stream << setw(10) << obj.x[i] << setw(15) << obj.u[i] << endl; return stream; } /* * Return the i-th grid point (i.e. a + i*dx). */ double PDE::xv(int i) const { // You need to fill in this method. } /* * Returns a copy of the solution field u. */ const Field PDE::getU() const { // You need to fill in this method. }