/* Copyright (C) Bernard Piette University of Durham (UK) Department of Mathematical Sciences This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. You can modify or use any part of the source code but only under the condition that this Copyright notice is kept in the resulting source file. */ #include #include using namespace std; // Constructor for Euler pde // Allocated 2 extra arrays //****************************** pde_euler::pde_euler(double xmin,double xmax,int nx) : pde(xmin,xmax,nx) { tmp1_ = new double[nx_]; } // Destructor //*********** pde_euler::~pde_euler() { delete [] tmp1_; } // Perform a single euler integration step on the grid // Update the time t_ // pde : pde parameters // Eqn(Force) : computes the right hand side of // the equation. // uses f_,fl_,fr_: local fct pointer // Force : Reference to a double for the result. // i_ : lattice index // Return : the updated time //***************************************************** double pde_euler::integrate_1step() { int i; // Scan the whole grid for(i=0; i < nx_; i++) { // set f_, fl_, fr_, x_ and i_ set_neighbour_fcts(Fcts_,i); // Computes the force for point i and // stores it in Force Eqn(Force_); // Update each fct using Force : f(n+1) = f(n) + Force*dt // tmp1 is used to store the fct temporarily tmp1_[i] = f_[0] + dt_*Force_; } /* Update Fct with the new fct */ for(i=0; i < nx_; i++) { Fcts_[i] = tmp1_[i]; } t_ += dt_; // Udate the integration time return(t_); }