Commit 16739f59 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#873 [DOES NOT COMPILE] I have added the time dependency almost seamlessly;...

#873 [DOES NOT COMPILE] I have added the time dependency almost seamlessly; there are still two missing steps:

- Additional constructor argument should be added in all instances.
- Code doesn't compile because I put bluntly the factor in GetValue() method; it should be filtered by a Traits
to consider nicely the possible TypeT (or I can try simple overload of the method here...)
parent 44c00182
......@@ -14,6 +14,7 @@
# include <memory>
# include <fstream>
# include <array>
# include <functional>
# include "Utilities/MatrixOrVector.hpp"
# include "Utilities/Filesystem/File.hpp"
......@@ -47,11 +48,28 @@ namespace HappyHeart
// ============================
/*!
* \class doxygen_hide_param_time_dependancy
*
* A Parameter is first and foremost a spatial-dependant data: its main purpose is to describe the value
* of a physical parameter at a given quadrature point. However, we might also want to apply a decoupled time
* dependancy, i.e. consider value of the parameter might be determined by:
* \verbatim
* P(x, t) = f(x) * g(t)
* \endverbatim
*
* In this case, g(t) is stored as a function and is recomputed at each \a TimeUpdate() calls (such calls
* should therefore be located in Model::InitializeStep() or Model::FinalizeStep()).
*/
/*!
* \brief Abstract class used to define a Parameter.
*
* \tparam TypeT Type of the parameter (real, vector, matrix).
*
* \copydoc doxygen_hide_param_time_dependancy
*
* Actual instantiations of the class are specializations of ParameterInstance template class; a developer should
* anyway use only InitParameter() free function to instantiate a parameter.
*/
......@@ -85,6 +103,7 @@ namespace HappyHeart
/// \name Special members.
///@{
/*!
* \brief Constructor.
*
......@@ -92,10 +111,17 @@ namespace HappyHeart
* \param[in] geometric_mesh_region Mesh upon which the parameter is built.
*
* \tparam T Type of name, in forwarding reference idiom. It must be convertible to a std::string.
*
* \copydoc doxygen_hide_param_time_dependancy
*
* \param[in] time_dependant_factor A functor which returns the time contribution g(t). This functor
* takes the time t as argument and returns a scalar.
*/
template<class T>
explicit Parameter(T&& name,
const GeometricMeshRegion& geometric_mesh_region);
const GeometricMeshRegion& geometric_mesh_region,
std::function<double(double)>&& time_dependant_factor = [](const double) { return 1.; } );
//! Destructor.
virtual ~Parameter() = default;
......@@ -156,6 +182,15 @@ namespace HappyHeart
//! Returns the geometric mesh region upon which the parameter is defined.
const GeometricMeshRegion& GetGeometricMeshRegion() const noexcept;
/*!
* \brief Apply a time update on the parameter.
*
* \copydoc doxygen_hide_param_time_dependancy
*
* \param[in] time Current time at which time dependant factor must be estimated.
*/
void TimeUpdate(double time);
protected:
......@@ -190,6 +225,11 @@ namespace HappyHeart
* \para,
*/
virtual void SupplWrite(std::ostream& out) const = 0;
private:
//! Constant accessor to the current value of the time dependancy factor.
double GetTimeDependancyFactor() const noexcept;
private:
......@@ -199,6 +239,12 @@ namespace HappyHeart
//! Mesh upon which the parameter is defined.
const GeometricMeshRegion& geometric_mesh_region_;
//! Functor which returns the time-dependant factor.
std::function<double(double)> time_dependancy_functor_;
//! Current value of the time dependancy factor.
double time_dependancy_factor_;
};
......
......@@ -19,10 +19,20 @@ namespace HappyHeart
template<ParameterNS::Type TypeT>
template<class T>
Parameter<TypeT>::Parameter(T&& name,
const GeometricMeshRegion& geometric_mesh_region)
const GeometricMeshRegion& geometric_mesh_region,
std::function<double(double)>&& time_dependant_factor)
: name_(name),
geometric_mesh_region_(geometric_mesh_region)
geometric_mesh_region_(geometric_mesh_region),
time_dependancy_functor_(std::move(time_dependant_factor)),
time_dependancy_factor_(time_dependancy_functor_(0.))
{ }
template<ParameterNS::Type TypeT>
void Parameter<TypeT>::TimeUpdate(double time)
{
time_dependancy_factor_ = time_dependancy_functor_(time);
}
template<ParameterNS::Type TypeT>
......@@ -30,7 +40,7 @@ namespace HappyHeart
{
assert(IsConstant() && "This method is relevant only for spatially constant parameters.");
return SupplGetConstantValue();
return SupplGetConstantValue() * GetTimeDependancyFactor();
}
......@@ -41,7 +51,7 @@ namespace HappyHeart
if (IsConstant())
return GetConstantValue();
return SupplGetValue(quad_pt, geom_elt);
return SupplGetValue(quad_pt, geom_elt) * GetTimeDependancyFactor();
}
......@@ -74,6 +84,14 @@ namespace HappyHeart
{
return geometric_mesh_region_;
}
template<ParameterNS::Type TypeT>
inline double Parameter<TypeT>::GetTimeDependancyFactor() const noexcept
{
return time_dependancy_factor_;
}
......
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