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

EclThermalConductionLaw(Params): use visitors #3291

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ list (APPEND TEST_SOURCE_FILES
tests/test_tabulation.cpp
tests/test_threecomponents_ptflash.cpp
tests/test_uniformtablelinear.cpp
tests/test_Visitor.cpp
)
if(ENABLE_ECL_INPUT)
list(APPEND TEST_SOURCE_FILES
Expand Down Expand Up @@ -662,6 +663,7 @@ list( APPEND PUBLIC_HEADER_FILES
opm/common/utility/FileSystem.hpp
opm/common/utility/OpmInputError.hpp
opm/common/utility/Serializer.hpp
opm/common/utility/Visitor.hpp
opm/common/utility/numeric/cmp.hpp
opm/common/utility/platform_dependent/disable_warnings.h
opm/common/utility/platform_dependent/reenable_warnings.h
Expand Down Expand Up @@ -877,6 +879,7 @@ list( APPEND PUBLIC_HEADER_FILES
opm/material/thermal/FluidThermalConductionLawParams.hpp
opm/material/thermal/EclHeatcrLawParams.hpp
opm/material/thermal/NullThermalConductionLaw.hpp
opm/material/thermal/NullThermalConductionLawParams.hpp
opm/material/thermal/EclSolidEnergyLawMultiplexer.hpp
opm/material/thermal/EclThermalConductionLawMultiplexerParams.hpp
opm/material/thermal/EclThermalConductionLawMultiplexer.hpp
Expand Down
64 changes: 64 additions & 0 deletions opm/common/utility/Visitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
This file is part of the Open Porous Media project (OPM).

OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.

Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/

#ifndef VISITOR_HPP
#define VISITOR_HPP

#include <string>
#include <variant>

namespace Opm {

//! \brief Helper struct for for generating visitor overload sets.
template<class... Ts>
struct VisitorOverloadSet : Ts...
{
using Ts::operator()...;
};

//! \brief Deduction guide for visitor overload sets.
template<class... Ts> VisitorOverloadSet(Ts...) -> VisitorOverloadSet<Ts...>;

//! \brief A functor for handling a monostate in a visitor overload set.
//! \details Throws an exception
template<class Exception>
struct MonoThrowHandler {
MonoThrowHandler(const std::string& message)
: message_(message)
{}

void operator()(std::monostate&)
{
throw Exception(message_);
}

void operator()(const std::monostate&) const
{
throw Exception(message_);
}

private:
std::string message_;
};

}

#endif
10 changes: 5 additions & 5 deletions opm/material/thermal/EclSolidEnergyLawMultiplexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class EclSolidEnergyLawMultiplexer
static Evaluation solidInternalEnergy(const Params& params, const FluidState& fluidState)
{
switch (params.solidEnergyApproach()) {
case Params::heatcrApproach:
case EclSolidEnergyApproach::Heatcr:
// relevant ECL keywords: HEATCR, HEATCRT and STCOND
return HeatcrLaw::solidInternalEnergy(params.template getRealParams<Params::heatcrApproach>(), fluidState);
return HeatcrLaw::solidInternalEnergy(params.template getRealParams<EclSolidEnergyApproach::Heatcr>(), fluidState);

case Params::specrockApproach:
case EclSolidEnergyApproach::Specrock:
// relevant ECL keyword: SPECROCK
return SpecrockLaw::solidInternalEnergy(params.template getRealParams<Params::specrockApproach>(), fluidState);
return SpecrockLaw::solidInternalEnergy(params.template getRealParams<EclSolidEnergyApproach::Specrock>(), fluidState);

case Params::nullApproach:
case EclSolidEnergyApproach::Null:
// (no relevant ECL keyword)
return NullLaw::solidInternalEnergy(0, fluidState);

Expand Down
56 changes: 28 additions & 28 deletions opm/material/thermal/EclSolidEnergyLawMultiplexerParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@

namespace Opm {

enum class EclSolidEnergyApproach {
Undefined,
Heatcr, // keywords: HEATCR, HEATCRT, STCOND
Specrock, // keyword: SPECROCK
Null // (no keywords)
};

/*!
* \brief The default implementation of a parameter object for the
* ECL thermal law.
Expand All @@ -50,78 +57,71 @@ class EclSolidEnergyLawMultiplexerParams : public EnsureFinalized
public:
using Scalar = ScalarT;

enum SolidEnergyApproach {
undefinedApproach,
heatcrApproach, // keywords: HEATCR, HEATCRT, STCOND
specrockApproach, // keyword: SPECROCK
nullApproach, // (no keywords)
};

using HeatcrLawParams = EclHeatcrLawParams<ScalarT>;
using SpecrockLawParams = EclSpecrockLawParams<ScalarT>;

EclSolidEnergyLawMultiplexerParams(const EclSolidEnergyLawMultiplexerParams&) = default;

EclSolidEnergyLawMultiplexerParams()
{ solidEnergyApproach_ = undefinedApproach; }
{ solidEnergyApproach_ = EclSolidEnergyApproach::Undefined; }

~EclSolidEnergyLawMultiplexerParams()
{ destroy_(); }

void setSolidEnergyApproach(SolidEnergyApproach newApproach)
void setSolidEnergyApproach(EclSolidEnergyApproach newApproach)
{
destroy_();

solidEnergyApproach_ = newApproach;
switch (solidEnergyApproach()) {
case undefinedApproach:
case EclSolidEnergyApproach::Undefined:
throw std::logic_error("Cannot set the approach for solid energy storage to 'undefined'!");

case heatcrApproach:
case EclSolidEnergyApproach::Heatcr:
realParams_ = new HeatcrLawParams;
break;

case specrockApproach:
case EclSolidEnergyApproach::Specrock:
realParams_ = new SpecrockLawParams;
break;

case nullApproach:
case EclSolidEnergyApproach::Null:
realParams_ = nullptr;
break;
}
}

SolidEnergyApproach solidEnergyApproach() const
EclSolidEnergyApproach solidEnergyApproach() const
{ return solidEnergyApproach_; }

// get the parameter object for the HEATCR case
template <SolidEnergyApproach approachV>
typename std::enable_if<approachV == heatcrApproach, HeatcrLawParams>::type&
template <EclSolidEnergyApproach approachV>
typename std::enable_if<approachV == EclSolidEnergyApproach::Heatcr, HeatcrLawParams>::type&
getRealParams()
{
assert(solidEnergyApproach() == approachV);
return *static_cast<HeatcrLawParams*>(realParams_);
}

template <SolidEnergyApproach approachV>
typename std::enable_if<approachV == heatcrApproach, const HeatcrLawParams>::type&
template <EclSolidEnergyApproach approachV>
typename std::enable_if<approachV == EclSolidEnergyApproach::Heatcr, const HeatcrLawParams>::type&
getRealParams() const
{
assert(solidEnergyApproach() == approachV);
return *static_cast<const HeatcrLawParams*>(realParams_);
}

// get the parameter object for the SPECROCK case
template <SolidEnergyApproach approachV>
typename std::enable_if<approachV == specrockApproach, SpecrockLawParams>::type&
template <EclSolidEnergyApproach approachV>
typename std::enable_if<approachV == EclSolidEnergyApproach::Specrock, SpecrockLawParams>::type&
getRealParams()
{
assert(solidEnergyApproach() == approachV);
return *static_cast<SpecrockLawParams*>(realParams_);
}

template <SolidEnergyApproach approachV>
typename std::enable_if<approachV == specrockApproach, const SpecrockLawParams>::type&
template <EclSolidEnergyApproach approachV>
typename std::enable_if<approachV == EclSolidEnergyApproach::Specrock, const SpecrockLawParams>::type&
getRealParams() const
{
assert(solidEnergyApproach() == approachV);
Expand All @@ -132,25 +132,25 @@ class EclSolidEnergyLawMultiplexerParams : public EnsureFinalized
void destroy_()
{
switch (solidEnergyApproach()) {
case undefinedApproach:
case EclSolidEnergyApproach::Undefined:
break;

case heatcrApproach:
case EclSolidEnergyApproach::Heatcr:
delete static_cast<HeatcrLawParams*>(realParams_);
break;

case specrockApproach:
case EclSolidEnergyApproach::Specrock:
delete static_cast<SpecrockLawParams*>(realParams_);
break;

case nullApproach:
case EclSolidEnergyApproach::Null:
break;
}

solidEnergyApproach_ = undefinedApproach;
solidEnergyApproach_ = EclSolidEnergyApproach::Undefined;
}

SolidEnergyApproach solidEnergyApproach_;
EclSolidEnergyApproach solidEnergyApproach_;
ParamPointerType realParams_;
};

Expand Down
18 changes: 8 additions & 10 deletions opm/material/thermal/EclThcLawParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

namespace Opm {

template <class ScalarT, class ParamsT> class EclThcLaw;

/*!
* \brief The default implementation of a parameter object for the
* thermal conduction law based on the THC* keywords from ECL.
Expand All @@ -40,11 +42,7 @@ class EclThcLawParams : public EnsureFinalized
{
public:
using Scalar = ScalarT;

EclThcLawParams(const EclThcLawParams&) = default;

EclThcLawParams()
{ }
using Law = EclThcLaw<ScalarT,EclThcLawParams<ScalarT>>;

/*!
* \brief Set the porosity
Expand Down Expand Up @@ -107,11 +105,11 @@ class EclThcLawParams : public EnsureFinalized
{ EnsureFinalized::check(); return thcwater_; }

private:
Scalar porosity_;
Scalar thcrock_;
Scalar thcoil_;
Scalar thcgas_;
Scalar thcwater_;
Scalar porosity_{};
Scalar thcrock_{};
Scalar thcoil_{};
Scalar thcgas_{};
Scalar thcwater_{};
};

} // namespace Opm
Expand Down
2 changes: 1 addition & 1 deletion opm/material/thermal/EclThconrLaw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Opm
*/
template <class ScalarT,
class FluidSystem,
class ParamsT = EclThconrLawParams<ScalarT>>
class ParamsT = EclThconrLawParams<ScalarT,FluidSystem>>
class EclThconrLaw
{
public:
Expand Down
14 changes: 6 additions & 8 deletions opm/material/thermal/EclThconrLawParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@

namespace Opm {

template <class ScalarT, class FluidSystem, class ParamsT> class EclThconrLaw;

/*!
* \brief The default implementation of a parameter object for the
* thermal conduction law based on the THCONR keyword from ECL.
*/
template <class ScalarT>
template <class ScalarT, class FluidSystem>
class EclThconrLawParams : public EnsureFinalized
{
public:
using Scalar = ScalarT;

EclThconrLawParams(const EclThconrLawParams&) = default;

EclThconrLawParams()
{ }
using Law = EclThconrLaw<ScalarT,FluidSystem,EclThconrLawParams<ScalarT,FluidSystem>>;

/*!
* \brief Set the total thermal conductivity [J/m^2 / (K/m)] of at Sg = 0
Expand All @@ -71,8 +69,8 @@ class EclThconrLawParams : public EnsureFinalized
{ EnsureFinalized::check(); return dTotalThermalConductivity_dSg_; }

private:
Scalar referenceTotalThermalConductivity_;
Scalar dTotalThermalConductivity_dSg_;
Scalar referenceTotalThermalConductivity_{};
Scalar dTotalThermalConductivity_dSg_{};
};

} // namespace Opm
Expand Down
Loading