1 #include "LagrangianExtensiveUpdate.hpp" 2 #include "../../misc/utils.hpp" 8 bool bracketed(
int low,
int arg,
int high)
10 return arg >= low && high > arg;
15 const& ghost) :lflux_(lflux), ghost_(ghost) {}
18 const Tessellation& tess,
const double dt,
const CacheData& cd,
const vector<ComputationalCell>& cells,
19 vector<Extensive>& extensives,
double time,
TracerStickerNames const& tracerstickernames)
const 23 size_t N =
static_cast<size_t>(tess.
GetPointNo());
24 std::vector<double> dA(N, 0), dWs(N, 0);
26 string(
"AreaX")) - tracerstickernames.
tracer_names.begin());
28 string(
"AreaY")) - tracerstickernames.
tracer_names.begin());
30 bool area_calc =
false;
34 for (
size_t i = 0; i < N; ++i)
36 extensives[i].tracers[indexX] *= 0.85;
37 extensives[i].tracers[indexY] *= 0.85;
41 boost::container::flat_map<size_t,ComputationalCell> ghosts = ghost_(tess, cells, time, tracerstickernames);
42 vector<ComputationalCell> newcells(cells);
44 for (boost::container::flat_map<size_t, ComputationalCell>::iterator it = ghosts.begin(); it != ghosts.end(); ++it)
45 newcells[it->first] = it->second;
47 for (
size_t i = 0; i < edge_list.size(); ++i)
49 const Edge& edge = edge_list[i];
51 delta *= dt*cd.
areas[i];
52 double deltaWs = -lflux_.
ws_[i] * cd.
areas[i] * dt;
56 double p_star =
ScalarProd(fluxes[i].momentum, normal);
57 double v_star = fluxes[i].energy / p_star;
58 double v_new = (v_star - lflux_.
ws_[i]);
62 && p_star > 1.2*newcells[
static_cast<size_t>(edge.
neighbors.second)].pressure)
66 && p_star > 1.2*newcells[
static_cast<size_t>(edge.
neighbors.first)].pressure)
74 delta.
energy = cd.
areas[i] * dt*v_new*newcells[static_cast<size_t>(edge.
neighbors.first)].pressure;
77 delta.
energy = cd.
areas[i] * dt*v_new*newcells[static_cast<size_t>(edge.
neighbors.second)].pressure;
84 extensives[
static_cast<size_t>(edge.
neighbors.first)] -= delta;
87 extensives[
static_cast<size_t>(edge.
neighbors.first)].tracers[indexX] -= normal.
x*deltaWs;
88 extensives[static_cast<size_t>(edge.
neighbors.first)].tracers[indexY] -= normal.
y*deltaWs;
93 extensives[
static_cast<size_t>(edge.
neighbors.second)] += delta;
96 extensives[
static_cast<size_t>(edge.
neighbors.second)].tracers[indexX] -= normal.
x*deltaWs;
97 extensives[static_cast<size_t>(edge.
neighbors.second)].tracers[indexY] -= normal.
y*deltaWs;
102 for (
size_t i = 0; i < N; ++i)
104 if ((!(extensives[i].mass > 0)) || (!(extensives[i].energy > 0)) || (!std::isfinite(extensives[i].momentum.x)) || (!std::isfinite(extensives[i].momentum.y)))
108 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
110 std::cout <<
"Bad cell in LagrangianExtensiveUpdate, cell " << i <<
" rank " << rank <<
" time " << time << std::endl;
111 std::cout <<
"mass " << extensives[i].mass <<
" energy " << extensives[i].energy <<
" Entropy " <<
112 extensives[i].tracers[0] <<
" momentum" <<
abs(extensives[i].momentum) <<
" volume " << cd.
volumes[i]<< std::endl;
113 std::cout <<
"Old cell, density " << cells[i].density <<
" pressure " << cells[i].pressure <<
" v " <<
114 abs(cells[i].velocity) << std::endl;
115 std::vector<int> temp = tess.
GetCellEdges(static_cast<int>(i));
116 for (
size_t j = 0; j < temp.size(); ++j)
122 std::cout <<
"Edge " << temp[j] <<
" neigh " << N0 <<
"," << N1 <<
" mass=" << fluxes[
static_cast<size_t>(temp[j])].mass*Area <<
123 " energy " << fluxes[static_cast<size_t>(temp[j])].energy*Area <<
" momentum=" <<
abs(fluxes[static_cast<size_t>(temp[j])].momentum)*Area <<
126 std::cout <<
"dl " << newcells[
static_cast<size_t>(N0)].density <<
" pl " << newcells[static_cast<size_t>(N0)].pressure <<
" vxl " << newcells[
static_cast<size_t>(N0)].velocity.x <<
" vyl " << newcells[static_cast<size_t>(N0)].velocity.y << std::endl;
127 std::cout <<
"dr " << newcells[
static_cast<size_t>(N1)].density <<
" pr " << newcells[static_cast<size_t>(N1)].pressure <<
" vxr " << newcells[
static_cast<size_t>(N1)].velocity.x <<
" vyr " << newcells[static_cast<size_t>(N1)].velocity.y << std::endl;
129 std::cout <<
"dx " << normal.
x <<
" dy " << normal.
y << std::endl;
130 if (lflux_.
Lag_calc_[static_cast<size_t>(temp[j])])
132 double p_star =
ScalarProd(fluxes[static_cast<size_t>(temp[j])].momentum, normal);
133 double v_star = fluxes[
static_cast<size_t>(temp[j])].energy / p_star;
134 double v_new = (v_star - lflux_.
ws_[
static_cast<size_t>(temp[j])]);
135 std::cout <<
"Old pstar " << p_star <<
" vstar " << v_star <<
" vnew " << v_new << std::endl;
136 if (v_new*v_star > 0)
139 && p_star > 1.2*newcells[
static_cast<size_t>(edge.
neighbors.second)].pressure)
143 && p_star > 1.2*newcells[
static_cast<size_t>(edge.
neighbors.first)].pressure)
150 p_star = newcells[static_cast<size_t>(edge.
neighbors.first)].pressure;
153 p_star = newcells[static_cast<size_t>(edge.
neighbors.second)].pressure;
157 std::cout <<
"Pstar " << p_star <<
" Ustar " << v_new << std::endl;
Abstract class for tessellation.
vector< bool > Lag_calc_
Was this edge calculated Lagrangialy.
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.
Interface between two cells.
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
const CachedLazyList< double > areas
List of areas of interfaces.
double max(vector< double > const &v)
returns the maximal term in a vector
Abstract class for creating ghost points.
double energy
energy, in relativity it is = rho*h*gamma^2-P-rho
double y
Component in the y direction.
LagrangianExtensiveUpdate(LagrangianFlux const &lflux, GhostPointGenerator const &ghost)
Class constructor.
virtual Edge const & GetEdge(int index) const =0
Returns edge (interface between cells)
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
virtual const vector< Edge > & getAllEdges(void) const =0
Returns reference to the list of all edges.
void ReplaceExtensive(Extensive &toreplace, Extensive const &other)
Replaces the data in the extensive. The tracers should already be allocated.
virtual int GetTotalPointNumber(void) const =0
Returns the total number of points (including ghost)
const CachedLazyList< double > volumes
List of cell volumes.
Container for cache data.
std::vector< std::string > tracer_names
The names of the tracers.
double min(vector< double > const &v)
Returns the minimal term in a vector.
void operator()(const vector< Extensive > &fluxes, const PhysicalGeometry &pg, const Tessellation &tess, const double dt, const CacheData &cd, const vector< ComputationalCell > &cells, vector< Extensive > &extensives, double time, TracerStickerNames const &tracerstickernames) const
Updates the extensive variables.
Vector2D normalize(const Vector2D &v)
Normalized a vector.
Class for keeping the names of the tracers and stickers.
std::pair< int, int > neighbors
Neighboring cells.
double abs(Vector3D const &v)
Norm of a vector.
A flux scheme that minimises mass transfer between cells.
virtual vector< int > const & GetCellEdges(int index) const =0
Returns the indexes of a cell's edges.
Iter binary_find(Iter begin, Iter end, T val)
Binary search that return iterator of found object or end if not found.
double GetLength(void) const
Returns the length of the edge.
Base class for physical geometry.
double x
Component in the x direction.
vector< double > ws_
Velocity of the interfaces.