[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 @@ ...@@ -5,7 +5,7 @@
#include <functional> #include <functional>
#include <string> #include <string>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/interface.hh> #include <dune/dorie/model/transport/parameterization/interface.hh>
namespace Dune { namespace Dune {
namespace Dorie { namespace Dorie {
...@@ -13,11 +13,11 @@ namespace Parameterization { ...@@ -13,11 +13,11 @@ namespace Parameterization {
template <class Traits> template <class Traits>
class ConstHydrodynamicDispersion : class ConstHydrodynamicDispersion :
public HydrodynamicDispersion<Traits> public Transport<Traits>
{ {
private: private:
using Tensor = typename Traits::Tensor; using Tensor = typename Traits::Tensor;
using Base = HydrodynamicDispersion<Traits>; using Base = Transport<Traits>;
public: public:
using HydrodynamicDispersionType = typename Base::HydrodynamicDispersionType; using HydrodynamicDispersionType = typename Base::HydrodynamicDispersionType;
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
ConstHydrodynamicDispersionType _const_hydrodynamic_dispersion; ConstHydrodynamicDispersionType _const_hydrodynamic_dispersion;
ConstHydrodynamicDispersion (const std::string name) : ConstHydrodynamicDispersion (const std::string name) :
HydrodynamicDispersion<Traits>(name) Transport<Traits>(name)
{ } { }
template<typename... Args> template<typename... Args>
...@@ -60,62 +60,85 @@ public: ...@@ -60,62 +60,85 @@ public:
}; };
} }
std::multimap<std::string, double&> parameters () override 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) if constexpr (Traits::dim == 2)
return { new_param = Map({
{_const_hydrodynamic_dispersion_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]}, {_const_type_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]}, {_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_hydrodynamic_dispersion_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]}, {_const_type_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_hydrodynamic_dispersion_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]} {_const_type_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]}
}; });
else if constexpr (Traits::dim == 3) else if constexpr (Traits::dim == 3)
return { new_param = Map({
{_const_hydrodynamic_dispersion_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]}, {_const_type_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]}, {_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_hydrodynamic_dispersion_name+"_xz", _const_hydrodynamic_dispersion.value[2][0]}, {_const_type_name+"_xz", _const_hydrodynamic_dispersion.value[2][0]},
{_const_hydrodynamic_dispersion_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]}, {_const_type_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_hydrodynamic_dispersion_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]}, {_const_type_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]},
{_const_hydrodynamic_dispersion_name+"_yz", _const_hydrodynamic_dispersion.value[2][1]}, {_const_type_name+"_yz", _const_hydrodynamic_dispersion.value[2][1]},
{_const_hydrodynamic_dispersion_name+"_zx", _const_hydrodynamic_dispersion.value[0][2]}, {_const_type_name+"_zx", _const_hydrodynamic_dispersion.value[0][2]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][2]}, {_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][2]},
{_const_hydrodynamic_dispersion_name+"_zz", _const_hydrodynamic_dispersion.value[2][2]} {_const_type_name+"_zz", _const_hydrodynamic_dispersion.value[2][2]}
}; });
else else
static_assert(true, static_assert(true,
"ConstHydrodynamicDispersion not available for this dimension"); "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 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) if constexpr (Traits::dim == 2)
return { new_param = Map({
{_const_hydrodynamic_dispersion_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]}, {_const_type_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]}, {_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_hydrodynamic_dispersion_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]}, {_const_type_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_hydrodynamic_dispersion_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]} {_const_type_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]}
}; });
else if constexpr (Traits::dim == 3) else if constexpr (Traits::dim == 3)
return { new_param = Map({
{_const_hydrodynamic_dispersion_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]}, {_const_type_name+"_xx", _const_hydrodynamic_dispersion.value[0][0]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]}, {_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][0]},
{_const_hydrodynamic_dispersion_name+"_xz", _const_hydrodynamic_dispersion.value[2][0]}, {_const_type_name+"_xz", _const_hydrodynamic_dispersion.value[2][0]},
{_const_hydrodynamic_dispersion_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]}, {_const_type_name+"_yx", _const_hydrodynamic_dispersion.value[0][1]},
{_const_hydrodynamic_dispersion_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]}, {_const_type_name+"_yy", _const_hydrodynamic_dispersion.value[1][1]},
{_const_hydrodynamic_dispersion_name+"_yz", _const_hydrodynamic_dispersion.value[2][1]}, {_const_type_name+"_yz", _const_hydrodynamic_dispersion.value[2][1]},
{_const_hydrodynamic_dispersion_name+"_zx", _const_hydrodynamic_dispersion.value[0][2]}, {_const_type_name+"_zx", _const_hydrodynamic_dispersion.value[0][2]},
{_const_hydrodynamic_dispersion_name+"_xy", _const_hydrodynamic_dispersion.value[1][2]}, {_const_type_name+"_xy", _const_hydrodynamic_dispersion.value[1][2]},
{_const_hydrodynamic_dispersion_name+"_zz", _const_hydrodynamic_dispersion.value[2][2]} {_const_type_name+"_zz", _const_hydrodynamic_dispersion.value[2][2]}
}; });
else else
static_assert(true, static_assert(true,
"ConstHydrodynamicDispersion not available for this dimension"); "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>; using ThisType = ConstHydrodynamicDispersion<Traits>;
return std::make_unique<ThisType>(*this); return std::make_unique<ThisType>(*this);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <string> #include <string>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/interface.hh> #include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/interface.hh>
#include <dune/dorie/model/transport/parameterization/peclet.hh>
namespace Dune { namespace Dune {
namespace Dorie { namespace Dorie {
...@@ -14,11 +13,11 @@ namespace Parameterization { ...@@ -14,11 +13,11 @@ namespace Parameterization {
template <class Traits> template <class Traits>
class PowerLawDispersion : class PowerLawDispersion :
public HydrodynamicDispersion<Traits> public Transport<Traits>
{ {
private: private:
using RangeField = typename Traits::RF; using RangeField = typename Traits::RF;
using Base = HydrodynamicDispersion<Traits>; using Base = Transport<Traits>;
public: public:
using HydrodynamicDispersionType = typename Base::HydrodynamicDispersionType; using HydrodynamicDispersionType = typename Base::HydrodynamicDispersionType;
...@@ -42,12 +41,9 @@ public: ...@@ -42,12 +41,9 @@ public:
GammaType _gamma; GammaType _gamma;
AlphaType _alpha; AlphaType _alpha;
std::shared_ptr<Peclet<Traits>> _peclet_ptr;
PowerLawDispersion (const std::string name, PowerLawDispersion (const std::string name) :
std::shared_ptr<Peclet<Traits>> peclet) : Base(name)
Base(name),
_peclet_ptr(peclet)
{ } { }
template<typename... Args> template<typename... Args>
...@@ -56,8 +52,7 @@ public: ...@@ -56,8 +52,7 @@ public:
const std::tuple<Args...> parameters) : const std::tuple<Args...> parameters) :
Base(name, parameters), Base(name, parameters),
_gamma(std::get<GammaType>(parameters)), _gamma(std::get<GammaType>(parameters)),
_alpha(std::get<AlphaType>(parameters)), _alpha(std::get<AlphaType>(parameters))
_peclet_ptr(std::make_shared<Peclet<Traits>>(name,parameters))
{ } { }
virtual ~PowerLawDispersion () override {} virtual ~PowerLawDispersion () override {}
...@@ -68,7 +63,7 @@ public: ...@@ -68,7 +63,7 @@ public:
hydrodynamic_dispersion_f () const override hydrodynamic_dispersion_f () const override
{ {
return [this](const WaterFluxType water_flux, const WaterContentType water_content) { 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.}; HydrodynamicDispersionType eff_hdr_disp{0.};
for (int i = 0; i < Traits::dim; ++i) for (int i = 0; i < Traits::dim; ++i)
eff_hdr_disp.value[i][i] = val; eff_hdr_disp.value[i][i] = val;
...@@ -76,23 +71,38 @@ public: ...@@ -76,23 +71,38 @@ public:
}; };
} }
std::multimap<std::string, double&> parameters () override std::multimap<std::string, double&> parameters () override
{ {
return { using Map = std::multimap<std::string, double&>;
{AlphaType::name, _alpha.value},
{GammaType::name, _gamma.value} 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 std::multimap<std::string, const double&> parameters () const override
{ {
return { using Map = std::multimap<std::string, const double&>;
{AlphaType::name, _alpha.value},
{GammaType::name, _gamma.value} 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>; using ThisType = PowerLawDispersion<Traits>;
return std::make_unique<ThisType>(*this); return std::make_unique<ThisType>(*this);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <functional> #include <functional>
#include <string> #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_hydromechanic_dispersion/interface.hh>
#include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/eff_diffusion/interface.hh> #include <dune/dorie/model/transport/parameterization/hydrodynamic_dispersion/eff_diffusion/interface.hh>
...@@ -16,11 +16,11 @@ namespace Parameterization { ...@@ -16,11 +16,11 @@ namespace Parameterization {
template <class Traits> template <class Traits>
class HydrodynamicDispersionSuperposition : class HydrodynamicDispersionSuperposition :
public HydrodynamicDispersion<Traits> public Transport<Traits>
{ {
private: private:
using RangeField = typename Traits::RF; using RangeField = typename Traits::RF;
using Base = HydrodynamicDispersion<Traits>; using Base = Transport<Traits>;
static constexpr int dim = Traits::dim; static constexpr int dim = Traits::dim;
public: public:
...@@ -36,11 +36,11 @@ public: ...@@ -36,11 +36,11 @@ public:
std::shared_ptr<EffectiveHydromechanicDispersion<Traits>> eff_hyrm_disp std::shared_ptr<EffectiveHydromechanicDispersion<Traits>> eff_hyrm_disp
) : Base(name), ) : Base(name),
_eff_diff(eff_diff), _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<EffectiveDiffusion<Traits>> _eff_diff;
std::shared_ptr<EffectiveHydromechanicDispersion<Traits>> _eff_hyrm_disp; std::shared_ptr<EffectiveHydromechanicDispersion<Traits>> _eff_hm_disp;
~HydrodynamicDispersionSuperposition () override {}; ~HydrodynamicDispersionSuperposition () override {};
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
{ {
return [this](const WaterFluxType water_flux, const WaterContentType water_content) { return [this](const WaterFluxType water_flux, const WaterContentType water_content) {
auto eff_diff = _eff_diff->effective_diffusion_f()(water_flux,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) for (int i = 0; i < dim; ++i)
eff_hyrm_disp.value[i][i]+=eff_diff.value; eff_hyrm_disp.value[i][i]+=eff_diff.value;
return HydrodynamicDispersionType{eff_hyrm_disp.value}; return HydrodynamicDispersionType{eff_hyrm_disp.value};
...@@ -60,10 +60,12 @@ public: ...@@ -60,10 +60,12 @@ public:
std::multimap<std::string, double&> parameters () override 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(); 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()); compsite_map.insert(eff_diff_param.begin(),eff_diff_param.end());
return compsite_map; return compsite_map;
...@@ -71,7 +73,8 @@ public: ...@@ -71,7 +73,8 @@ public:
std::multimap<std::string, const double&> parameters () const override 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(); auto eff_diff_param = _eff_diff->parameters();
std::multimap<std::string, const double&> compsite_map; std::multimap<std::string, const double&> compsite_map;
...@@ -81,10 +84,10 @@ public: ...@@ -81,10 +84,10 @@ public:
return compsite_map; return compsite_map;
} }
std::unique_ptr<HydrodynamicDispersion<Traits>> clone () const override std::unique_ptr<Transport<Traits>> clone () const override
{ {
using ThisType = HydrodynamicDispersionSuperposition<Traits>; 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 { ...@@ -9,8 +9,6 @@ namespace Dune {
namespace Dorie { namespace Dorie {
namespace Parameterization { namespace Parameterization {
template<class Traits>
class Peclet;
template<class Traits> template<class Traits>
class HydrodynamicDispersion; class HydrodynamicDispersion;
...@@ -49,17 +47,33 @@ public: ...@@ -49,17 +47,33 @@ public:
RangeField value; RangeField value;
}; };
Transport (const std::string name, struct CharacteristicLengthType
std::shared_ptr<Peclet<Traits>> peclet, {
std::shared_ptr<HydrodynamicDispersion<Traits>> hyrd_disp CharacteristicLengthType() {}
) : _peclet(peclet), RangeField value;
_hyrd_disp(hyrd_disp), inline static const std::string name = "char_length";
_name(name) };
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; template<typename... Args>
std::shared_ptr<HydrodynamicDispersion<Traits>> _hyrd_disp; 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; virtual ~Transport () = default;
...@@ -67,17 +81,16 @@ public: ...@@ -67,17 +81,16 @@ public:
virtual std::function< virtual std::function<
HydrodynamicDispersionType(const WaterFluxType water_flux, const WaterContentType water_content)> HydrodynamicDispersionType(const WaterFluxType water_flux, const WaterContentType water_content)>
hydrodynamic_dispersion_f () const hydrodynamic_dispersion_f () const = 0;
{
return _hyrd_disp->hydrodynamic_dispersion_f();
};
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 a map referecing all parameters by their names.
/** \return Map. Key: Name of parameter (string). /** \return Map. Key: Name of parameter (string).
...@@ -85,36 +98,25 @@ public: ...@@ -85,36 +98,25 @@ public:
*/ */
virtual std::multimap<std::string, double&> parameters () virtual std::multimap<std::string, double&> parameters ()
{ {
auto hydrd_disp_param = _hyrd_disp->parameters(); return {
auto peclet_param = _peclet->parameters(); {_char_length.name, _char_length.value},
{_mol_diff.name, _mol_diff.value}
std::multimap<std::string, double&> compsite_map(hydrd_disp_param); };
compsite_map.insert(peclet_param.begin(),peclet_param.end()); }
return compsite_map;
};
/// Return a map referecing all parameters by their names. /// Return a map referecing all parameters by their names.
/** \return Map. Key: Name of parameter (string). /** \return Map. Key: Name of parameter (string).
* Value: Value of parameter (const double&) * Value: Value of parameter (const double&)
*/ */
virtual std::multimap<std::string, const double&> parameters () const virtual std::multimap<std::string, const double&> parameters () const
{ {
auto hydrd_disp_param = _hyrd_disp->parameters(); return {
auto peclet_param = _peclet->parameters(); {_char_length.name, _char_length.value},
{_mol_diff.name, _mol_diff.value}
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 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: private:
const std::string _name; const std::string _name;
};