/*************************************************************************** * Title: finite_volume.cc, program to demonstrate the use of classes * in a Dune-like style for solving a numerical problem, here * a convection problem with finite volumes in 1D. * Date: * Copyright: ***************************************************************************/ #include #include #include #include //#include using std::string; using std::cerr; using std::cout; using std::ofstream; /*************************************************************************** * Model class collecting the analytical data functions, here the model * represents the Burgers equation ***************************************************************************/ class Model ... /*************************************************************************** * Grid class providing access to 1D equidistant cartesian grid ***************************************************************************/ class Grid ... /*************************************************************************** * DiscreteFunction class for providing access to discfuncs ***************************************************************************/ class DiscreteFunction ... /*************************************************************************** * NumericalFlux class for computing elementwise fluxes ***************************************************************************/ class NumericalFlux { public: // Constructor NumericalFlux(const Grid& grid, const Model& model, const double& lambda): grid_(grid), model_(model), lambda_(lambda) { } // Destructor ~NumericalFlux() { } // return reference to underlying grid inline const Grid& grid() const { return(grid_); } // return reference to underlying model inline const Model& model() const { return(model_); } // function evaluating the numerical flux g_ij, here Lax-Friedrichs double evaluate(const int element, const int face, const double u_i, const double u_ij) const { double fu,fv; model_.flux(u_i,fu); model_.flux(u_ij,fv); double normal = grid_.unit_normal(element,face); return 0.5*(fu+fv)*normal - 0.5/lambda_*(u_ij-u_i); } private: // store references to model and grid const Grid& grid_; const Model& model_; const double& lambda_; }; /*************************************************************************** * SpaceDiscOperator class for performing the finite volume * update computation ***************************************************************************/ class SpaceDiscOperator ... /*************************************************************************** * main program performing the time-loop ***************************************************************************/ int main(int argc, char** argv) { // read command line parameters // generate Grid, Model, Flux, DiscreteFunctions and SpaceDiscOperator // projection of initial data // perform time loop // write final solution }