move NumericDifferenceMethod to TypeTag-free parameter system

This commit is contained in:
Arne Morten Kvarving 2024-07-05 17:49:51 +02:00
parent 7da433b6dd
commit 00121f10a4
6 changed files with 52 additions and 47 deletions

View File

@ -164,11 +164,6 @@ template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::FingerBaseProblem> struct NewtonWriteConvergence<TypeTag, Properties::TTag::FingerBaseProblem>
{ static constexpr bool value = false; }; { static constexpr bool value = false; };
// Use forward differences instead of central differences
template<class TypeTag>
struct NumericDifferenceMethod<TypeTag, Properties::TTag::FingerBaseProblem>
{ static constexpr int value = +1; };
} // namespace Opm::Parameters } // namespace Opm::Parameters
namespace Opm { namespace Opm {
@ -298,6 +293,9 @@ public:
Parameters::SetDefault<Parameters::CellsZ>(1); Parameters::SetDefault<Parameters::CellsZ>(1);
Parameters::SetDefault<Parameters::DomainSizeZ<Scalar>>(0.1); Parameters::SetDefault<Parameters::DomainSizeZ<Scalar>>(0.1);
} }
// Use forward differences
Parameters::SetDefault<Parameters::NumericDifferenceMethod>(+1);
} }
/*! /*!

View File

@ -118,11 +118,6 @@ template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::InfiltrationBaseProblem> struct NewtonWriteConvergence<TypeTag, Properties::TTag::InfiltrationBaseProblem>
{ static constexpr bool value = false; }; { static constexpr bool value = false; };
// -1 backward differences, 0: central differences, +1: forward differences
template<class TypeTag>
struct NumericDifferenceMethod<TypeTag, Properties::TTag::InfiltrationBaseProblem>
{ static constexpr int value = 1; };
} // namespace Opm::Parameters } // namespace Opm::Parameters
namespace Opm { namespace Opm {
@ -247,6 +242,7 @@ public:
ParentType::registerParameters(); ParentType::registerParameters();
Parameters::SetDefault<Parameters::GridFile>("./data/infiltration_50x3.dgf"); Parameters::SetDefault<Parameters::GridFile>("./data/infiltration_50x3.dgf");
Parameters::SetDefault<Parameters::NumericDifferenceMethod>(1);
} }
/*! /*!

View File

@ -228,7 +228,7 @@ namespace Opm {
* water saturated medium. * water saturated medium.
* *
* The domain is sized 6m times 4m and features a rectangular lens * The domain is sized 6m times 4m and features a rectangular lens
* with low permeablility which spans from (1 m , 2 m) to (4 m, 3 m) * with low permeablility which spans from (1m, 2m) to (4m, 3m)
* and is surrounded by a medium with higher permability. Note that * and is surrounded by a medium with higher permability. Note that
* this problem is discretized using only two dimensions, so from the * this problem is discretized using only two dimensions, so from the
* point of view of the model, the depth of the domain is implicitly * point of view of the model, the depth of the domain is implicitly
@ -371,6 +371,13 @@ public:
Parameters::SetDefault<Parameters::CellsZ>(16); Parameters::SetDefault<Parameters::CellsZ>(16);
Parameters::SetDefault<Parameters::DomainSizeZ<Scalar>>(1.0); Parameters::SetDefault<Parameters::DomainSizeZ<Scalar>>(1.0);
} }
// Use forward differences
using LLS = GetPropType<TypeTag, Properties::LocalLinearizerSplice>;
constexpr bool useFD = std::is_same_v<LLS, Properties::TTag::FiniteDifferenceLocalLinearizer>;
if constexpr (useFD) {
Parameters::SetDefault<Parameters::NumericDifferenceMethod>(+1);
}
} }
/*! /*!
@ -379,20 +386,21 @@ public:
static std::string briefDescription() static std::string briefDescription()
{ {
std::string thermal = "isothermal"; std::string thermal = "isothermal";
bool enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>(); constexpr bool enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>();
if (enableEnergy) if constexpr (enableEnergy)
thermal = "non-isothermal"; thermal = "non-isothermal";
std::string deriv = "finite difference"; std::string deriv = "finite difference";
using LLS = GetPropType<TypeTag, Properties::LocalLinearizerSplice>; using LLS = GetPropType<TypeTag, Properties::LocalLinearizerSplice>;
bool useAutoDiff = std::is_same<LLS, Properties::TTag::AutoDiffLocalLinearizer>::value; constexpr bool useAutoDiff = std::is_same_v<LLS, Properties::TTag::AutoDiffLocalLinearizer>;
if (useAutoDiff) if constexpr (useAutoDiff) {
deriv = "automatic differentiation"; deriv = "automatic differentiation";
}
std::string disc = "vertex centered finite volume"; std::string disc = "vertex centered finite volume";
using D = GetPropType<TypeTag, Properties::Discretization>; using D = GetPropType<TypeTag, Properties::Discretization>;
bool useEcfv = std::is_same<D, Opm::EcfvDiscretization<TypeTag>>::value; constexpr bool useEcfv = std::is_same<D, Opm::EcfvDiscretization<TypeTag>>::value;
if (useEcfv) if constexpr (useEcfv)
disc = "element centered finite volume"; disc = "element centered finite volume";
return std::string("")+ return std::string("")+
@ -467,10 +475,10 @@ public:
{ {
using LLS = GetPropType<TypeTag, Properties::LocalLinearizerSplice>; using LLS = GetPropType<TypeTag, Properties::LocalLinearizerSplice>;
bool useAutoDiff = std::is_same<LLS, Properties::TTag::AutoDiffLocalLinearizer>::value; constexpr bool useAutoDiff = std::is_same_v<LLS, Properties::TTag::AutoDiffLocalLinearizer>;
using FM = GetPropType<TypeTag, Properties::FluxModule>; using FM = GetPropType<TypeTag, Properties::FluxModule>;
bool useTrans = std::is_same<FM, Opm::TransFluxModule<TypeTag>>::value; constexpr bool useTrans = std::is_same_v<FM, Opm::TransFluxModule<TypeTag>>;
std::ostringstream oss; std::ostringstream oss;
oss << "lens_" << Model::name() oss << "lens_" << Model::name()

View File

@ -139,11 +139,6 @@ template<class TypeTag>
struct NewtonMaxIterations<TypeTag, Properties::TTag::RichardsLensProblem> struct NewtonMaxIterations<TypeTag, Properties::TTag::RichardsLensProblem>
{ static constexpr int value = 28; }; { static constexpr int value = 28; };
// Use central differences to approximate the Jacobian matrix
template<class TypeTag>
struct NumericDifferenceMethod<TypeTag, Properties::TTag::RichardsLensProblem>
{ static constexpr int value = 0; };
} // namespace Opm::Parameters } // namespace Opm::Parameters
namespace Opm { namespace Opm {
@ -270,6 +265,13 @@ public:
ParentType::registerParameters(); ParentType::registerParameters();
Parameters::SetDefault<Parameters::GridFile>("./data/richardslens_24x16.dgf"); Parameters::SetDefault<Parameters::GridFile>("./data/richardslens_24x16.dgf");
// Use central differences to approximate the Jacobian matrix
using LLS = GetPropType<TypeTag, Properties::LocalLinearizerSplice>;
constexpr bool useFD = std::is_same_v<LLS, Properties::TTag::FiniteDifferenceLocalLinearizer>;
if constexpr (useFD) {
Parameters::SetDefault<Parameters::NumericDifferenceMethod>(0);
}
} }
/*! /*!

View File

@ -28,25 +28,28 @@
#ifndef EWOMS_WATER_AIR_PROBLEM_HH #ifndef EWOMS_WATER_AIR_PROBLEM_HH
#define EWOMS_WATER_AIR_PROBLEM_HH #define EWOMS_WATER_AIR_PROBLEM_HH
#include <opm/models/pvs/pvsproperties.hh> #include <dune/common/fmatrix.hh>
#include <opm/simulators/linalg/parallelistlbackend.hh> #include <dune/common/fvector.hh>
#include <opm/material/fluidsystems/H2OAirFluidSystem.hpp>
#include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
#include <opm/material/fluidstates/CompositionalFluidState.hpp>
#include <opm/material/fluidmatrixinteractions/LinearMaterial.hpp>
#include <opm/material/fluidmatrixinteractions/RegularizedBrooksCorey.hpp>
#include <opm/material/fluidmatrixinteractions/EffToAbsLaw.hpp>
#include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
#include <opm/material/thermal/ConstantSolidHeatCapLaw.hpp>
#include <opm/material/thermal/SomertonThermalConductionLaw.hpp>
#include <opm/material/constraintsolvers/ComputeFromReferencePhase.hpp>
#include <dune/grid/yaspgrid.hh> #include <dune/grid/yaspgrid.hh>
#include <dune/grid/io/file/dgfparser/dgfyasp.hh> #include <dune/grid/io/file/dgfparser/dgfyasp.hh>
#include <dune/common/fvector.hh> #include <opm/material/constraintsolvers/ComputeFromReferencePhase.hpp>
#include <dune/common/fmatrix.hh> #include <opm/material/fluidmatrixinteractions/LinearMaterial.hpp>
#include <opm/material/fluidmatrixinteractions/RegularizedBrooksCorey.hpp>
#include <opm/material/fluidmatrixinteractions/EffToAbsLaw.hpp>
#include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
#include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
#include <opm/material/fluidstates/CompositionalFluidState.hpp>
#include <opm/material/fluidsystems/H2OAirFluidSystem.hpp>
#include <opm/material/thermal/ConstantSolidHeatCapLaw.hpp>
#include <opm/material/thermal/SomertonThermalConductionLaw.hpp>
#include <opm/models/discretization/common/fvbasefdlocallinearizer.hh>
#include <opm/models/pvs/pvsproperties.hh>
#include <opm/simulators/linalg/parallelistlbackend.hh>
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -310,6 +313,9 @@ public:
ParentType::registerParameters(); ParentType::registerParameters();
Parameters::SetDefault<Parameters::GridFile>("./data/waterair.dgf"); Parameters::SetDefault<Parameters::GridFile>("./data/waterair.dgf");
// Use forward differences
Parameters::SetDefault<Parameters::NumericDifferenceMethod>(+1);
} }
/*! /*!

View File

@ -82,9 +82,6 @@ struct BaseEpsilon<TypeTag, TTag::FiniteDifferenceLocalLinearizer>
namespace Opm::Parameters { namespace Opm::Parameters {
template<class TypeTag, class MyTypeTag>
struct NumericDifferenceMethod { using type = Properties::UndefinedProperty; };
/*! /*!
* \brief Specify which kind of method should be used to numerically * \brief Specify which kind of method should be used to numerically
* calculate the partial derivatives of the residual. * calculate the partial derivatives of the residual.
@ -92,9 +89,7 @@ struct NumericDifferenceMethod { using type = Properties::UndefinedProperty; };
* -1 means backward differences, 0 means central differences, 1 means * -1 means backward differences, 0 means central differences, 1 means
* forward differences. By default we use forward differences. * forward differences. By default we use forward differences.
*/ */
template<class TypeTag> struct NumericDifferenceMethod { static constexpr int value = +1; };
struct NumericDifferenceMethod<TypeTag, Properties::TTag::FiniteDifferenceLocalLinearizer>
{ static constexpr int value = +1; };
} // namespace Opm::Parameters } // namespace Opm::Parameters
@ -188,7 +183,7 @@ public:
*/ */
static void registerParameters() static void registerParameters()
{ {
Parameters::registerParam<TypeTag, Parameters::NumericDifferenceMethod> Parameters::Register<Parameters::NumericDifferenceMethod>
("The method used for numeric differentiation (-1: backward " ("The method used for numeric differentiation (-1: backward "
"differences, 0: central differences, 1: forward differences)"); "differences, 0: central differences, 1: forward differences)");
} }
@ -342,7 +337,7 @@ protected:
*/ */
static int numericDifferenceMethod_() static int numericDifferenceMethod_()
{ {
static int diff = Parameters::get<TypeTag, Parameters::NumericDifferenceMethod>(); static int diff = Parameters::Get<Parameters::NumericDifferenceMethod>();
return diff; return diff;
} }