/* 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 #include #include using namespace std; // sine-Gordon diffusion Equation class dsg_pde : public pde_euler { public: dsg_pde(double xmin,double xmax,int nx) : pde_euler(xmin,xmax,nx) { } // Evaluate the sine-Gordon equation // functions: // f[0] : f : sine Gordond fct // F : array for result //*********************************** void Eqn(double &F) { eval_derivatives(); Force_ = fxx_ - sin(f_[0]); } // Compute the initial condition. // Fcts_[i] : f(x_i) //******************************** void Init(double x,double &F) { double xm; xm = (Xmin_+Xmax_)*0.5; F = exp(-(x-xm)*(x-xm)); } }; double xmin = -10.0; double xmax = 10.0; double tmax = 5.0; double grf_dt = 0.5; int nx = 101; char *file_name = "test"; int main(int argc,char **argv) { try { // Build a pde for sineGordon dsg_pde pde(xmin,xmax,nx); // Set dt by hand : dx * par.dt_r pde.set_dt(pde.dx()*pde.dx()*0.25); // Create a new graphic object grf_pde *grfp = new grf_pde(&pde,file_name); pde.init_grf(grfp); // compute the initial condition pde.initial_value(); // integrate up to tmax; pde.integrate_grf_until(tmax,grf_dt); } catch(string e) { cerr << e << std::endl; } }