Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup compositional fluid model #2812

Merged
merged 11 commits into from
Dec 11, 2023
16 changes: 12 additions & 4 deletions src/coreComponents/common/PhysicsConstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,32 @@
* @file PhysicsConstants.hpp
* @brief Regroups useful constants that are globally used for math and physics computations.
*/
#ifndef GEOS_MATH_PHYSICSCONSTANTS_HPP_
#define GEOS_MATH_PHYSICSCONSTANTS_HPP_
#ifndef GEOS_COMMON_PHYSICSCONSTANTS_HPP_
#define GEOS_COMMON_PHYSICSCONSTANTS_HPP_

namespace geos
{

namespace constants
{


/**
* @brief Zero degree Celsius in Kelvin
*/
constexpr double zeroDegreesCelsiusInKelvin = 273.15;

/**
* @brief Shorthand for pi
*/
constexpr double pi = 3.141592653589793238;

/**
* @brief Universal gas constant
*/
constexpr double gasConstant = 8.31446261815324;

} // end namespace constants

} // end namespace geos

#endif //GEOS_MATH_PHYSICSCONSTANTS_HPP_
#endif //GEOS_COMMON_PHYSICSCONSTANTS_HPP_
2 changes: 2 additions & 0 deletions src/coreComponents/common/Units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ namespace units
* @return the input Kelvin degrees converted in Celsius
* @param kelvin degrees input
*/
GEOS_HOST_DEVICE
inline constexpr double convertKToC( double kelvin )
{ return kelvin - constants::zeroDegreesCelsiusInKelvin; }
/**
* @return the input Celsius degrees converted in Kelvin
* @param celsius degrees input
*/
GEOS_HOST_DEVICE
dkachuma marked this conversation as resolved.
Show resolved Hide resolved
inline constexpr double convertCToK( double celsius )
{ return celsius + constants::zeroDegreesCelsiusInKelvin; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "constitutive/fluid/multifluid/CO2Brine/functions/CO2EOSSolver.hpp"
#include "constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionHelpers.hpp"
#include "constitutive/fluid/multifluid/MultiFluidConstants.hpp"

#include "functions/FunctionManager.hpp"
#include "common/Units.hpp"
Expand All @@ -42,7 +41,7 @@ namespace
constexpr real64 P_Pa_f = 1e+5;
constexpr real64 P_c = 73.773 * P_Pa_f;
constexpr real64 T_c = 304.1282;
constexpr real64 Rgas = MultiFluidConstants::gasConstant;
constexpr real64 Rgas = constants::gasConstant;
constexpr real64 V_c = Rgas*T_c/P_c;

// these coefficients are in Table (A1) of Duan and Sun (2003)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_MULTIFLUIDCONSTANTS_HPP_

#include "LvArray/src/Macros.hpp"
#include "common/PhysicsConstants.hpp"

namespace geos
{
Expand All @@ -40,16 +41,6 @@ struct MultiFluidConstants
*/
static constexpr integer MAX_NUM_PHASES = 4;

/**
* @brief Shorthand for pi
*/
static constexpr real64 pi = 3.141592653589793238;

/**
* @brief Universal gas constant
*/
static constexpr real64 gasConstant = 8.31446261815324;

/**
* @brief Epsilon used in the calculations to check against zero
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,7 @@ CompositionalMultiphaseFluidUpdates( compositional::ComponentProperties const &
m_phase1( phase1.createKernelWrapper() ),
m_phase2( phase2.createKernelWrapper() ),
m_phase3( phase3.createKernelWrapper() )
{
std::cout << "Sizes:\n"
<< "this: " << sizeof(CompositionalMultiphaseFluidUpdates) << "\n"
<< "props: " << sizeof(compositional::ComponentProperties::KernelWrapper) << "\n"
<< "flash: " << sizeof(typename FLASH::KernelWrapper) << "\n"
<< "phase1: " << sizeof(typename PHASE1::KernelWrapper) << "\n"
<< "phase2: " << sizeof(typename PHASE2::KernelWrapper) << "\n"
<< "phase3: " << sizeof(typename PHASE3::KernelWrapper) << "\n"
<< std::endl;
}
{}

template< typename FLASH, typename PHASE1, typename PHASE2, typename PHASE3 >
GEOS_HOST_DEVICE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void CompositionalProperties::computeMolarDensity( integer const numComps,
real64 & molarDensity )
{

real64 vEos = MultiFluidConstants::gasConstant * temperature * compressibilityFactor / pressure;
real64 vEos = constants::gasConstant * temperature * compressibilityFactor / pressure;
real64 vCorrected = vEos;

for( integer ic = 0; ic < numComps; ++ic )
Expand Down Expand Up @@ -91,17 +91,17 @@ void CompositionalProperties::computeMolarDensity( integer const numComps,
real64 dvCorrected_dx = 0.0;

// Pressure derivative
dvCorrected_dx = MultiFluidConstants::gasConstant * temperature * (dCompressibilityFactor_dp - compressibilityFactor / pressure) / pressure;
dvCorrected_dx = constants::gasConstant * temperature * (dCompressibilityFactor_dp - compressibilityFactor / pressure) / pressure;
dMolarDensity_dp = -molarDensity * molarDensity * dvCorrected_dx;

// Temperature derivative
dvCorrected_dx = MultiFluidConstants::gasConstant * (temperature * dCompressibilityFactor_dt + compressibilityFactor) / pressure;
dvCorrected_dx = constants::gasConstant * (temperature * dCompressibilityFactor_dt + compressibilityFactor) / pressure;
dMolarDensity_dt = -molarDensity * molarDensity * dvCorrected_dx;

// Composition derivative
for( integer ic = 0; ic < numComps; ++ic )
{
dvCorrected_dx = MultiFluidConstants::gasConstant * temperature * dCompressibilityFactor_dz[ic] / pressure + volumeShift[ic];
dvCorrected_dx = constants::gasConstant * temperature * dCompressibilityFactor_dz[ic] / pressure + volumeShift[ic];
dMolarDensity_dz[ic] = -molarDensity * molarDensity * dvCorrected_dx;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ solveCubicPolynomial( real64 const & m3,
real64 const theta = acos( r / sqrt( qCubed ) );
real64 const qSqrt = sqrt( q );
roots[0] = -2 * qSqrt * cos( theta / 3 ) - a1 / 3;
roots[1] = -2 * qSqrt * cos( ( theta + 2 * MultiFluidConstants::pi ) / 3 ) - a1 / 3;
roots[2] = -2 * qSqrt * cos( ( theta + 4 * MultiFluidConstants::pi ) / 3 ) - a1 / 3;
roots[1] = -2 * qSqrt * cos( ( theta + 2 * constants::pi ) / 3 ) - a1 / 3;
roots[2] = -2 * qSqrt * cos( ( theta + 4 * constants::pi ) / 3 ) - a1 / 3;
numRoots = 3;
}
// one real root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ComponentProperties final
* @brief Get the number of components
* @return The number of components
*/
integer getNumberOfComponents() const { return m_componentMolarWeight.size( 0 ); }
integer getNumberOfComponents() const { return m_componentNames.size(); }

struct KernelWrapper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "ReactionsBase.hpp"

#include "constitutive/fluid/multifluid/Layouts.hpp"
#include "constitutive/fluid/multifluid/MultiFluidConstants.hpp"
#include "common/PhysicsConstants.hpp"

namespace geos
{
Expand All @@ -43,7 +43,7 @@ class KineticReactions : public ReactionsBase
{
public:

static constexpr real64 RConst = MultiFluidConstants::gasConstant;
static constexpr real64 RConst = constants::gasConstant;

KernelWrapper( integer const numPrimarySpecies,
integer const numSecondarySpecies,
Expand Down
Loading