simple_cfl.cpp
1 #include "simple_cfl.hpp"
2 #include "hydrodynamics_2d.hpp"
3 #include <boost/foreach.hpp>
4 #ifdef RICH_MPI
5 #include <mpi.h>
6 #endif
7 
8 SimpleCFL::SimpleCFL(const double cfl): cfl_(cfl) {}
9 
10 namespace {
11  class TimeStepCalculator: public LazyList<double>
12  {
13  public:
14 
15  TimeStepCalculator(const Tessellation& tess,
16  const vector<ComputationalCell>& cells,
17  const EquationOfState& eos,
18  const vector<Vector2D>& edge_velocities,
19  TracerStickerNames const& tracerstickernames):
20  tess_(tess), cells_(cells),
21  edge_velocities_(edge_velocities), eos_(eos), tracerstickernames_(tracerstickernames){}
22 
23  size_t size(void) const
24  {
25  return static_cast<size_t>(tess_.GetPointNo());
26  }
27 
28  double operator[](size_t i) const
29  {
30  double res = 0;
31  const double radius = tess_.GetWidth(static_cast<int>(i));
32  const double c = eos_.dp2c
33  (cells_[i].density,
34  cells_[i].pressure,
35  cells_[i].tracers,
36  tracerstickernames_.tracer_names);
37  const Vector2D v = cells_.at(i).velocity;
38  BOOST_FOREACH
39  (int index,
40  tess_.GetCellEdges(static_cast<int>(i))){
41  const Vector2D ve = edge_velocities_.at(static_cast<size_t>(index));
42  Edge const& edge = tess_.GetEdge(index);
43  const Vector2D n =
44  normalize(tess_.GetMeshPoint(edge.neighbors.second) - tess_.GetMeshPoint(edge.neighbors.first));
45  res = fmax
46  (res,
47  (c+std::abs(ScalarProd(n,(v-ve))))/radius);
48  }
49  return 1.0/res;
50  }
51 
52  private:
53  const Tessellation& tess_;
54  const vector<ComputationalCell>& cells_;
55  const vector<Vector2D>& edge_velocities_;
56  const EquationOfState& eos_;
57  TracerStickerNames const& tracerstickernames_;
58  };
59 }
60 
62  const vector<ComputationalCell>& cells,
63  const EquationOfState& eos,
64  const vector<Vector2D>& point_velocities,
65  const double /*time*/,TracerStickerNames const& tracerstickernames) const
66 {
67  double res = cfl_*lazy_min(TimeStepCalculator(tess,cells,eos,point_velocities,tracerstickernames));
68 #ifdef RICH_MPI
69  double res_new=res;
70  MPI_Allreduce(&res, &res_new, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);
71  res=res_new;
72 #endif
73  return res;
74 }
SimpleCFL(const double cfl)
Class constructor.
Definition: simple_cfl.cpp:8
Abstract class for time step calculator.
T lazy_min(const LazyList< T > &i2m)
Finds the minimum of a lazy list.
Definition: lazy_list.hpp:186
Abstract class for tessellation.
Interface between two cells.
Definition: Edge.hpp:13
Ordered list whose terms are evaluated lazily.
Definition: lazy_list.hpp:17
Time step based on CFL criterion.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Definition: Vector3D.cpp:185
Base class for equation of state.
double operator()(const Tessellation &tess, const vector< ComputationalCell > &cells, const EquationOfState &eos, const vector< Vector2D > &point_velocities, const double time, TracerStickerNames const &tracerstickernames) const
Calculates the time step.
Definition: simple_cfl.cpp:61
Vector2D normalize(const Vector2D &v)
Normalized a vector.
Definition: geometry.cpp:158
Class for keeping the names of the tracers and stickers.
std::pair< int, int > neighbors
Neighboring cells.
Definition: Edge.hpp:21
Various manipulations of hydrodynamic variables.
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
2D Mathematical vector
Definition: geometry.hpp:15