Skip to content

Commit

Permalink
Add BlackOilFluidSystemNonStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
multitalentloes committed Jan 15, 2025
1 parent 93338de commit ecd9eb7
Show file tree
Hide file tree
Showing 7 changed files with 2,450 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/material/densead/Evaluation.cpp
opm/material/fluidmatrixinteractions/EclEpsScalingPoints.cpp
opm/material/fluidsystems/BlackOilFluidSystem.cpp
opm/material/fluidsystems/BlackOilFluidSystemNonStatic.cpp
opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.cpp
opm/material/fluidsystems/blackoilpvt/BrineH2Pvt.cpp
opm/material/fluidsystems/blackoilpvt/Co2GasPvt.cpp
Expand Down Expand Up @@ -926,6 +927,7 @@ list( APPEND PUBLIC_HEADER_FILES
opm/material/fluidsystems/GasPhase.hpp
opm/material/fluidsystems/TwoPhaseImmiscibleFluidSystem.hpp
opm/material/fluidsystems/BlackOilFluidSystem.hpp
opm/material/fluidsystems/BlackOilFluidSystemNonStatic.hpp
opm/material/fluidsystems/LiquidPhase.hpp
opm/material/fluidsystems/PTFlashParameterCache.hpp
opm/material/fluidsystems/Spe5ParameterCache.hpp
Expand Down
10 changes: 5 additions & 5 deletions opm/input/eclipse/Schedule/ScheduleState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include <type_traits>
#include <unordered_map>
#include <utility>
template <typename>
struct always_false1 : std::false_type {};

namespace {

Expand Down Expand Up @@ -428,11 +430,10 @@ namespace Opm {
return const_cast<ptr_member<T>&>(std::as_const(*this).template get<T>());
}


template <typename T>
const ptr_member<T>& get() const
{
struct always_false1 : std::false_type {};

if constexpr ( std::is_same_v<T, PAvg> )
return this->pavg;
else if constexpr ( std::is_same_v<T, WellTestConfig> )
Expand Down Expand Up @@ -478,14 +479,13 @@ namespace Opm {
else if constexpr ( std::is_same_v<T, WCYCLE> )
return this->wcycle;
else
static_assert(always_false1::value, "Template type <T> not supported in get()");
static_assert(always_false1<T>::value, "Template type <T> not supported in get()");
}


template <typename K, typename T>
map_member<K,T>& get_map()
{
struct always_false2 : std::false_type {};
if constexpr ( std::is_same_v<T, VFPProdTable> )
return this->vfpprod;
else if constexpr ( std::is_same_v<T, VFPInjTable> )
Expand All @@ -495,7 +495,7 @@ namespace Opm {
else if constexpr ( std::is_same_v<T, Well> )
return this->wells;
else
static_assert(always_false2::value, "Template type <K,T> not supported in get_map()");
static_assert(always_false1<T>::value, "Template type <K,T> not supported in get_map()");
}

map_member<int, VFPProdTable> vfpprod;
Expand Down
4 changes: 4 additions & 0 deletions opm/material/binarycoefficients/Brine_CO2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,11 @@ class Brine_CO2 {
convTerm = 1.0;
}
else {
#if !OPM_IS_INSIDE_DEVICE_FUNCTION
throw std::runtime_error("Activity model for salt-out effect has not been implemented!");
#else
assert(false && "Activity model for salt-out effect has not been implemented!");
#endif
}

// Eq. (18)
Expand Down
118 changes: 116 additions & 2 deletions opm/material/fluidsystems/BlackOilFluidSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <opm/material/common/Valgrind.hpp>
#include <opm/material/common/HasMemberGeneratorMacros.hpp>
#include <opm/material/fluidsystems/NullParameterCache.hpp>
#include <opm/material/fluidsystems/BlackOilFluidSystemNonStatic.hpp>

#include <array>
#include <cstddef>
Expand Down Expand Up @@ -151,21 +152,33 @@ auto getSaltSaturation_(typename std::enable_if<HasMember_saltSaturation<FluidSt

}

template <class Scalar, class IndexTraits>
class BlackOilFluidSystemNonStatic;

/*!
* \brief A fluid system which uses the black-oil model assumptions to calculate
* termodynamically meaningful quantities.
*
* \tparam Scalar The type used for scalar floating point values
*/
template <class Scalar, class IndexTraits = BlackOilDefaultIndexTraits>
class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<Scalar, IndexTraits> >
template <class Scalar, class IndexTraits_ = BlackOilDefaultIndexTraits>
class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<Scalar, IndexTraits_> >
{
using ThisType = BlackOilFluidSystem;

public:
using NonStaticBlackOilFluidSystem = BlackOilFluidSystemNonStatic<Scalar, IndexTraits_>;
using GasPvt = GasPvtMultiplexer<Scalar>;
using OilPvt = OilPvtMultiplexer<Scalar>;
using WaterPvt = WaterPvtMultiplexer<Scalar>;
using IndexTraits = IndexTraits_;

public:

static const NonStaticBlackOilFluidSystem& getNonStatic()
{
return NonStaticBlackOilFluidSystem::getInstance();
}

//! \copydoc BaseFluidSystem::ParameterCache
template <class EvaluationT>
Expand Down Expand Up @@ -407,6 +420,9 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
return phaseIsActive_[phaseIdx];
}

static std::array<bool,numPhases> phaseIsActiveArray()
{ return phaseIsActive_; }

//! \brief returns the index of "primary" component of a phase (solvent)
static unsigned solventComponentIndex(unsigned phaseIdx);

Expand All @@ -420,6 +436,10 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static Scalar molarMass(unsigned compIdx, unsigned regionIdx = 0)
{ return molarMass_[regionIdx][compIdx]; }

//! \copydoc BaseFluidSystem::molarMass
static std::vector<std::array<Scalar, 3>> molarMass()
{ return molarMass_; }

//! \copydoc BaseFluidSystem::isIdealMixture
static bool isIdealMixture(unsigned /*phaseIdx*/)
{
Expand Down Expand Up @@ -509,6 +529,26 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static Scalar referenceDensity(unsigned phaseIdx, unsigned regionIdx)
{ return referenceDensity_[regionIdx][phaseIdx]; }

/*!
* \brief Returns the density of a fluid phase at surface pressure [kg/m^3]
*
* \copydoc Doxygen::phaseIdxParam
*/
static std::vector<std::array<Scalar, 3>> referenceDensity()
{ return referenceDensity_; }

/*!
* \brief Returns the canonical to active phase idx mapping
*/
static std::array<short, numPhases> canonicalToActivePhaseIdx()
{ return canonicalToActivePhaseIdx_; }

/*!
* \brief Returns the active to canonical phase idx mapping
*/
static std::array<short, numPhases> activeToCanonicalPhaseIdx()
{ return activeToCanonicalPhaseIdx_; }

/****************************************
* thermodynamic quantities (generic version)
****************************************/
Expand Down Expand Up @@ -1609,6 +1649,9 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static const GasPvt& gasPvt()
{ return *gasPvt_; }

static const std::shared_ptr<GasPvt>& gasPvtSharedPtr()
{ return gasPvt_; }

/*!
* \brief Return a reference to the low-level object which calculates the oil phase
* quantities.
Expand All @@ -1619,6 +1662,9 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static const OilPvt& oilPvt()
{ return *oilPvt_; }

static const std::shared_ptr<OilPvt>& oilPvtSharedPtr()
{ return oilPvt_; }

/*!
* \brief Return a reference to the low-level object which calculates the water phase
* quantities.
Expand All @@ -1629,6 +1675,9 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static const WaterPvt& waterPvt()
{ return *waterPvt_; }

static const std::shared_ptr<WaterPvt>& waterPvtSharedPtr()
{ return waterPvt_; }

/*!
* \brief Set the temperature of the reservoir.
*
Expand All @@ -1653,6 +1702,10 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static Scalar diffusionCoefficient(unsigned compIdx, unsigned phaseIdx, unsigned regionIdx = 0)
{ return diffusionCoefficients_[regionIdx][numPhases*compIdx + phaseIdx]; }

//! \copydoc BaseFluidSystem::diffusionCoefficient
static std::vector<std::array<Scalar, 9>> diffusionCoefficient()
{ return diffusionCoefficients_; }

//! \copydoc BaseFluidSystem::setDiffusionCoefficient
static void setDiffusionCoefficient(Scalar coefficient, unsigned compIdx, unsigned phaseIdx, unsigned regionIdx = 0)
{ diffusionCoefficients_[regionIdx][numPhases*compIdx + phaseIdx] = coefficient ; }
Expand Down Expand Up @@ -1723,6 +1776,67 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
inline static bool enthalpy_eq_energy_ = false;
};


// Helper trait to check for the existence of member types Scalar and IndexTraits
template<typename, typename = std::void_t<>>
struct has_Scalar_and_IndexTraits : std::false_type {};

template<typename FluidSystem>
struct has_Scalar_and_IndexTraits<
FluidSystem,
std::void_t<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>
> : std::true_type {};

// Adjusted function
template<class FluidSystem>
constexpr bool is_a_blackoil_system() {
if constexpr (std::is_same_v<FluidSystem, void*>) {
return false;
} else if constexpr (std::is_same_v<FluidSystem, std::nullptr_t>) {
return false;
} else if constexpr (!std::is_class_v<FluidSystem>) {
return false;
} else if constexpr (!has_Scalar_and_IndexTraits<FluidSystem>::value) {
return false;
} else if constexpr (
// !std::is_class_v<typename FluidSystem::Scalar> ||
!std::is_class_v<typename FluidSystem::IndexTraits>
) {
return false;
} else {
return \
std::is_same_v<BlackOilFluidSystem<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>, FluidSystem>
|| std::is_same_v<const BlackOilFluidSystem<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>,FluidSystem>
|| std::is_same_v<const BlackOilFluidSystem<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>&,FluidSystem>
|| std::is_same_v<BlackOilFluidSystemNonStatic<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>, FluidSystem>
|| std::is_same_v<const BlackOilFluidSystemNonStatic<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>,FluidSystem>
|| std::is_same_v<const BlackOilFluidSystemNonStatic<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>&,FluidSystem>;
}
}

template<class FluidSystem>
constexpr bool is_a_dynamic_blackoil_system() {
if constexpr (std::is_same_v<FluidSystem, void*>) {
return false;
} else if constexpr (std::is_same_v<FluidSystem, std::nullptr_t>) {
return false;
} else if constexpr (!std::is_class_v<FluidSystem>) {
return false;
} else if constexpr (!has_Scalar_and_IndexTraits<FluidSystem>::value) {
return false;
} else if constexpr (
// !std::is_class_v<typename FluidSystem::Scalar> ||
!std::is_class_v<typename FluidSystem::IndexTraits>
) {
return false;
} else {
return \
std::is_same_v<BlackOilFluidSystemNonStatic<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>, FluidSystem>
|| std::is_same_v<const BlackOilFluidSystemNonStatic<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>,FluidSystem>
|| std::is_same_v<const BlackOilFluidSystemNonStatic<typename FluidSystem::Scalar, typename FluidSystem::IndexTraits>&,FluidSystem>;
}
}

template <typename T> using BOFS = BlackOilFluidSystem<T, BlackOilDefaultIndexTraits>;

#define DECLARE_INSTANCE(T) \
Expand Down
Loading

0 comments on commit ecd9eb7

Please sign in to comment.