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

#873 Parameter/time dependency: it now works for vector and matrices, but with...

#873 Parameter/time dependency: it now works for vector and matrices, but with memory allocation at each call (I need to write a function that copies only the content of a Seldon vector or matrix).
parent a00e96fe
......@@ -265,7 +265,8 @@ namespace HappyHeart
>
inline const TimeDependencyT<TypeT>& Parameter<TypeT, TimeDependencyT>::GetTimeDependency() const noexcept
{
assert(!(!time_dependency_));
assert(!(!time_dependency_) && "Make sure Parameter::SetTimeDependency() has been correctly called after "
"construction.");
return *time_dependency_;
}
......
......@@ -27,16 +27,15 @@ namespace HappyHeart
{
double ApplyTimeFactor(double value_without_time_factor,
double unused,
double time_factor)
void ApplyTimeFactor(double value_without_time_factor,
double time_factor,
double& value_with_time_factor)
{
static_cast<void>(unused);
return value_without_time_factor * time_factor;
value_with_time_factor = value_without_time_factor * time_factor;
}
} // namespace Private
......
......@@ -14,6 +14,8 @@
# include <memory>
# include <vector>
# include "Utilities/MatrixOrVector.hpp"
namespace HappyHeart
{
......@@ -31,13 +33,17 @@ namespace HappyHeart
{
double ApplyTimeFactor(double value_without_time_factor,
double unused,
double time_factor);
void ApplyTimeFactor(double value_without_time_factor,
double time_factor,
double& value_with_time_factor);
template<class SeldonLinearAlgebraT>
void ApplyTimeFactor(const SeldonLinearAlgebraT& value_without_time_factor,
double time_factor,
SeldonLinearAlgebraT& value_with_time_factor);
} // namespace Private
......
......@@ -28,6 +28,17 @@ namespace HappyHeart
{
template<class SeldonLinearAlgebraT>
void ApplyTimeFactor(const SeldonLinearAlgebraT& value_without_time_factor,
double time_factor,
SeldonLinearAlgebraT& value_with_time_factor)
{
value_with_time_factor = value_without_time_factor;
value_with_time_factor *= time_factor;
}
} // namespace Private
......
......@@ -55,9 +55,13 @@ namespace HappyHeart
typename Base<TypeT, FunctorT>::return_type Base<TypeT, FunctorT>
::ApplyTimeFactor(return_type value_without_time_factor) const
{
return Private::ApplyTimeFactor(value_without_time_factor,
GetNonCstValueWithTimeFactor(),
GetCurrentTimeFactor());
auto& ret = GetNonCstValueWithTimeFactor();
Private::ApplyTimeFactor(value_without_time_factor,
GetCurrentTimeFactor(),
ret);
return ret;
}
......
......@@ -40,12 +40,6 @@ namespace HappyHeart
decltype(auto) god_of_dof = GetGodOfDof(EnumUnderlyingType(MeshIndex::mesh));
decltype(auto) mesh = god_of_dof.GetGeometricMeshRegion();
auto linear = [](double time)
{
return time;
};
auto time_dep = std::make_unique<ParameterNS::TimeDependency<ParameterNS::Type::scalar>>(GetTimeManager(), std::move(linear));
using Solid = InputParameter::Solid;
young_modulus_ =
......@@ -57,7 +51,18 @@ namespace HappyHeart
mesh,
input_parameter_data);
young_modulus_->SetTimeDependency(std::move(time_dep));
{
auto linear = [](double time)
{
return time;
};
auto time_dep = std::make_unique<ParameterNS::TimeDependency<ParameterNS::Type::scalar>>(GetTimeManager(),
std::move(linear));
young_modulus_->SetTimeDependency(std::move(time_dep));
}
poisson_ratio_ =
......@@ -83,6 +88,18 @@ namespace HappyHeart
assert(!(!source_parameter_));
{
auto linear = [](double time)
{
return time;
};
auto time_dep = std::make_unique<ParameterNS::TimeDependency<ParameterNS::Type::vector>>(GetTimeManager(),
std::move(linear));
GetNonCstSourceParameter().SetTimeDependency(std::move(time_dep));
}
using operator_type = decltype(source_operator_)::element_type;
decltype(auto) felt_space = god_of_dof.GetFEltSpace(EnumUnderlyingType(FEltSpaceIndex::index));
......@@ -95,7 +112,7 @@ namespace HappyHeart
mesh.GetDimension(),
DetermineDefaultQuadratureRule(5),
DoComputeProcessorWiseLocal2Global::no,
*source_parameter_);
GetNonCstSourceParameter());
}
......@@ -103,12 +120,15 @@ namespace HappyHeart
{
std::cout << "Young modulus = " << GetYoungModulus().GetConstantValue() << std::endl;
std::cout << "Poisson ratio = " << GetPoissonRatio().GetConstantValue() << std::endl;
std::cout << "Transient source = " << GetSourceParameter().GetConstantValue() << std::endl;
}
void Model::SupplInitializeStep()
{
GetNonCstYoungModulus().TimeUpdate();
GetNonCstSourceParameter().TimeUpdate();
}
......
......@@ -162,6 +162,16 @@ namespace HappyHeart
const GlobalVariationalOperatorNS::TransientSource<ParameterNS::TimeDependency>&
GetSourceOperator() const noexcept;
//! Non constant accessor to the source operator.
GlobalVariationalOperatorNS::TransientSource<ParameterNS::TimeDependency>&
GetNonCstSourceOperator() noexcept;
//! Constant accessor to the underlying Parameter used to define source operator.
const Parameter<ParameterNS::Type::vector, ParameterNS::TimeDependency>& GetSourceParameter() const noexcept;
//! Non constant accessor to the underlying Parameter used to define source operator.
Parameter<ParameterNS::Type::vector, ParameterNS::TimeDependency>& GetNonCstSourceParameter() noexcept;
private:
......
......@@ -70,6 +70,29 @@ namespace HappyHeart
assert(!(!source_operator_));
return *source_operator_;
}
inline GlobalVariationalOperatorNS::TransientSource<ParameterNS::TimeDependency>& Model
::GetNonCstSourceOperator() noexcept
{
return const_cast<GlobalVariationalOperatorNS::TransientSource<ParameterNS::TimeDependency>&>(GetSourceOperator());
}
inline const Parameter<ParameterNS::Type::vector, ParameterNS::TimeDependency>&
Model::GetSourceParameter() const noexcept
{
assert(!(!source_parameter_));
return *source_parameter_;
}
inline Parameter<ParameterNS::Type::vector, ParameterNS::TimeDependency>&
Model::GetNonCstSourceParameter() noexcept
{
return const_cast<Parameter<ParameterNS::Type::vector, ParameterNS::TimeDependency>&>(GetSourceParameter());
}
} // namespace TestParameterTimeDependencyNS
......
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