[Richards] Gather parameterization classes within a namespace

parent 0d14817b
......@@ -24,21 +24,21 @@ namespace Dorie {
template<class Traits>
struct RichardsParameterizationFactory
: public ParameterizationFactory<Dorie::RichardsParameterization<Traits>>
: public ParameterizationFactory<Dorie::Parameterization::Richards<Traits>>
{
/// Return a default-initialized parameterization object
/** \param type The type indicating the parameterization implementation
* \param name The name of the parameterization object (layer type)
*/
std::shared_ptr<Dorie::RichardsParameterization<Traits>>
std::shared_ptr<Dorie::Parameterization::Richards<Traits>>
selector(
const YAML::Node& type_node,
const std::string name) const override
{
auto log = Dorie::get_logger(log_richards);
const auto type = type_node["type"].as<std::string>();
if (type == MualemVanGenuchtenParameterization<Traits>::type) {
return std::make_shared<MualemVanGenuchtenParameterization<Traits>>(name);
if (type == Parameterization::MualemVanGenuchten<Traits>::type) {
return std::make_shared<Parameterization::MualemVanGenuchten<Traits>>(name);
}
else {
log->error("Parameterization '{}' has unknown type '{}'",
......@@ -91,23 +91,23 @@ private:
/// Index type used by the element mapper
using Index = typename Mapper::Index;
/// Base class of the parameterization
using Parameterization = Dorie::RichardsParameterization<Traits>;
using ParameterizationType = Dorie::Parameterization::Richards<Traits>;
/// Parameterization factory
using ParameterizationFactory = Dorie::RichardsParameterizationFactory<Traits>;
/// Struct for storing scaling factors
using Scaling = Dorie::ScalingFactors<RF>;
using Scaling = Dorie::Parameterization::ScalingFactors<RF>;
/// Base class for scaling adapters
using ScaleAdapter = Dorie::ScalingAdapter<Traits>;
using ScaleAdapter = Dorie::Parameterization::ScalingAdapter<Traits>;
/// Storage for parameters and skaling factors
using ParameterStorage = std::unordered_map<Index,
std::tuple<std::shared_ptr<Parameterization>, Scaling>
std::tuple<std::shared_ptr<ParameterizationType>, Scaling>
>;
/// Need this gruesome typedef because 'map::value_type' has const key
using Cache = std::tuple<std::shared_ptr<Parameterization>, Scaling>;
using Cache = std::tuple<std::shared_ptr<ParameterizationType>, Scaling>;
using ConstCache = std::tuple<std::shared_ptr<const Parameterization>, Scaling>;
using ConstCache = std::tuple<std::shared_ptr<const ParameterizationType>, Scaling>;
/// Configuration file tree
const Dune::ParameterTree& _config;
/// Grid view of the coarsest grid configuration (level 0)
......@@ -128,7 +128,7 @@ private:
/// Check if an entity has been cached
void verify_cache () const
{
if (not std::get<std::shared_ptr<Parameterization>>(_cache)) {
if (not std::get<std::shared_ptr<ParameterizationType>>(_cache)) {
_log->error("Parameterization cache is empty. Call 'bind' before "
"accessing the cache or the parameterization");
DUNE_THROW(Dune::InvalidStateException,
......@@ -155,7 +155,7 @@ public:
for(const auto& [index, tuple] : flow_param._param) {
const auto& [p, sk] = tuple;
// make a hard copy of parameterization
std::shared_ptr<RichardsParameterization<Traits>> _p = p->clone();
std::shared_ptr<Parameterization::Richards<Traits>> _p = p->clone();
this->_param.emplace(index,std::make_tuple(_p,sk));
}
}
......@@ -226,9 +226,9 @@ public:
{
verify_cache();
const auto& par =
std::get<std::shared_ptr<Parameterization>>(_cache);
std::get<std::shared_ptr<ParameterizationType>>(_cache);
const auto cond_f = par->conductivity_f();
using Saturation = typename Parameterization::Saturation;
using Saturation = typename ParameterizationType::SaturationType;
const auto& xi_cond = std::get<Scaling>(_cache).scale_cond;
......@@ -246,9 +246,9 @@ public:
{
verify_cache();
const auto& par =
std::get<std::shared_ptr<Parameterization>>(_cache);
std::get<std::shared_ptr<ParameterizationType>>(_cache);
const auto sat_f = par->saturation_f();
using MatricHead = typename Parameterization::MatricHead;
using MatricHead = typename ParameterizationType::MatricHeadType;
const auto& scale_head = std::get<Scaling>(_cache).scale_head;
......@@ -266,13 +266,13 @@ public:
{
verify_cache();
const auto& par =
std::get<std::shared_ptr<Parameterization>>(_cache);
std::get<std::shared_ptr<ParameterizationType>>(_cache);
// get water content function and apply the scaling
const auto& scale_por = std::get<Scaling>(_cache).scale_por;
const auto wc_f = par->water_content_f(scale_por);
using Saturation = typename Parameterization::Saturation;
using Saturation = typename ParameterizationType::SaturationType;
return [wc_f](const RF saturation) {
return wc_f(Saturation{saturation}).value;
};
......@@ -292,7 +292,7 @@ private:
const auto parameterization_map = factory.reader(param_file,"richards",_log);
// build global scaling
using SAF = Dorie::ScalingAdapterFactory<Traits>;
using SAF = Dorie::Parameterization::ScalingAdapterFactory<Traits>;
auto scale_cfg = param_file["scaling"];
auto scaling_adapter = SAF::create(scale_cfg["type"].as<std::string>(),
scale_cfg["data"],
......
......@@ -7,6 +7,7 @@
namespace Dune {
namespace Dorie {
namespace Parameterization {
/// Interface for parameterizations of Richards equation.
/** Defines the basic parameters and the relation between water content
......@@ -23,7 +24,7 @@ namespace Dorie {
* \ingroup RichardsParam
*/
template <typename Traits>
class RichardsParameterization
class Richards
{
private:
using RF = typename Traits::RF;
......@@ -32,56 +33,56 @@ public:
// These are standard types for all parameterizations of Richards Equation
/// Type of water saturation
struct Saturation
struct SaturationType
{
RF value;
};
/// Type of volumetric water content
struct WaterContent
struct WaterContentType
{
RF value;
};
/// Type of hydraulic conductivity
struct Conductivity
struct ConductivityType
{
RF value;
};
/// Type of matric head
struct MatricHead
struct MatricHeadType
{
RF value;
};
/// Parameter defining the saturated hydraulic conductivity
struct SaturatedConductivity
struct SaturatedConductivityType
{
RF value;
inline static const std::string name = "k0";
};
/// Parameter defining the residual water content
struct ResidualWaterContent
struct ResidualWaterContentType
{
RF value;
inline static const std::string name = "theta_r";
};
/// Parameter defining the saturated water content
struct SaturatedWaterContent
struct SaturatedWaterContentType
{
RF value;
inline static const std::string name = "theta_s";
};
//! Value of the residual water content.
ResidualWaterContent _theta_r;
ResidualWaterContentType _theta_r;
//! Value of the saturated water content.
SaturatedWaterContent _theta_s;
SaturatedWaterContentType _theta_s;
//! Value of the saturated hydraulic conductivity.
SaturatedConductivity _k0;
SaturatedConductivityType _k0;
//! The name of this parameterization instance, associated with the layer.
const std::string _name;
......@@ -91,7 +92,7 @@ public:
/** \param name The name associated with this soil layer
* \param parameters Tuple of parameters to use in this parameterization
*/
RichardsParameterization (const std::string name) :
Richards (const std::string name) :
_name(name)
{ }
......@@ -100,16 +101,16 @@ public:
* \param parameters Tuple of parameters to use in this parameterization
*/
template<typename... Args>
RichardsParameterization (const std::string name,
Richards (const std::string name,
const std::tuple<Args...> parameters) :
_theta_r(std::get<ResidualWaterContent>(parameters)),
_theta_s(std::get<SaturatedWaterContent>(parameters)),
_k0(std::get<SaturatedConductivity>(parameters)),
_theta_r(std::get<ResidualWaterContentType>(parameters)),
_theta_s(std::get<SaturatedWaterContentType>(parameters)),
_k0(std::get<SaturatedConductivityType>(parameters)),
_name(name)
{ }
/// Default constructor (virtual).
virtual ~RichardsParameterization () = default;
virtual ~Richards () = default;
/// Return the name of this parameterization instance.
const std::string& get_name() const { return _name; }
......@@ -118,12 +119,12 @@ public:
/** \param scale_por Porosity scaling factor
* \return Function: Saturation -> Water content
*/
std::function<WaterContent(const Saturation)> water_content_f (
std::function<WaterContentType(const SaturationType)> water_content_f (
const RF& scale_por
) const
{
return [this, &scale_por](const Saturation sat) {
return WaterContent{
return [this, &scale_por](const SaturationType sat) {
return WaterContentType{
sat.value * (_theta_s.value - _theta_r.value + scale_por)
+ _theta_r.value
};
......@@ -133,13 +134,13 @@ public:
/// Return a bound version of the saturation function
/** \return Function: Matric Head -> Water content
*/
virtual std::function<Saturation(const MatricHead)> saturation_f () const
virtual std::function<SaturationType(const MatricHeadType)> saturation_f () const
= 0;
/// Return a bound version of the conductivity function
/** \return Function: Saturation -> Hydraulic conductivity
*/
virtual std::function<Conductivity(const Saturation)> conductivity_f ()
virtual std::function<ConductivityType(const SaturationType)> conductivity_f ()
const = 0;
/// Return a multimap referecing all parameters by their names.
......@@ -157,12 +158,13 @@ public:
/// Return a clone of this object
/** \return a unique pointer with a copy of this object.
*/
virtual std::unique_ptr<RichardsParameterization<Traits>> clone () const = 0;
virtual std::unique_ptr<Richards<Traits>> clone () const = 0;
};
} // namespace Dune
} // namespace Parameterization
} // namespace Dorie
} // namespace Dune
#endif // DUNE_DORIE_PARAM_RICHARDS_INTERFACE_HH
\ No newline at end of file
......@@ -9,6 +9,7 @@
namespace Dune {
namespace Dorie {
namespace Parameterization {
/// Representation of the Mualem–van Genuchten parameterization
/** Implements the following relations:
......@@ -23,22 +24,22 @@ namespace Dorie {
* \date 2018
*/
template <typename Traits>
class MualemVanGenuchtenParameterization :
public RichardsParameterization<Traits>
class MualemVanGenuchten :
public Richards<Traits>
{
private:
using RF = typename Traits::RF;
using Base = RichardsParameterization<Traits>;
using Base = Richards<Traits>;
public:
using Saturation = typename Base::Saturation;
using Conductivity = typename Base::Conductivity;
using MatricHead = typename Base::MatricHead;
using SaturatedConductivity = typename Base::SaturatedConductivity;
using SaturationType = typename Base::SaturationType;
using ConductivityType = typename Base::ConductivityType;
using MatricHeadType = typename Base::MatricHeadType;
using SaturatedConductivityType = typename Base::SaturatedConductivityType;
using ResidualWaterContent = typename Base::ResidualWaterContent;
using SaturatedWaterContent = typename Base::SaturatedWaterContent;
using ResidualWaterContentType = typename Base::ResidualWaterContentType;
using SaturatedWaterContentType = typename Base::SaturatedWaterContentType;
/// Parameter defining the value of alpha (air-entry value)
struct Alpha
......@@ -73,8 +74,8 @@ public:
/// Construct with default-initialized parameters
/** \param name The name associated with this soil layer
*/
MualemVanGenuchtenParameterization (const std::string name) :
RichardsParameterization<Traits>(name)
MualemVanGenuchten (const std::string name) :
Richards<Traits>(name)
{ }
/// Construct from a tuple of parameters
......@@ -82,27 +83,27 @@ public:
* \param parameters Tuple of parameters to use in this parameterization
*/
template<typename... Args>
MualemVanGenuchtenParameterization (
MualemVanGenuchten (
const std::string name,
const std::tuple<Args...> parameters) :
RichardsParameterization<Traits>(name, parameters),
Richards<Traits>(name, parameters),
_alpha(std::get<Alpha>(parameters)),
_tau(std::get<Tau>(parameters)),
_n(std::get<N>(parameters))
{ }
/// Add default destructor to clarify override
~MualemVanGenuchtenParameterization () override = default;
~MualemVanGenuchten () override = default;
/// Return a scaled conductivity function
/** Saturation -> Conductivity
*/
std::function<Conductivity(const Saturation)> conductivity_f () const
std::function<ConductivityType(const SaturationType)> conductivity_f () const
override
{
const auto m = 1.0 - 1.0 / _n.value;
return [this, m](const Saturation sat) {
return Conductivity {
return [this, m](const SaturationType sat) {
return ConductivityType {
this->_k0.value
* std::pow(sat.value, _tau.value)
* std::pow(1 - std::pow(1 - std::pow(sat.value, 1.0/m), m), 2)
......@@ -113,15 +114,15 @@ public:
/// Return a scaled saturation function
/** Matric head -> Saturation
*/
std::function<Saturation(const MatricHead)> saturation_f () const
std::function<SaturationType(const MatricHeadType)> saturation_f () const
override
{
const auto m = 1.0 - 1.0 / _n.value;
return [this, m](const MatricHead head) {
return [this, m](const MatricHeadType head) {
if (head.value >= 0.0) {
return Saturation{1.0};
return SaturationType{1.0};
}
return Saturation {
return SaturationType {
std::pow(1 + std::pow(_alpha.value * head.value, _n.value), -m)
};
};
......@@ -133,9 +134,9 @@ public:
std::multimap<std::string, double&> parameters () override
{
return {
{ResidualWaterContent::name, this->_theta_r.value},
{SaturatedWaterContent::name, this->_theta_s.value},
{SaturatedConductivity::name, this->_k0.value},
{ResidualWaterContentType::name, this->_theta_r.value},
{SaturatedWaterContentType::name, this->_theta_s.value},
{SaturatedConductivityType::name, this->_k0.value},
{Alpha::name, _alpha.value},
{Tau::name, _tau.value},
{N::name, _n.value}
......@@ -148,23 +149,24 @@ public:
std::multimap<std::string, const double&> parameters () const override
{
return {
{ResidualWaterContent::name, this->_theta_r.value},
{SaturatedWaterContent::name, this->_theta_s.value},
{SaturatedConductivity::name, this->_k0.value},
{ResidualWaterContentType::name, this->_theta_r.value},
{SaturatedWaterContentType::name, this->_theta_s.value},
{SaturatedConductivityType::name, this->_k0.value},
{Alpha::name, _alpha.value},
{Tau::name, _tau.value},
{N::name, _n.value}
};
}
std::unique_ptr<RichardsParameterization<Traits>> clone () const override
std::unique_ptr<Richards<Traits>> clone () const override
{
using ThisType = MualemVanGenuchtenParameterization<Traits>;
using ThisType = MualemVanGenuchten<Traits>;
return std::make_unique<ThisType>(*this);
}
};
} // namespace Dune
} // namespace Parameterization
} // namespace Dorie
} // namespace Dune
#endif // DUNE_DORIE_PARAM_MVG_HH
......@@ -16,6 +16,7 @@
namespace Dune {
namespace Dorie {
namespace Parameterization {
/// Define scaling factors used for any scaling type.
/** The variables are initialized to their default values
......@@ -252,7 +253,7 @@ public:
}
};
} // namespace Parameterization
} // namespace Dorie
} // namespace Dune
......
......@@ -44,7 +44,7 @@ void test_scaled_parameterization (FlowParameters& param_scaled,
param_unscaled.bind(cell);
// retrieve actual scaling
using Scale = Dune::Dorie::ScalingFactors<Traits<2>::RF>;
using Scale = Dune::Dorie::Parameterization::ScalingFactors<Traits<2>::RF>;
auto scale = std::get<Scale>(param_scaled.cache());
// check results of scaled functions
......
......@@ -74,7 +74,7 @@ void test_new_parameters (const FlowParameters& fparam,
{
// bind parameterization to cell and fetch parameters
fparam.bind(cell);
using RP = Dune::Dorie::RichardsParameterization<Traits<2>>;
using RP = Dune::Dorie::Parameterization::Richards<Traits<2>>;
auto par = std::get<std::shared_ptr<const RP>>(fparam.cache());
auto parameters = par->parameters();
......@@ -116,14 +116,14 @@ void test_parameter_manipulation (FlowParameters& fparam,
fparam.bind(cell);
// manipulate via returned map (this is the preferred way)
using RP = Dune::Dorie::RichardsParameterization<Traits<2>>;
using RP = Dune::Dorie::Parameterization::Richards<Traits<2>>;
auto par = std::get<std::shared_ptr<RP>>(fparam.cache());
auto parameters = par->parameters();
parameters.find("theta_r")->second = 0.0;
assert(par->_theta_r.value == 0.0);
// manipulate directly via casting (this is not recommended)
using MvG = Dune::Dorie::MualemVanGenuchtenParameterization<Traits<2>>;
using MvG = Dune::Dorie::Parameterization::MualemVanGenuchten<Traits<2>>;
auto& par_mvg = dynamic_cast<MvG&>(*par);
parameters.find("alpha")->second = -10.0;
assert(par_mvg._alpha.value = -10.0);
......@@ -141,7 +141,7 @@ bool compare_parameters (const FlowParameters& fparam1,
// bind parameterization to cell and fetch parameters
fparam1.bind(cell);
fparam2.bind(cell);
using RP = Dune::Dorie::RichardsParameterization<Traits<2>>;
using RP = Dune::Dorie::Parameterization::Richards<Traits<2>>;
auto par1 = std::get<std::shared_ptr<const RP>>(fparam1.cache());
auto par2 = std::get<std::shared_ptr<const RP>>(fparam2.cache());
auto parameters1 = par1->parameters();
......
......@@ -23,8 +23,8 @@
/// Compare two scaling factor structs
template<typename T>
std::enable_if_t<std::is_arithmetic_v<T>, bool> operator==
(const Dune::Dorie::ScalingFactors<T>& a,
const Dune::Dorie::ScalingFactors<T>& b)
(const Dune::Dorie::Parameterization::ScalingFactors<T>& a,
const Dune::Dorie::Parameterization::ScalingFactors<T>& b)
{
if (a.scale_cond == b.scale_cond
and a.scale_head == b. scale_head
......@@ -56,7 +56,7 @@ void test_scaling_setting (const YAML::Node& cfg,
{
// create the scaling
const auto type = cfg["type"].as<std::string>();
using SAF = Dune::Dorie::ScalingAdapterFactory<Traits<dim>>;
using SAF = Dune::Dorie::Parameterization::ScalingAdapterFactory<Traits<dim>>;
const auto log = Dune::Dorie::get_logger(Dune::Dorie::log_base);
auto scaling = SAF::create(type, cfg["data"], grid_view, log);
......@@ -77,7 +77,7 @@ void evaluate_scaling (const std::string& type,
const std::vector<Domain>& positions)
{
// create reference scaling
using Scaling = Dune::Dorie::ScalingFactors<double>;
using Scaling = Dune::Dorie::Parameterization::ScalingFactors<double>;
Scaling reference;
if (type == "none") {
reference = Scaling{1.0, 1.0, 0.0};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment