cell_updater_1d.cpp
1 #include <cmath>
2 #include "cell_updater_1d.hpp"
3 #include "spdlog/spdlog.h"
4 
5 CellUpdater1D::~CellUpdater1D(void) {}
6 
8 
9 namespace{
10 
11  double calc_cell_volume
12  (const PhysicalGeometry1D& pg,
13  const vector<double>& vertices,
14  const size_t i)
15  {
16  return pg.calcVolume(vertices.at(i+1)) - pg.calcVolume(vertices.at(i));
17  }
18 
19  ComputationalCell retrieve_single_cell
20  (const double volume,
21  const Extensive& extensive,
22  const EquationOfState& eos)
23  {
24  const double density = extensive.mass/volume;
25  const Vector2D velocity = extensive.momentum/extensive.mass;
26  const double kinetic_specific_energy = 0.5*pow(abs(velocity),2);
27  const double total_specific_energy = extensive.energy/extensive.mass;
28  const double thermal_specific_energy =
29  total_specific_energy - kinetic_specific_energy;
30  const double pressure = eos.de2p
31  (density, thermal_specific_energy);
32 
34  res.density = density;
35  res.pressure = pressure;
36  res.velocity = velocity;
37  res.tracers = extensive.tracers;
38  for(size_t i=0;i<res.tracers.size();++i)
39  res.tracers.at(i) /= extensive.mass;
40  return res;
41  }
42 
43  void validate_input
44  (const vector<Extensive>& extensives,
45  const SimulationState1D& old)
46  {
47  assert(extensives.at(0).tracers.size()==
48  old.getCells().at(0).tracers.size());
49  }
50 }
51 
52 vector<ComputationalCell> SimpleCellUpdater1D::operator()
53  (const PhysicalGeometry1D& pg,
54  const vector<Extensive>& extensives,
55  const SimulationState1D& old,
56  const EquationOfState& eos) const
57 {
58  validate_input(extensives, old);
59  vector<ComputationalCell> res(extensives.size());
60  for(size_t i=0;i<res.size();++i){
61  try{
62  res.at(i) = retrieve_single_cell
63  (calc_cell_volume(pg,old.getVertices(),i),
64  extensives.at(i),
65  eos);
66  }
67  catch(...){
68  spdlog::critical("error found in cell {0}, position {1}, mass {2}, momentum {3} and energy {4}",
69  i,
70  old.getVertices().at(i),
71  extensives.at(i).mass,
72  extensives.at(i).momentum.x,
73  extensives.at(i).energy);
74  throw;
75  }
76  }
77  return res;
78 }
79 
80 SimpleCellUpdater1D::~SimpleCellUpdater1D(void) {}
Extensive variables.
Definition: extensive.hpp:18
virtual double de2p(double d, double e, tvector const &tracers=tvector(), vector< string > const &tracernames=vector< string >()) const =0
Calculates the pressure.
Vector2D momentum
momentum, in relativity it is = rho*h*gamma*v
Definition: extensive.hpp:31
double mass
rest mass times gamma
Definition: extensive.hpp:25
Base class for physical geometry.
Base class for cell update schemes.
double energy
energy, in relativity it is = rho*h*gamma^2-P-rho
Definition: extensive.hpp:28
tvector tracers
Tracers (can transfer from one cell to another)
double pressure
Pressure.
tvector tracers
tracers
Definition: extensive.hpp:34
const vector< ComputationalCell > & getCells(void) const
Access to hydro cells.
Base class for equation of state.
virtual double calcVolume(double radius) const =0
Calculates the volume.
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
SimpleCellUpdater1D(void)
Class constructor.
Vector2D velocity
Velocity.
Package for computational domain and hydro cells.
2D Mathematical vector
Definition: geometry.hpp:15
Computational cell.