Commit 6dac85de authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#873 Parameter: init time dependency with dummy object when none.

parent fd077537
......@@ -208,6 +208,22 @@ namespace HappyHeart
const std::string& GetName() const;
private:
/*!
* \brief Constant accessor to the object which handles if relevant the time dependancy (computation of
* the time related factor, etc...).
*/
const TimeDependencyT<TypeT>& GetTimeDependency() const noexcept;
/*!
* \brief Non constant accessor to the object which handles if relevant the time dependancy
* (computation of the time related factor, etc...).
*/
TimeDependencyT<TypeT>& GetNonCstTimeDependency() noexcept;
private:
return_type ApplyTimeDependancyFactor(return_type value_without_time_factor) const;
......@@ -246,7 +262,10 @@ namespace HappyHeart
//! Mesh upon which the parameter is defined.
const GeometricMeshRegion& geometric_mesh_region_;
//!
/*!
* \brief Object which handles if relevant the time dependancy (computation of the time related factor,
* etc...).
*/
typename TimeDependencyT<TypeT>::unique_ptr time_dependency_ = nullptr;
};
......
......@@ -16,6 +16,63 @@ namespace HappyHeart
{
template
<
ParameterNS::Type TypeT,
template<ParameterNS::Type> class TimeDependencyT
>
struct InitNoTimeDependencyHelper
{
static void Perform(typename TimeDependencyT<TypeT>::unique_ptr& time_dependency);
};
template
<
ParameterNS::Type TypeT
>
struct InitNoTimeDependencyHelper<TypeT, ParameterNS::TimeDependencyNS::None>
{
static void Perform(typename ParameterNS::TimeDependencyNS::None<TypeT>::unique_ptr& time_dependency);
};
template
<
ParameterNS::Type TypeT,
template<ParameterNS::Type> class TimeDependencyT
>
void InitNoTimeDependencyHelper<TypeT, TimeDependencyT>
::Perform(typename TimeDependencyT<TypeT>::unique_ptr& time_dependency)
{
// Do nothing!
}
template
<
ParameterNS::Type TypeT
>
void InitNoTimeDependencyHelper<TypeT, ParameterNS::TimeDependencyNS::None>
::Perform(typename ParameterNS::TimeDependencyNS::None<TypeT>::unique_ptr& ptr)
{
ptr = std::make_unique<ParameterNS::TimeDependencyNS::None<TypeT>>();
}
template
<
ParameterNS::Type TypeT,
......@@ -26,7 +83,12 @@ namespace HappyHeart
const GeometricMeshRegion& geometric_mesh_region)
: name_(name),
geometric_mesh_region_(geometric_mesh_region)
{ }
{
// If there is a time dependency, it must be set up through SetTimeDependency() method.
// If not, I need an empty object for conveniency; let's define it here.
InitNoTimeDependencyHelper<TypeT, TimeDependencyT>::Perform(time_dependency_);
}
template
......@@ -70,7 +132,8 @@ namespace HappyHeart
using return_type = typename ParameterNS::Traits<TypeT>::return_type;
static return_type Perform(return_type);
static return_type Perform(return_type value_without_time_contribution,
const TimeDependencyT& time_dependency_object);
};
......@@ -83,7 +146,10 @@ namespace HappyHeart
using return_type = typename ParameterNS::Traits<TypeT>::return_type;
static return_type Perform(return_type);
static return_type Perform(return_type value_without_time_contribution,
const ParameterNS::TimeDependencyNS::None<TypeT>& unused);
};
......@@ -92,8 +158,10 @@ namespace HappyHeart
ParameterNS::Type TypeT,
class TimeDependencyT
>
typename ApplyTimeFactorHelper<TypeT, TimeDependencyT>::return_type ApplyTimeFactorHelper<TypeT, TimeDependencyT>
::Perform(return_type value_without_time_factor)
typename ApplyTimeFactorHelper<TypeT, TimeDependencyT>::return_type
ApplyTimeFactorHelper<TypeT, TimeDependencyT>
::Perform(return_type value_without_time_factor,
const TimeDependencyT& time_dependency_object)
{
std::cout << "Time factor should be applied here." << std::endl;
return value_without_time_factor;
......@@ -102,7 +170,9 @@ namespace HappyHeart
template<ParameterNS::Type TypeT>
typename ApplyTimeFactorHelper<TypeT, ParameterNS::TimeDependencyNS::None<TypeT>>::return_type
ApplyTimeFactorHelper<TypeT, ParameterNS::TimeDependencyNS::None<TypeT>>::Perform(return_type value_without_time_factor)
ApplyTimeFactorHelper<TypeT, ParameterNS::TimeDependencyNS::None<TypeT>>
::Perform(return_type value_without_time_factor,
const ParameterNS::TimeDependencyNS::None<TypeT>& unused)
{
std::cout << "No time factor to apply." << std::endl;
return value_without_time_factor;
......@@ -119,7 +189,8 @@ namespace HappyHeart
Parameter<TypeT, TimeDependencyT>
::ApplyTimeDependancyFactor(typename Parameter<TypeT, TimeDependencyT>::return_type value_without_time) const
{
return ApplyTimeFactorHelper<TypeT, TimeDependencyT<TypeT>>::Perform(value_without_time);
return ApplyTimeFactorHelper<TypeT, TimeDependencyT<TypeT>>::Perform(value_without_time,
GetTimeDependency());
}
......@@ -185,6 +256,29 @@ namespace HappyHeart
{
return geometric_mesh_region_;
}
template
<
ParameterNS::Type TypeT,
template<ParameterNS::Type> class TimeDependencyT
>
inline const TimeDependencyT<TypeT>& Parameter<TypeT, TimeDependencyT>::GetTimeDependency() const noexcept
{
assert(!(!time_dependency_));
return *time_dependency_;
}
template
<
ParameterNS::Type TypeT,
template<ParameterNS::Type> class TimeDependencyT
>
inline TimeDependencyT<TypeT>& Parameter<TypeT, TimeDependencyT>::GetNonCstTimeDependency() noexcept
{
return const_cast<TimeDependencyT<TypeT>&>(GetTimeDependency());
}
} // namespace HappyHeart
......
......@@ -70,7 +70,7 @@ namespace HappyHeart
* \param[in] function Functor which returns the time-dependent factor given the current time.
*/
explicit Base(const TimeManager& time_manager,
FunctorT&& functor);
FunctorT&& functor);
//! Destructor.
~Base() = default;
......
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