Advertisement
bolverk

capricorn_breakout

Feb 27th, 2015
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include "hydro_snapshot.hpp"
  4. #include "hdsim.hpp"
  5. #include "ideal_gas.hpp"
  6. #include "hll.hpp"
  7. #include "free_flow.hpp"
  8. #include "pcm.hpp"
  9. #include "hdf5_diagnostics.hpp"
  10. #include <fenv.h>
  11.      
  12. using namespace std;
  13.      
  14. namespace {
  15.      
  16.   double cell_width(double position)
  17.   {
  18.     return abs(position)*0.01+0.01;
  19.   }
  20.      
  21.   vector<double> generate_grid(void)
  22.   {
  23.     const double left = -2000;
  24.     const double right = 2000;
  25.     vector<double> res;
  26.     for(double x=left;x<right;x+=cell_width(x))
  27.       res.push_back(x);
  28.     return res;
  29.   }
  30.      
  31.   Primitive generate_cell(double position)
  32.   {
  33.     return Primitive(pow(-min(position,-1e-12),1.5),
  34.              0.1*exp(-pow(position+1000,2)/10),
  35.              0);
  36.   }
  37.      
  38.   vector<Primitive> generate_cells(const vector<double>& grid)
  39.   {
  40.     vector<Primitive> cells(grid.size()-1);
  41.     for(size_t i=0;i<grid.size()-1;++i)
  42.       cells[i] = generate_cell(0.5*(grid[i]+grid[i+1]));
  43.     return cells;
  44.   }
  45.      
  46.   HydroSnapshot initial_conditions(void)
  47.   {
  48.     const vector<double> grid = generate_grid();
  49.     const vector<Primitive> cells = generate_cells(grid);
  50.     return HydroSnapshot(grid,cells);
  51.   }
  52.      
  53.   class SimData
  54.   {
  55.   public:
  56.      
  57.     SimData(void):
  58.       eos_(5./3.),
  59.       rs_(eos_),
  60.       bc_(),
  61.       sr_(),
  62.       sim_(initial_conditions(),
  63.        eos_, rs_, bc_, sr_) {}
  64.      
  65.     HydroSimulation& getSim(void)
  66.     {
  67.       return sim_;
  68.     }
  69.      
  70.   private:
  71.     const IdealGas eos_;
  72.     const HLL rs_;
  73.     const FreeFlow bc_;
  74.     const PCM sr_;
  75.     HydroSimulation sim_;
  76.   };
  77.      
  78.   void main_loop(HydroSimulation& sim)
  79.   {
  80.     write_snapshot_to_hdf5(sim,"initial.h5");
  81.     while(sim.getTime()<5e6){
  82.       sim.timeAdvance();
  83.       cout << sim.getTime() << endl;
  84.     }
  85.     write_snapshot_to_hdf5(sim,"final.h5");
  86.   }
  87. }
  88.      
  89. int main(void)
  90. {
  91.   feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
  92.      
  93.   main_loop(SimData().getSim());
  94.      
  95.   return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement