[Transport] Move peclet class to the interface class

* This is necessary in order to keep all the parameters available through the method parameters() when cloning. In particular the clone() method of PowerLaw class was creating a deep copy of the Peclet class different to the one accessible via the Transport interface class.
parent 6743e622
......@@ -5,7 +5,7 @@
#include <functional>
#include <string>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/interface.hh>
#include <dune/dorie/model/transport/parameterization/interface.hh>
namespace Dune {
namespace Dorie {
......@@ -13,11 +13,11 @@ namespace Parameterization {
template <class Traits>
class ConstHydrodynamicDispersion :
public HydrodynamicDispersion<Traits>
public Transport<Traits>
{
private:
using Tensor = typename Traits::Tensor;
using Base = HydrodynamicDispersion<Traits>;
using Base = Transport<Traits>;
public:
using HydrodynamicDispersionType = typename Base::HydrodynamicDispersionType;
......@@ -36,7 +36,7 @@ public:
ConstHydrodynamicDispersionType _const_hydrodynamic_dispersion;
ConstHydrodynamicDispersion (const std::string name) :
HydrodynamicDispersion<Traits>(name)
Transport<Traits>(name)
{ }
template<typename... Args>
......@@ -60,62 +60,85 @@ public:
};
}
std::multimap<std::string, double&> parameters () override
{
const std::string _const_hydrodynamic_dispersion_name = ConstHydrodynamicDispersionType::name;
using Map = std::multimap<std::string, double&>;
Map base_param = Transport<Traits>::parameters();
Map new_param;
Map compsite_map;
auto _const_type_name = ConstHydrodynamicDispersionType::name;
if constexpr (Traits::dim == 2)
return {
{_const_hydrodynamic_dispersion_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_hydrodynamic_dispersion_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_hydrodynamic_dispersion_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]}
};
new_param = Map({
{_const_type_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_type_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_type_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]}
});
else if constexpr (Traits::dim == 3)
return {
{_const_hydrodynamic_dispersion_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_hydrodynamic_dispersion_name+"_xz", _const_hydrodynamic_dispersion.value[2][0]},
{_const_hydrodynamic_dispersion_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_hydrodynamic_dispersion_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]},
{_const_hydrodynamic_dispersion_name+"_yz", _const_hydrodynamic_dispersion.value[2][1]},
{_const_hydrodynamic_dispersion_name+"_zx", _const_hydrodynamic_dispersion.value[0][2]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][2]},
{_const_hydrodynamic_dispersion_name+"_zz", _const_hydrodynamic_dispersion.value[2][2]}
};
new_param = Map({
{_const_type_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_type_name+"_xz", _const_hydrodynamic_dispersion.value[2][0]},
{_const_type_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_type_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]},
{_const_type_name+"_yz", _const_hydrodynamic_dispersion.value[2][1]},
{_const_type_name+"_zx", _const_hydrodynamic_dispersion.value[0][2]},
{_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][2]},
{_const_type_name+"_zz", _const_hydrodynamic_dispersion.value[2][2]}
});
else
static_assert(true,
"ConstHydrodynamicDispersion not available for this dimension");
compsite_map.insert(base_param.begin(),base_param.end());
compsite_map.insert(new_param.begin(),new_param.end());
return compsite_map;
}
std::multimap<std::string, const double&> parameters () const override
{
const std::string _const_hydrodynamic_dispersion_name = ConstHydrodynamicDispersionType::name;
using Map = std::multimap<std::string, const double&>;
Map base_param = Transport<Traits>::parameters();
Map new_param;
Map compsite_map;
auto _const_type_name = ConstHydrodynamicDispersionType::name;
if constexpr (Traits::dim == 2)
return {
{_const_hydrodynamic_dispersion_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_hydrodynamic_dispersion_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_hydrodynamic_dispersion_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]}
};
new_param = Map({
{_const_type_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_type_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_type_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]}
});
else if constexpr (Traits::dim == 3)
return {
{_const_hydrodynamic_dispersion_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_hydrodynamic_dispersion_name+"_xz", _const_hydrodynamic_dispersion.value[2][0]},
{_const_hydrodynamic_dispersion_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_hydrodynamic_dispersion_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]},
{_const_hydrodynamic_dispersion_name+"_yz", _const_hydrodynamic_dispersion.value[2][1]},
{_const_hydrodynamic_dispersion_name+"_zx", _const_hydrodynamic_dispersion.value[0][2]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][2]},
{_const_hydrodynamic_dispersion_name+"_zz", _const_hydrodynamic_dispersion.value[2][2]}
};
new_param = Map({
{_const_type_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_type_name+"_xz", _const_hydrodynamic_dispersion.value[2][0]},
{_const_type_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_type_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]},
{_const_type_name+"_yz", _const_hydrodynamic_dispersion.value[2][1]},
{_const_type_name+"_zx", _const_hydrodynamic_dispersion.value[0][2]},
{_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][2]},
{_const_type_name+"_zz", _const_hydrodynamic_dispersion.value[2][2]}
});
else
static_assert(true,
"ConstHydrodynamicDispersion not available for this dimension");
compsite_map.insert(base_param.begin(),base_param.end());
compsite_map.insert(new_param.begin(),new_param.end());
return compsite_map;
}
std::unique_ptr<HydrodynamicDispersion<Traits>> clone () const override
std::unique_ptr<Transport<Traits>> clone () const override
{
using ThisType = ConstHydrodynamicDispersion<Traits>;
return std::make_unique<ThisType>(*this);
......
......@@ -6,7 +6,6 @@
#include <string>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/interface.hh>
#include <dune/dorie/model/transport/parameterization/peclet.hh>
namespace Dune {
namespace Dorie {
......@@ -14,11 +13,11 @@ namespace Parameterization {
template <class Traits>
class PowerLawDispersion :
public HydrodynamicDispersion<Traits>
public Transport<Traits>
{
private:
using RangeField = typename Traits::RF;
using Base = HydrodynamicDispersion<Traits>;
using Base = Transport<Traits>;
public:
using HydrodynamicDispersionType = typename Base::HydrodynamicDispersionType;
......@@ -42,12 +41,9 @@ public:
GammaType _gamma;
AlphaType _alpha;
std::shared_ptr<Peclet<Traits>> _peclet_ptr;
PowerLawDispersion (const std::string name,
std::shared_ptr<Peclet<Traits>> peclet) :
Base(name),
_peclet_ptr(peclet)
PowerLawDispersion (const std::string name) :
Base(name)
{ }
template<typename... Args>
......@@ -56,8 +52,7 @@ public:
const std::tuple<Args...> parameters) :
Base(name, parameters),
_gamma(std::get<GammaType>(parameters)),
_alpha(std::get<AlphaType>(parameters)),
_peclet_ptr(std::make_shared<Peclet<Traits>>(name,parameters))
_alpha(std::get<AlphaType>(parameters))
{ }
virtual ~PowerLawDispersion () override {}
......@@ -68,7 +63,7 @@ public:
hydrodynamic_dispersion_f () const override
{
return [this](const WaterFluxType water_flux, const WaterContentType water_content) {
auto val = _gamma.value*std::pow(_peclet_ptr->peclet_f()(water_flux,water_content).value,_alpha.value);
auto val = _gamma.value*std::pow(this->peclet_f()(water_flux,water_content).value,_alpha.value);
HydrodynamicDispersionType eff_hdr_disp{0.};
for (int i = 0; i < Traits::dim; ++i)
eff_hdr_disp.value[i][i] = val;
......@@ -76,23 +71,38 @@ public:
};
}
std::multimap<std::string, double&> parameters () override
{
return {
{AlphaType::name, _alpha.value},
{GammaType::name, _gamma.value}
};
using Map = std::multimap<std::string, double&>;
Map base_param = Transport<Traits>::parameters();
Map new_param({{AlphaType::name, _alpha.value},
{GammaType::name, _gamma.value}});
Map compsite_map;
compsite_map.insert(base_param.begin(),base_param.end());
compsite_map.insert(new_param.begin(),new_param.end());
return compsite_map;
}
std::multimap<std::string, const double&> parameters () const override
{
return {
{AlphaType::name, _alpha.value},
{GammaType::name, _gamma.value}
};
using Map = std::multimap<std::string, const double&>;
Map base_param = Transport<Traits>::parameters();
Map new_param({{AlphaType::name, _alpha.value},
{GammaType::name, _gamma.value}});
Map compsite_map;
compsite_map.insert(base_param.begin(),base_param.end());
compsite_map.insert(new_param.begin(),new_param.end());
return compsite_map;
}
std::unique_ptr<HydrodynamicDispersion<Traits>> clone () const override
std::unique_ptr<Transport<Traits>> clone () const override
{
using ThisType = PowerLawDispersion<Traits>;
return std::make_unique<ThisType>(*this);
......
......@@ -5,7 +5,7 @@
#include <functional>
#include <string>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/interface.hh>
#include <dune/dorie/model/transport/parameterization/interface.hh>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/eff_hydromechanic_dispersion/interface.hh>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/eff_diffusion/interface.hh>
......@@ -16,11 +16,11 @@ namespace Parameterization {
template <class Traits>
class HydrodynamicDispersionSuperposition :
public HydrodynamicDispersion<Traits>
public Transport<Traits>
{
private:
using RangeField = typename Traits::RF;
using Base = HydrodynamicDispersion<Traits>;
using Base = Transport<Traits>;
static constexpr int dim = Traits::dim;
public:
......@@ -36,11 +36,11 @@ public:
std::shared_ptr<EffectiveHydromechanicDispersion<Traits>> eff_hyrm_disp
) : Base(name),
_eff_diff(eff_diff),
_eff_hyrm_disp(eff_hyrm_disp)
_eff_hm_disp(eff_hyrm_disp)
{ }
std::shared_ptr<EffectiveDiffusion<Traits>> _eff_diff;
std::shared_ptr<EffectiveHydromechanicDispersion<Traits>> _eff_hyrm_disp;
std::shared_ptr<EffectiveHydromechanicDispersion<Traits>> _eff_hm_disp;
~HydrodynamicDispersionSuperposition () override {};
......@@ -51,7 +51,7 @@ public:
{
return [this](const WaterFluxType water_flux, const WaterContentType water_content) {
auto eff_diff = _eff_diff->effective_diffusion_f()(water_flux,water_content);
auto eff_hyrm_disp = _eff_hyrm_disp->effective_hydromechanic_dispersion_f()(water_flux,water_content);
auto eff_hyrm_disp = _eff_hm_disp->effective_hydromechanic_dispersion_f()(water_flux,water_content);
for (int i = 0; i < dim; ++i)
eff_hyrm_disp.value[i][i]+=eff_diff.value;
return HydrodynamicDispersionType{eff_hyrm_disp.value};
......@@ -60,10 +60,12 @@ public:
std::multimap<std::string, double&> parameters () override
{
auto eff_hydr_disp_param = _eff_hyrm_disp->parameters();
auto base_param = Transport<Traits>::parameters();
auto eff_hydr_disp_param = _eff_hm_disp->parameters();
auto eff_diff_param = _eff_diff->parameters();
std::multimap<std::string, double&> compsite_map(eff_hydr_disp_param);
std::multimap<std::string, double&> compsite_map;
compsite_map.insert(eff_hydr_disp_param.begin(),eff_hydr_disp_param.end());
compsite_map.insert(eff_diff_param.begin(),eff_diff_param.end());
return compsite_map;
......@@ -71,7 +73,8 @@ public:
std::multimap<std::string, const double&> parameters () const override
{
auto eff_hydr_disp_param = _eff_hyrm_disp->parameters();
auto base_param = Transport<Traits>::parameters();
auto eff_hydr_disp_param = _eff_hm_disp->parameters();
auto eff_diff_param = _eff_diff->parameters();
std::multimap<std::string, const double&> compsite_map;
......@@ -81,10 +84,10 @@ public:
return compsite_map;
}
std::unique_ptr<HydrodynamicDispersion<Traits>> clone () const override
std::unique_ptr<Transport<Traits>> clone () const override
{
using ThisType = HydrodynamicDispersionSuperposition<Traits>;
return std::make_unique<ThisType>(this->get_name(),_eff_diff->clone(),_eff_hyrm_disp->clone());
return std::make_unique<ThisType>(this->get_name(),_eff_diff->clone(),_eff_hm_disp->clone());
}
};
......
......@@ -9,8 +9,6 @@ namespace Dune {
namespace Dorie {
namespace Parameterization {
template<class Traits>
class Peclet;
template<class Traits>
class HydrodynamicDispersion;
......@@ -49,17 +47,33 @@ public:
RangeField value;
};
Transport (const std::string name,
std::shared_ptr<Peclet<Traits>> peclet,
std::shared_ptr<HydrodynamicDispersion<Traits>> hyrd_disp
) : _peclet(peclet),
_hyrd_disp(hyrd_disp),
_name(name)
struct CharacteristicLengthType
{
CharacteristicLengthType() {}
RangeField value;
inline static const std::string name = "char_length";
};
struct MolecularDiffusionType
{
MolecularDiffusionType() {}
RangeField value;
inline static const std::string name = "mol_diff";
};
Transport (const std::string name) : _name(name)
{ }
std::shared_ptr<Peclet<Traits>> _peclet;
std::shared_ptr<HydrodynamicDispersion<Traits>> _hyrd_disp;
template<typename... Args>
Transport (
const std::string name,
const std::tuple<Args...> parameters) :
_char_length(std::get<CharacteristicLengthType>(parameters)),
_mol_diff(std::get<MolecularDiffusionType>(parameters))
{ }
CharacteristicLengthType _char_length;
MolecularDiffusionType _mol_diff;
virtual ~Transport () = default;
......@@ -67,17 +81,16 @@ public:
virtual std::function<
HydrodynamicDispersionType(const WaterFluxType water_flux, const WaterContentType water_content)>
hydrodynamic_dispersion_f () const
{
return _hyrd_disp->hydrodynamic_dispersion_f();
};
hydrodynamic_dispersion_f () const = 0;
virtual std::function<PecletType(const WaterFluxType, const WaterContentType)> peclet_f() const
std::function<
PecletType(const WaterFluxType, const WaterContentType)>
peclet_f () const
{
return _peclet->peclet_f();
};
return [this](const WaterFluxType water_flux, const WaterContentType water_content){
return PecletType{_char_length.value*water_flux.value.two_norm()/(_mol_diff.value*water_content.value)};
};
}
/// Return a map referecing all parameters by their names.
/** \return Map. Key: Name of parameter (string).
......@@ -85,36 +98,25 @@ public:
*/
virtual std::multimap<std::string, double&> parameters ()
{
auto hydrd_disp_param = _hyrd_disp->parameters();
auto peclet_param = _peclet->parameters();
std::multimap<std::string, double&> compsite_map(hydrd_disp_param);
compsite_map.insert(peclet_param.begin(),peclet_param.end());
return compsite_map;
};
return {
{_char_length.name, _char_length.value},
{_mol_diff.name, _mol_diff.value}
};
}
/// Return a map referecing all parameters by their names.
/** \return Map. Key: Name of parameter (string).
* Value: Value of parameter (const double&)
*/
virtual std::multimap<std::string, const double&> parameters () const
{
auto hydrd_disp_param = _hyrd_disp->parameters();
auto peclet_param = _peclet->parameters();
std::multimap<std::string, const double&> compsite_map;
compsite_map.insert(hydrd_disp_param.begin(),hydrd_disp_param.end());
compsite_map.insert(peclet_param.begin(),peclet_param.end());
return {
{_char_length.name, _char_length.value},
{_mol_diff.name, _mol_diff.value}
};
}
return compsite_map;
};
virtual std::unique_ptr<Transport<Traits>> clone () const = 0;
virtual std::unique_ptr<Transport<Traits>> clone () const
{
using ThisType = Transport<Traits>;
return std::make_unique<ThisType>(this->get_name(),_peclet->clone(),_hyrd_disp->clone());
}
private:
const std::string _name;
};
......
#ifndef DUNE_DORIE_PARAM_PECLET_INTERFACE_HH
#define DUNE_DORIE_PARAM_PECLET_INTERFACE_HH
#include <functional>
#include <string>
#include <map>
#include <dune/dorie/model/transport/parameterization/interface.hh>
namespace Dune {
namespace Dorie {
namespace Parameterization {
template <class Traits>
class Peclet
{
private:
using BaseP = Transport<Traits>;
using RangeField = typename Traits::RF;
using Scalar = typename Traits::Scalar;
using Vector = typename Traits::Vector;
using Tensor = typename Traits::Tensor;
public:
struct CharacteristicLengthType
{
CharacteristicLengthType() {}
RangeField value;
inline static const std::string name = "char_length";
};
struct MolecularDiffusionType
{
MolecularDiffusionType() {}
RangeField value;
inline static const std::string name = "mol_diff";
};
CharacteristicLengthType _char_length;
MolecularDiffusionType _mol_diff;
Peclet (const std::string name)
: _name(name)
{ }
template<typename... Args>
Peclet (const std::string name,
const std::tuple<Args...> parameters) :
_char_length(std::get<CharacteristicLengthType>(parameters)),
_mol_diff(std::get<MolecularDiffusionType>(parameters))
{ }
~Peclet () = default;
const std::string& get_name() const { return _name; }
using PecletType = typename BaseP::PecletType;
using WaterContentType = typename BaseP::WaterContentType;
using WaterFluxType = typename BaseP::WaterFluxType;
std::function<
PecletType(const WaterFluxType, const WaterContentType)>
peclet_f () const
{
return [this](const WaterFluxType water_flux, const WaterContentType water_content){
return PecletType{_char_length.value*water_flux.value.two_norm()/(_mol_diff.value*water_content.value)};
};
}
std::map<std::string, double&> parameters ()
{
return {
{CharacteristicLengthType::name, _char_length.value},
{MolecularDiffusionType::name, _mol_diff.value}
};
}
std::map<std::string, const double&> parameters () const
{
return {
{CharacteristicLengthType::name, _char_length.value},
{MolecularDiffusionType::name, _mol_diff.value}
};
}
std::unique_ptr<Peclet<Traits>> clone () const
{
using ThisType = Peclet<Traits>;
return std::make_unique<ThisType>(*this);
}
private:
const std::string _name;
};
} // namespace Parameterization
} // namespace Dune
} // namespace Dorie
#endif // DUNE_DORIE_PARAM_PECLET_INTERFACE_HH
\ No newline at end of file
......@@ -16,7 +16,6 @@
#include <dune/dorie/common/parameterization_factory.hh>
#include <dune/dorie/model/transport/parameterization/interface.hh>
#include <dune/dorie/model/transport/parameterization/peclet.hh>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/interface.hh>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/const.hh>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/power_law.hh>
......@@ -52,18 +51,14 @@ struct TransportParameterizationFactory
const YAML::Node& type_node,
const std::string name) const override
{
// peclet
std::shared_ptr<Parameterization::Peclet<Traits>> peclet;
peclet = std::make_shared<Parameterization::Peclet<Traits>>(name);
std::shared_ptr<Parameterization::HydrodynamicDispersion<Traits>> hd_dips;
std::shared_ptr<Parameterization::Transport<Traits>> hd_dips;
const auto type = type_node["type"].as<std::string>();
if (type == Parameterization::ConstHydrodynamicDispersion<Traits>::type) {
hd_dips = std::make_shared<Parameterization::ConstHydrodynamicDispersion<Traits>>(name);
} else if (type == Parameterization::PowerLawDispersion<Traits>::type) {
hd_dips = std::make_shared<Parameterization::PowerLawDispersion<Traits>>(name,peclet);
hd_dips = std::make_shared<Parameterization::PowerLawDispersion<Traits>>(name);
} else if (type == Parameterization::HydrodynamicDispersionSuperposition<Traits>::type) {
// Select type for effective diffusion
......@@ -123,7 +118,7 @@ struct TransportParameterizationFactory
} else {
DUNE_THROW(NotImplemented,"Invalid hydrodyn_disp" );
}
return std::make_shared<Dorie::Parameterization::Transport<Traits>>(name,peclet,hd_dips);
return hd_dips;