Commit 4e98061b authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#873 Parameter: flesh out the interface of TimeDependency template class.

parent d32bb775
......@@ -155,7 +155,7 @@ namespace HappyHeart
*
* \param[in] time_dependency Unique pointer to the time dependency object to set.
*/
void SetTimeDependency(typename TimeDependencyT::const_unique_ptr&& time_dependency);
void SetTimeDependency(typename TimeDependencyT::unique_ptr&& time_dependency);
/*!
......@@ -244,7 +244,7 @@ namespace HappyHeart
const GeometricMeshRegion& geometric_mesh_region_;
//!
typename TimeDependencyT::const_unique_ptr time_dependency_ = nullptr;
typename TimeDependencyT::unique_ptr time_dependency_ = nullptr;
};
......
......@@ -29,31 +29,30 @@ namespace HappyHeart
{ }
template
<
ParameterNS::Type TypeT,
class TimeDependencyT
>
void Parameter<TypeT, TimeDependencyT>
::SetTimeDependency(typename TimeDependencyT::const_unique_ptr&& time_dependency)
::SetTimeDependency(typename TimeDependencyT::unique_ptr&& time_dependency)
{
static_assert(!std::is_same<TimeDependencyT, ParameterNS::TimeDependencyNS::None>::value,
"Should not be called for Parameters without time dependency!");
assert(time_dependency_ == nullptr && "SHould be assigned only once!");
assert(time_dependency_ == nullptr && "Should be assigned only once!");
time_dependency_ = std::move(time_dependency);
}
template
<
ParameterNS::Type TypeT,
class TimeDependencyT
>
inline typename Parameter<TypeT, TimeDependencyT>::return_type Parameter<TypeT, TimeDependencyT>::GetConstantValue() const
inline typename Parameter<TypeT, TimeDependencyT>::return_type Parameter<TypeT, TimeDependencyT>
::GetConstantValue() const
{
assert(IsConstant() && "This method is relevant only for spatially constant parameters.");
......
......@@ -39,7 +39,7 @@ namespace HappyHeart
//! This object is never to be instantiated, so nullptr_t is a relevant choice.
using const_unique_ptr = std::nullptr_t;
using unique_ptr = std::nullptr_t;
};
......
......@@ -11,9 +11,12 @@
#ifndef HAPPY_HEART_x_PARAMETERS_x_TIME_DEPENDENCY_x_TIME_DEPENDENCY_HPP_
# define HAPPY_HEART_x_PARAMETERS_x_TIME_DEPENDENCY_x_TIME_DEPENDENCY_HPP_
# include <functional>
# include <memory>
# include <vector>
# include "Core/TimeManager/TimeManager.hpp"
namespace HappyHeart
{
......@@ -23,7 +26,10 @@ namespace HappyHeart
{
template<class FunctorT>
template
<
class FunctorT = std::function<double(double)>
>
class TimeDependency
{
......@@ -40,8 +46,14 @@ namespace HappyHeart
/// \name Special members.
///@{
//! Constructor.
explicit TimeDependency(FunctorT&& functor);
/*!
* \brief Constructor.
*
* \param[in] time_manager Object that keeps track of the time within the Model.
* \param[in] function Functor which returns the time-dependent factor given the current time.
*/
explicit TimeDependency(const TimeManager& time_manager,
FunctorT&& functor);
//! Destructor.
~TimeDependency() = default;
......@@ -60,8 +72,47 @@ namespace HappyHeart
///@}
/*!
* \brief Update the value of the time dependent factor.
*/
void Update();
//! Constant accessor to the value of time dependent factor.
double GetCurrentValue() const noexcept;
//! Constant accessor to the object that keeps track of the time within the Model.
const TimeManager& GetTimeManager() const noexcept;
private:
/// \name Accessors
///@{
//! Constant accessor to the value of TimeManager::NtimesModified() at the last Update() call.
unsigned int GetNtimesModifiedAtLastUpdate() const noexcept;
///@}
/*!
* \brief Update \a Ntimes_modified_at_last_update_.
*
* New value is given by GetTimeManager().NtimesModified().
*/
void UpdateNtimesModifiedAtLastUpdate();
private:
/*!
* \brief Value of \a TimeManager::NtimesModified() at the last \a Update() call.
*/
unsigned int Ntimes_modified_at_last_update_ = NumericNS::UninitializedIndex<unsigned int>();
//! Value computed for the current time.
double current_value_;
//! Object that keeps track of the time within the Model.
const TimeManager& time_manager_;
/*!
* \brief Functor which returns the time dependant factor.
*
......@@ -74,7 +125,6 @@ namespace HappyHeart
*/
const FunctorT functor_;
};
......
......@@ -20,13 +20,47 @@ namespace HappyHeart
{
template<class FunctorT>
TimeDependency<FunctorT>::TimeDependency(FunctorT&& functor)
: functor_(std::move(functor))
TimeDependency<FunctorT>::TimeDependency(const TimeManager& time_manager,
FunctorT&& functor)
: time_manager_(time_manager),
functor_(std::move(functor))
{ }
template<class FunctorT>
inline const TimeManager& TimeDependency<FunctorT>::GetTimeManager() const noexcept
{
return time_manager_;
}
template<class FunctorT>
void TimeDependency<FunctorT>::Update()
{
decltype(auto) time_manager = GetTimeManager();
UpdateNtimesModifiedAtLastUpdate();
current_value_ = functor_(time_manager.GetTime());
}
template<class FunctorT>
void TimeDependency<FunctorT>::UpdateNtimesModifiedAtLastUpdate()
{
Ntimes_modified_at_last_update_ = GetTimeManager().NtimeModified();
}
template<class FunctorT>
inline double TimeDependency<FunctorT>::GetCurrentValue() const noexcept
{
assert(GetNtimesModifiedAtLastUpdate() == GetTimeManager().NtimeModified()
&& "Check parameter is correctly up-to-date!");
return current_value_;
}
} // namespace ParameterNS
......
......@@ -13,6 +13,7 @@
#include "Parameters/Policy/AtDof.hpp"
#include "Parameters/InitParameter.hpp"
#include "Parameters/Private/ParameterInstance.hpp"
#include "Parameters/TimeDependency/TimeDependency.hpp"
#include "Operators/InterpolationOperatorInstances/ConformInterpolator.hpp"
......@@ -40,15 +41,24 @@ namespace HappyHeart
{
decltype(auto) mesh = GetGeometricMeshRegion(EnumUnderlyingType(MeshIndex::mesh));
auto linear = [](double time)
{
return time;
};
auto time_dep = std::make_unique<ParameterNS::TimeDependency<>>(GetTimeManager(), std::move(linear));
using Solid = InputParameter::Solid;
young_modulus_ =
InitScalarParameter
<
Solid::YoungModulus,
ParameterNS::TimeDependencyNS::None
ParameterNS::TimeDependency<>
>("Young modulus",
mesh,
input_parameter_data);
young_modulus_->SetTimeDependency(std::move(time_dep));
}
......
......@@ -12,13 +12,13 @@
# include <memory>
# include <vector>
# include "Model/Model.hpp"
# include "Parameters/TimeDependency/TimeDependency.hpp"
# include "Operators/ConformInterpolatorInstances/SubsetOrSuperset.hpp"
# include "Test/Parameter/TimeDependency/InputParameterList.hpp"
# include "Model/Model.hpp"
# include "Test/Parameter/TimeDependency/InputParameterList.hpp"
namespace HappyHeart
......@@ -133,10 +133,10 @@ namespace HappyHeart
//! Constant accessor to the young modulus (i.e. scalar parameter)
const ScalarParameter<>& GetYoungModulus() const noexcept;
const ScalarParameter<ParameterNS::TimeDependency<>>& GetYoungModulus() const noexcept;
//! Non constant accessor to the young modulus (i.e. scalar parameter)
ScalarParameter<>& GetNonCstYoungModulus() noexcept;
ScalarParameter<ParameterNS::TimeDependency<>>& GetNonCstYoungModulus() noexcept;
private:
......@@ -144,7 +144,7 @@ namespace HappyHeart
const std::string output_directory_;
//! Young modulus (i.e. scalar parameter)
ScalarParameter<>::const_unique_ptr young_modulus_ = nullptr;
ScalarParameter<ParameterNS::TimeDependency<>>::unique_ptr young_modulus_ = nullptr;
};
......
......@@ -37,16 +37,16 @@ namespace HappyHeart
}
inline const ScalarParameter<>& Model::GetYoungModulus() const noexcept
inline const ScalarParameter<ParameterNS::TimeDependency<>>& Model::GetYoungModulus() const noexcept
{
assert(!(!young_modulus_));
return *young_modulus_;
}
inline ScalarParameter<>& Model::GetNonCstYoungModulus() noexcept
inline ScalarParameter<ParameterNS::TimeDependency<>>& Model::GetNonCstYoungModulus() noexcept
{
return const_cast<ScalarParameter<>&>(GetYoungModulus());
return const_cast<ScalarParameter<ParameterNS::TimeDependency<>>&>(GetYoungModulus());
}
......
Supports Markdown
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