1 / 14

Finite Volume Code

Finite Volume Code. Tim Handy. Goals. Modular Code – Didn’t want to have to rework all of my code to add a new feature Dynamic Variables/Functions – Minimal assumptions about code requirements apriori No anticipation of special variables required for a particular method

Download Presentation

Finite Volume Code

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Finite Volume Code Tim Handy

  2. Goals • Modular Code – Didn’t want to have to rework all of my code to add a new feature • Dynamic Variables/Functions – Minimal assumptions about code requirements apriori • No anticipation of special variables required for a particular method • Ability to use scriptable C (Ch) for non-constant, analytic input conditions • Try some stuff I don’t normally do

  3. High Level Simulation Mesh Initial Conditions Boundary Conditions Interpolation Advection Output Cell

  4. 1-Dimensional Level Simulation1D Mesh1D - Uniform1D Initial Conditions (In Progress) Boundary Conditions - Periodic1D Interpolation - Interpolation1D Advection - Advection1D Output Cell1D

  5. Simulation1D class Simulation1D : public Simulation { protected: Mesh1D* mesh; BoundaryCondition1D* bc; InitialCondition* ic; Advection1D* advect; Interpolation1D* interp; Output* output; std::string resultsfile; std::map<std::string, std::string> solvers; std::multimap<int,outputinfo*> write_info; . . . }; • Primary constructor takes an input file as an argument and sets up other classes • Abusing polymorphism as much as possible • Simvars is a C++ Map of string->double • Allows for dynamic addition/removal of variables, clear accessing (no need to remember array indices) • Stores generic information other classes may require or are pertinent at the simulation level • Solvers maps a string->string • “interpolation”->”PPM”, “advection”->”Euler” • Allows easy input file parsing (no need for 40 cases for different variables)

  6. Mesh1D class Mesh1D : public Mesh { public: Cell1D** cells; intnum_ghost; intindex_lb, index_ub; intNtotal; . . . }; • Holds array (probably change to vector ASAP) of Cell1Ds (Total size = Ncells + 2*num_ghost) • Makes no assumptions about distribution of cells, just here to hold generic information and generic function calls/virtual functions • In 1D case, holds information on

  7. Cell1D class Cell { protected: int index; std::map<char,Cell*> neighbors; public: std::map<std::string,double> vars; … }; class Cell1D : public Cell { public: double xl, xr, xc, dx; double A; void populate_vars() { vars["density"] = 0.0; vars["density_w"] = 0.0; vars["density_e"] = 0.0; vars["xl"] = this->xl; vars["xr"] = this->xr; vars["xc"] = this->xc; vars["dx"] = this->dx; vars["A"] = this->A; vars["vx"] = 0.0; vars["vx_e"] = 0.0; vars["vx_w"] = 0.0; } void add_var(std::string var, double val); void remove_var(std::string var);

  8. Interpolation1D class Interpolation1D { private: typedef void(*ptr2Interp)(Mesh1D*,double,std::string); public: std::map<std::string, void (*)(Mesh1D*,double,std::string)> func_ptrs; Interpolation1D() { // probably need to be a bit safer here func_ptrs["FOU"] = FOupwind1D; func_ptrs["SOU"] = linear_upwind1D; func_ptrs["PPM"] = PPM; func_ptrs["PPMnonmono"] = nonmonoPPM; } … }; • Interpolation 1D contains the First Order, Second Order, and PPM schemes that operate on a given mesh for a given variable • Contains a map of strings->function pointers (Member functions are made static to make this easy) • Essentially just a wrapper for a set of functions, but allows easy modularity

  9. Input File N 64 CFL 0.25 tmin 0 tmax 6.283185307180 V0 -1 xmin 0 xmax6.283185307180 maxiter 3000 solver interpolation PPMnonmono write density.dat density 1 write velocity.dat vx 4 write xc.dat xc 1

  10. How to Run a Simulation Simulation1D* sim = new Simulation1D(in); sim->simulate(); … void simulate() { this->t = this->simvars["tmin"]; double Tmax = this->simvars["tmax"]; int iteration = 0; do { iteration++; double dt = this->stable_timestep(); this->set_timestep(dt); this->t += dt; if(this->t > Tmax) { dt -= this->t-Tmax; this->t = Tmax; } std::string interp_method = this->solvers["interpolation"]; interp->run(interp_method, this->mesh, dt, "density"); std::string advect_method = this->solvers["advection"]; advect->run(advect_method, this->mesh, dt, "density"); this->write_output(iteration); }while(t<Tmax && iteration < this->simvars["maxiter"]); }

  11. Temporal Rate of Convergence

  12. Spatial Rate of Convergence

  13. Limited Visible Change

  14. Current/Future Work • Rework InitialCondition/BoundaryCondition + Source terms to utilize scriptable C functions using Ch for MMS & incorporate Automatic Differentiation library • Minor code reorganization and front/back-end options (snapshots, forced timestep) • Incorporate new mesh types/BC

More Related