src/Hydro/VoronoiHourglassControl.cc
//------------------------------------------------------------------------------
// Find the center of mass for a cell given a slope for the density in the cell.
//------------------------------------------------------------------------------
// 1D
Find the center of mass for a cell given a slope for the density in the cell.
1D
Find the center of mass for a cell given a slope for the density in the cell . 1D
inline
Dim<1>::Vector
centerOfMass(const Dim<1>::Vector& xi,
             const Dim<1>::Scalar& rhoi,
             const Dim<1>::Vector& gradRhoi,
             const Mesh<Dim<1> >& mesh,
             const unsigned zoneID) {
  typedef Dim<1>::Scalar Scalar;
  typedef Dim<1>::Vector Vector;
  REQUIRE(zoneID < mesh.numZones());
  const vector<unsigned>& nodeIDs = mesh.zone(zoneID).nodeIDs();
  CHECK(nodeIDs.size() == 2);
  const Scalar x0 = mesh.node(nodeIDs[0]).position().x();
  const Scalar x1 = mesh.node(nodeIDs[1]).position().x();
  const Scalar xxi = xi.x();
  CHECK(x0 < x1);
  CHECK2(x0 <= xxi and xxi <= x1, zoneID << " : " << x0 << " " << xxi << " " << x1);
  const Scalar dx  = x1 - x0;
  const Scalar dx2 = x1*x1 - x0*x0;
  const Scalar dx3 = x1*x1*x1 - x0*x0*x0;
  const Scalar grhoi = gradRhoi.x();
  const Scalar A = rhoi - grhoi*xxi;
  const Scalar num = 0.5*A*dx2 + grhoi*dx3/3.0;
  const Scalar den = A*dx + 0.5*grhoi*dx2;
  CHECK(den > 0.0);
  return Vector(num/den);
}
inline Dim < 1 > :: Vector centerOfMass ( const Dim < 1 > :: Vector & xi , const Dim < 1 > :: Scalar & rhoi , const Dim < 1 > :: Vector & gradRhoi , const Mesh < Dim < 1 > > & mesh , const unsigned zoneID ) { typedef Dim < 1 > :: Scalar Scalar ; typedef Dim < 1 > :: Vector Vector ; REQUIRE ( zoneID < mesh . numZones ( ) ) ; const vector < unsigned > & nodeIDs = mesh . zone ( zoneID ) . nodeIDs ( ) ; CHECK ( nodeIDs . size ( ) == 2 ) ; const Scalar x0 = mesh . node ( nodeIDs [ 0 ] ) . position ( ) . x ( ) ; const Scalar x1 = mesh . node ( nodeIDs [ 1 ] ) . position ( ) . x ( ) ; const Scalar xxi = xi . x ( ) ; CHECK ( x0 < x1 ) ; CHECK2 ( x0 <= xxi and xxi <= x1 , zoneID << " " << x0 << " " << xxi << " " << x1 ) ; const Scalar dx = x1 - x0 ; const Scalar dx2 = x1 * x1 - x0 * x0 ; const Scalar dx3 = x1 * x1 * x1 - x0 * x0 * x0 ; const Scalar grhoi = gradRhoi . x ( ) ; const Scalar A = rhoi - grhoi * xxi ; const Scalar num = 0.5 * A * dx2 + grhoi * dx3 / 3.0 ; const Scalar den = A * dx + 0.5 * grhoi * dx2 ; CHECK ( den > 0.0 ) ; return Vector ( num / den ) ; }
Find the center of mass for a cell given a slope for the density in the cell.
Find the center of mass for a cell given a slope for the density in the cell .
// Read the node positions. // cerr << "  --> " << zoneID << " " << (num/den - xxi)/0.01 << endl;