condition_action_sequence.cpp
1 #include "condition_action_sequence.hpp"
3 #include "../../misc/utils.hpp"
4 
6 (const vector<pair<const Condition*, const Action*> >& sequence) :
7  sequence_(sequence) {}
8 
9 ConditionActionSequence::~ConditionActionSequence(void)
10 {
11  for (size_t i = 0; i < sequence_.size(); ++i) {
12  delete sequence_[i].first;
13  delete sequence_[i].second;
14  }
15 }
16 
17 namespace
18 {
19  void choose_action
20  (const Edge& edge,
21  const Tessellation& tess,
22  const vector<ComputationalCell>& cells,
23  const EquationOfState& eos,
24  const Vector2D& edge_velocity,
25  const vector<pair<const ConditionActionSequence::Condition*, const ConditionActionSequence::Action*> >& sequence,
26  Extensive &res, double time, TracerStickerNames const& tracerstickernames)
27  {
28  for (size_t i = 0; i < sequence.size(); ++i) {
29  const pair<bool, bool> flag_aux = (*sequence[i].first)
30  (edge, tess, cells, tracerstickernames);
31  if (flag_aux.first)
32  return (*sequence[i].second)
33  (edge, tess, edge_velocity, cells, eos, flag_aux.second, res, time, tracerstickernames);
34  }
35  throw UniversalError("Error in ConditionActionSequence");
36  }
37 }
38 
39 vector<Extensive> ConditionActionSequence::operator()
40 (const Tessellation& tess,
41  const vector<Vector2D>& edge_velocities,
42  const vector<ComputationalCell>& cells,
43  const vector<Extensive>& extensives,
44  const CacheData& /*cd*/,
45  const EquationOfState& eos,
46  const double time,
47  const double /*dt*/,
48  TracerStickerNames const& tracerstickernames) const
49 {
50  vector<Extensive> res(tess.getAllEdges().size(), extensives[0]);
51  for (size_t i = 0; i < tess.getAllEdges().size(); ++i)
52  choose_action
53  (tess.getAllEdges()[i],
54  tess,
55  cells,
56  eos,
57  edge_velocities[i],
58  sequence_, res[i], time, tracerstickernames);
59  return res;
60 }
61 
62 ConditionActionSequence::Condition::~Condition(void) {}
63 
64 ConditionActionSequence::Action::~Action(void) {}
65 
67  rs_(rs) {}
68 
69 namespace
70 {
71  void conserved_to_extensive
72  (const Conserved& c, const ComputationalCell& cell, Extensive &res)
73  {
74  res.mass = c.Mass;
75  res.momentum = c.Momentum;
76  res.energy = c.Energy;
77  res.tracers.resize(cell.tracers.size());
78  size_t N = cell.tracers.size();
79  for (size_t i = 0; i < N; ++i)
80  res.tracers[i] = cell.tracers[i] * c.Mass;
81  }
82 }
83 
84 void RegularFlux::operator()
85 (const Edge& edge,
86  const Tessellation& tess,
87  const Vector2D& edge_velocity,
88  const vector<ComputationalCell>& cells,
89  const EquationOfState& eos,
90  const bool /*aux*/,
91  Extensive &res, double /*time*/, TracerStickerNames const& tracerstickernames) const
92 {
93  assert(edge.neighbors.first >= 0 && tess.GetOriginalIndex(edge.neighbors.first) !=
94  tess.GetOriginalIndex(edge.neighbors.second) && edge.neighbors.second >= 0);
95  const Vector2D p = normalize
96  (edge.vertices.second -
97  edge.vertices.first);
98  const Vector2D n = normalize
99  (tess.GetMeshPoint(edge.neighbors.second) -
100  tess.GetMeshPoint(edge.neighbors.first));
101  const double v =
102  ScalarProd(n, edge_velocity);
104  (rs_,
106  (cells.at(static_cast<size_t>(edge.neighbors.first)), eos,tracerstickernames),
108  (cells.at(static_cast<size_t>(edge.neighbors.second)), eos,tracerstickernames),
109  v, n, p);
110  conserved_to_extensive
111  (c,
112  c.Mass > 0 ?
113  cells.at(static_cast<size_t>(edge.neighbors.first)) :
114  cells.at(static_cast<size_t>(edge.neighbors.second)), res);
115 }
116 
118 (const RiemannSolver& rs) :
119  rs_(rs) {}
120 
121 namespace {
122  pair<Primitive, Primitive> rigid_wall_states
123  (const Primitive& state,
124  const Vector2D& p,
125  const bool aux)
126  {
127  if (aux) {
128  const Primitive left = state;
129  const Primitive right = reflect(left, p);
130  return pair<Primitive, Primitive>(left, right);
131  }
132  else {
133  const Primitive right = state;
134  const Primitive left = reflect(right, p);
135  return pair<Primitive, Primitive>(left, right);
136  }
137  }
138 }
139 
140 void RigidWallFlux::operator()
141 (const Edge& edge,
142  const Tessellation& tess,
143  const Vector2D& /*edge_velocity*/,
144  const vector<ComputationalCell>& cells,
145  const EquationOfState& eos,
146  const bool aux,
147  Extensive &res, double /*time*/,TracerStickerNames const& tracerstickernames) const
148 {
149 #ifndef RICH_MPI
150  if (aux)
151  assert(edge.neighbors.first >= 0 && edge.neighbors.first < tess.GetPointNo());
152  else
153  assert(edge.neighbors.second >= 0 && edge.neighbors.second < tess.GetPointNo());
154 #endif //RICH_MPI
155  const Vector2D p = normalize
156  (edge.vertices.second - edge.vertices.first);
157  const Vector2D n =
158  normalize(tess.GetMeshPoint(edge.neighbors.second) - tess.GetMeshPoint(edge.neighbors.first));
159  const double v = 0;
160  const pair<Primitive, Primitive> left_right =
161  rigid_wall_states
163  (cells.at
164  (static_cast<size_t>
165  (aux ? edge.neighbors.first : edge.neighbors.second)),
166  eos,tracerstickernames),
167  p, aux);
169  (rs_,
170  left_right.first,
171  left_right.second,
172  v, n, p);
173  conserved_to_extensive
174  (c,
175  cells.at(static_cast<size_t>(aux ? edge.neighbors.first : edge.neighbors.second)), res);
176 }
177 
179  rs_(rs) {}
180 
181 void FreeFlowFlux::operator()
182 (const Edge& edge,
183  const Tessellation& tess,
184  const Vector2D& /*edge_velocity*/,
185  const vector<ComputationalCell>& cells,
186  const EquationOfState& eos,
187  const bool aux,
188  Extensive &res, double /*time*/, TracerStickerNames const& tracerstickernames) const
189 {
190 #ifndef RICH_MPI
191  if (aux)
192  assert(edge.neighbors.first >= 0 && edge.neighbors.first < tess.GetPointNo());
193  else
194  assert(edge.neighbors.second >= 0 && edge.neighbors.second < tess.GetPointNo());
195 #endif //RICH_MPI
196  const Vector2D p = normalize
197  (edge.vertices.second - edge.vertices.first);
198  const Vector2D n =
199  normalize
201  (aux ?
202  edge.vertices.first - tess.GetMeshPoint(edge.neighbors.first) :
203  tess.GetMeshPoint(edge.neighbors.second) - edge.vertices.first,
204  p));
205  const double v = 0;
206  const Primitive state =
208  (cells.at
209  (static_cast<size_t>
210  (aux ? edge.neighbors.first : edge.neighbors.second)),
211  eos,tracerstickernames);
213  (rs_,
214  state, state,
215  v, n, p);
216  conserved_to_extensive
217  (c,
218  cells.at(static_cast<size_t>(aux ? edge.neighbors.first : edge.neighbors.second)), res);
219 }
220 
221 IsBoundaryEdge::IsBoundaryEdge(void) {}
222 
223 pair<bool, bool> IsBoundaryEdge::operator()
224 (const Edge& edge,
225  const Tessellation& tess,
226  const vector<ComputationalCell>& /*cells*/, TracerStickerNames const& /*tracerstickernames*/) const
227 {
228  if (tess.GetOriginalIndex(edge.neighbors.first) != tess.GetOriginalIndex(edge.neighbors.second))
229  return pair<bool, bool>(false, false);
230  else
231  {
232  if (edge.neighbors.first < tess.GetPointNo())
233  return pair<bool, bool>(true, true);
234  else
235  return pair<bool, bool>(true, false);
236  }
237 }
238 
239 IsBulkEdge::IsBulkEdge(void) {}
240 
241 pair<bool, bool> IsBulkEdge::operator()
242 (const Edge& edge,
243  const Tessellation& tess,
244  const vector<ComputationalCell>& /*cells*/, TracerStickerNames const& /*tracerstickernames*/) const
245 {
246  return pair<bool, bool>
247  (edge.neighbors.first >= 0 &&
248  edge.neighbors.second >= 0 &&
249  ((edge.neighbors.first < tess.GetPointNo() &&
250  edge.neighbors.second < tess.GetPointNo()) ||
251  (tess.GetOriginalIndex(edge.neighbors.first) !=
252  tess.GetOriginalIndex(edge.neighbors.second))),
253  false);
254 }
255 
256 RegularSpecialEdge::RegularSpecialEdge(const string& sticker_name) :
257  sticker_name_(sticker_name) {}
258 
259 pair<bool, bool> RegularSpecialEdge::operator()
260 (const Edge& edge,
261  const Tessellation& /*tess*/,
262  const vector<ComputationalCell>& cells, TracerStickerNames const& tracerstickernames) const
263 {
264  if (safe_retrieve(cells.at(static_cast<size_t>(edge.neighbors.first)).stickers,tracerstickernames.sticker_names,
265  sticker_name_)) {
266  if (safe_retrieve(cells.at(static_cast<size_t>(edge.neighbors.second)).stickers,tracerstickernames.sticker_names,
267  sticker_name_))
268  return pair<bool, bool>(false, false);
269  return pair<bool, bool>(true, false);
270  }
271  if (safe_retrieve(cells.at(static_cast<size_t>(edge.neighbors.second)).stickers,tracerstickernames.sticker_names,
272  sticker_name_))
273  return pair<bool, bool>(true, true);
274  return pair<bool, bool>(false, false);
275 }
Set of conserved variables (extensive)
Extensive variables.
Definition: extensive.hpp:18
Vector2D Momentum
Momentum.
FreeFlowFlux(const RiemannSolver &rs)
Class constructor.
Vector2D remove_parallel_component(const Vector2D &v, const Vector2D &p)
Remove parallel component of a vector.
Abstract class for tessellation.
virtual int GetPointNo(void) const =0
Get Total number of mesh generating points.
virtual int GetOriginalIndex(int point) const
Returns the original index of the duplicated point.
Definition: tessellation.cpp:5
Vector2D momentum
momentum, in relativity it is = rho*h*gamma*v
Definition: extensive.hpp:31
Container for error reports.
Primitive convert_to_primitive(const ComputationalCell &cell, const EquationOfState &eos, TracerStickerNames const &tracerstickernames)
Converts computational cell to primitive variables.
double mass
rest mass times gamma
Definition: extensive.hpp:25
Interface between two cells.
Definition: Edge.hpp:13
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
double Energy
Total energy (kinetic + thermal)
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)
Simple flux calculator.
RegularSpecialEdge(const string &sticker_name)
Class constructor.
Base class for Riemann solver.
tvector tracers
tracers
Definition: extensive.hpp:34
Conserved rotate_solve_rotate_back(const RiemannSolver &rs, const Primitive &left, const Primitive &right, const double velocity, const Vector2D &n, const Vector2D &p)
Rotates, solve riemann problem and rotates results back.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Definition: Vector3D.cpp:185
virtual const vector< Edge > & getAllEdges(void) const =0
Returns reference to the list of all edges.
Base class for equation of state.
std::pair< Vector2D, Vector2D > vertices
Points at the ends of the edge.
Definition: Edge.hpp:18
Primitive reflect(const Primitive &p, const Vector2D &axis)
Reflects velocity about axis.
Container for cache data.
Definition: cache_data.hpp:14
vector< T >::const_reference safe_retrieve(vector< T > const &data, vector< S > const &keys, const S &key)
Checks for existence and retrieves entry from flat map.
Definition: utils.hpp:727
Vector2D normalize(const Vector2D &v)
Normalized a vector.
Definition: geometry.cpp:158
RegularFlux(const RiemannSolver &rs)
Class constructor.
Class for keeping the names of the tracers and stickers.
std::pair< int, int > neighbors
Neighboring cells.
Definition: Edge.hpp:21
ConditionActionSequence(const vector< pair< const Condition *, const Action *> > &sequence)
Class constructor.
RigidWallFlux(const RiemannSolver &rs)
Class constructor.
Primitive hydrodynamic variables.
2D Mathematical vector
Definition: geometry.hpp:15
Computational cell.