Advertisement
bolverk

capricorn_breakout

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