Commit 905edcf0 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#873 Parameters: time interface is almost done (storage allocation and proper...

#873 Parameters: time interface is almost done (storage allocation and proper multiplication depending on type remain to be done.
parent 4a2213e4
......@@ -14,6 +14,7 @@
# include <memory>
# include <fstream>
# include <array>
# include <cassert>
# include <functional>
# include "Utilities/MatrixOrVector.hpp"
......@@ -209,10 +210,8 @@ namespace HappyHeart
private:
return_type ApplyTimeDependancyFactor(return_type value_without_time_factor) const;
/*!
* \brief Returns the constant value (if the parameters is constant).
*
......
......@@ -60,21 +60,70 @@ namespace HappyHeart
}
template
<
ParameterNS::Type TypeT,
class TimeDependencyT
>
struct ApplyTimeFactorHelper
{
using return_type = typename ParameterNS::Traits<TypeT>::return_type;
static return_type Perform(return_type);
};
template<ParameterNS::Type TypeT>
struct ApplyTimeFactorHelper<TypeT, ParameterNS::TimeDependencyNS::None<TypeT>>
{
using return_type = typename ParameterNS::Traits<TypeT>::return_type;
static return_type Perform(return_type);
};
template
<
ParameterNS::Type TypeT,
class TimeDependencyT
>
typename ApplyTimeFactorHelper<TypeT, TimeDependencyT>::return_type ApplyTimeFactorHelper<TypeT, TimeDependencyT>
::Perform(return_type value_without_time_factor)
{
std::cout << "Time factor should be applied here." << std::endl;
return value_without_time_factor;
}
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)
{
std::cout << "No time factor to apply." << std::endl;
return value_without_time_factor;
}
template
<
ParameterNS::Type TypeT,
template<ParameterNS::Type> class TimeDependencyT
>
typename Parameter<TypeT, TimeDependencyT>::return_type
inline typename Parameter<TypeT, TimeDependencyT>::return_type
Parameter<TypeT, TimeDependencyT>
::ApplyTimeDependancyFactor(typename Parameter<TypeT, TimeDependencyT>::return_type value_without_time) const
{
return value_without_time;
return ApplyTimeFactorHelper<TypeT, TimeDependencyT<TypeT>>::Perform(value_without_time);
}
template
<
ParameterNS::Type TypeT,
......
......@@ -11,6 +11,7 @@
#ifndef HAPPY_HEART_x_PARAMETERS_x_TIME_DEPENDENCY_x_NONE_HPP_
# define HAPPY_HEART_x_PARAMETERS_x_TIME_DEPENDENCY_x_NONE_HPP_
# include <memory>
namespace HappyHeart
{
......@@ -37,10 +38,11 @@ namespace HappyHeart
template<Type TypeT>
struct None
{
//! This object is never to be instantiated, so nullptr_t is a relevant choice.
using unique_ptr = std::nullptr_t;
using unique_ptr = std::unique_ptr<None>;
};
......
......@@ -48,6 +48,16 @@ namespace HappyHeart
//! Alias to unique pointer.
using unique_ptr = std::unique_ptr<self>;
//! Alias to traits class related to TypeT.
using traits = Traits<TypeT>;
//! Alias to the return type.
using return_type = typename traits::return_type;
//! Alias to the type of the value actually stored.
using storage_type = std::decay_t<return_type>;
public:
/// \name Special members.
......@@ -101,6 +111,8 @@ namespace HappyHeart
//! Constant accessor to the object that keeps track of the time within the Model.
const TimeManager& GetTimeManager() const noexcept;
// return_type ApplyFactor(return_type value_without_time_factor);
private:
/// \name Accessors
......@@ -145,16 +157,10 @@ namespace HappyHeart
private:
//! Alias to traits class related to TypeT.
using traits = Traits<TypeT>;
//! Alias to the return type.
using return_type = typename traits::return_type;
mutable storage_type value_with_time_factor_;
//! Alias to the type of the value actually stored.
using storage_type = std::decay_t<return_type>;
storage_type value_with_time_factor_;
};
......
......@@ -46,6 +46,20 @@ namespace HappyHeart
}
// template
// <
// ParameterNS::Type TypeT,
// class FunctorT
// >
// typename Base<TypeT, FunctorT>::return_type Base<TypeT, FunctorT>
// ::ApplyFactor(return_type value_without_time_factor)
// {
// std::cout << "ADD CHANGES" << std::endl;
// return value_without_time_factor;
// }
template
<
ParameterNS::Type TypeT,
......
......@@ -57,6 +57,17 @@ namespace HappyHeart
input_parameter_data);
young_modulus_->SetTimeDependency(std::move(time_dep));
poisson_ratio_ =
InitScalarParameter
<
Solid::YoungModulus,
ParameterNS::TimeDependencyNS::None
>("Poisson ratio",
mesh,
input_parameter_data);
}
......@@ -64,6 +75,7 @@ namespace HappyHeart
void Model::Forward()
{
std::cout << "Young modulus = " << GetYoungModulus().GetConstantValue() << std::endl;
std::cout << "Poisson ratio = " << GetPoissonRatio().GetConstantValue() << std::endl;
}
......
......@@ -48,11 +48,18 @@ namespace HappyHeart
//! Friendship granted to the base class so this one can manipulates private methods.
friend parent;
using foo = Parameter
using scalar_varying_type = Parameter
<
ParameterNS::Type::scalar,
ParameterNS::TimeDependency
>;
using scalar_immutable_type = Parameter
<
ParameterNS::Type::scalar,
ParameterNS::TimeDependencyNS::None
>;
public:
......@@ -138,11 +145,17 @@ namespace HappyHeart
///@}
//! Constant accessor to the young modulus (i.e. scalar parameter)
const foo& GetYoungModulus() const noexcept;
//! Constant accessor to the scalar parameter that varies with time.
const scalar_varying_type& GetYoungModulus() const noexcept;
//! Non constant accessor to the scalar parameter that varies with time.
scalar_varying_type& GetNonCstYoungModulus() noexcept;
//! Non constant accessor to the young modulus (i.e. scalar parameter)
foo& GetNonCstYoungModulus() noexcept;
//! Constant accessor to the scalar parameter that does not vary with time.
const scalar_immutable_type& GetPoissonRatio() const noexcept;
//! Non constant accessor to scalar parameter that does not vary with time.
scalar_immutable_type& GetNonCstPoissonRatio() noexcept;
private:
......@@ -152,8 +165,11 @@ namespace HappyHeart
//! Young modulus (i.e. scalar parameter)
typename foo::unique_ptr young_modulus_ = nullptr;
//! Young modulus (i.e. scalar parameter) that in the test may vary with time.
typename scalar_varying_type::unique_ptr young_modulus_ = nullptr;
//! Poisson ratio (i.e. scalar parameter) that in the test may not vary with time.
typename scalar_immutable_type::unique_ptr poisson_ratio_ = nullptr;
};
......
......@@ -37,16 +37,30 @@ namespace HappyHeart
}
inline const Model::foo& Model::GetYoungModulus() const noexcept
inline const Model::scalar_immutable_type& Model::GetPoissonRatio() const noexcept
{
assert(!(!poisson_ratio_));
return *poisson_ratio_;
}
inline Model::scalar_immutable_type& Model::GetNonCstPoissonRatio() noexcept
{
return const_cast<scalar_immutable_type&>(GetPoissonRatio());
}
inline const Model::scalar_varying_type& Model::GetYoungModulus() const noexcept
{
assert(!(!young_modulus_));
return *young_modulus_;
}
inline Model::foo& Model::GetNonCstYoungModulus() noexcept
inline Model::scalar_varying_type& Model::GetNonCstYoungModulus() noexcept
{
return const_cast<foo&>(GetYoungModulus());
return const_cast<scalar_varying_type&>(GetYoungModulus());
}
......
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