Commit aaa96c6d authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#718 Hyperelasticity: make sure evaluation state is modified at only one...

#718 Hyperelasticity: make sure evaluation state is modified at only one location (namely given from Petsc).
parent 69d4c750
......@@ -385,11 +385,13 @@ namespace HappyHeart
HyperelasticityNS::TimeScheme TimeSchemeT
>
void VariationalFormulationHyperElasticity<LawPolicyT, TimeSchemeT>
::UpdateVectorsAndMatrices()
::UpdateVectorsAndMatrices(const Vec& a_evaluation_state)
{
std::cout << "UPDATE VM" << std::endl;
auto& vm = this->GetNonCstVectorsAndMatrices();
vm.UpdateEvaluationState(a_evaluation_state);
{
// Compute some matrices and vectors through arithmetical operations (e.g. vector for midpoint position).
......@@ -398,8 +400,7 @@ namespace HappyHeart
}
{
// Update relevant ghosts.
vm.GetNonCstEvaluationState().UpdateGhosts(__FILE__, __LINE__);
// Update relevant ghosts.
HyperelasticityNS::Private::PreSnesTimeSchemeDependantUpdateGhosts(vm);
}
......
......@@ -67,11 +67,6 @@ namespace HappyHeart
auto& formulation = *formulation_ptr;
const auto& numbering_subset = formulation.GetNumberingSubset();
auto& vm = formulation.GetNonCstVectorsAndMatrices();
auto& evaluation_state = vm.GetNonCstEvaluationState();
evaluation_state.SetFromPetscVec(a_evaluation_state, __FILE__, __LINE__);
#ifndef NDEBUG
{
......@@ -80,7 +75,7 @@ namespace HappyHeart
namespace Petsc = Wrappers::Petsc;
const bool is_same = Petsc::AreEqual(Petsc::Vector(a_residual, false),
formulation.GetNonCstSystemRhs(numbering_subset),
formulation.GetSystemRhs(numbering_subset),
1.e-12,
desc,
__FILE__, __LINE__);
......@@ -95,7 +90,7 @@ namespace HappyHeart
}
#endif // NDEBUG
formulation.UpdateVectorsAndMatrices();
formulation.UpdateVectorsAndMatrices(a_evaluation_state);
formulation.ComputeResidual();
return 0;
......
......@@ -81,6 +81,14 @@ namespace HappyHeart
///@}
/*!
* \brief Update the vector that contains the values seeked at the moment the residual is evaluated.
*
* \param[in] evaluation_state Evaluation state given by the Petsc's snes function.
*/
void UpdateEvaluationState(Vec evaluation_state);
/// \name Accessors to the global vectors and matrices managed by the class.
///@{
......@@ -106,8 +114,7 @@ namespace HappyHeart
GlobalVector& GetNonCstVelocityPreviousTimeIteration() noexcept;
GlobalVector& GetNonCstDisplacementPreviousTimeIteration() noexcept;
GlobalVector& GetNonCstEvaluationState() noexcept;
//! Access to stiffness in the next time iteration.
const GlobalVector& GetVectorNewStiffness() const noexcept;
......@@ -133,6 +140,19 @@ namespace HappyHeart
const GlobalVector& system_rhs);
private:
/*!
* \brief Non constant access to the evaluation state, i.e. the values at the time Petsc evaluates
* the residual.
*
* \internal This accessor should not be used except in the Snes::Function() method: the point is to
* store the value given by Petsc internal Newton algorithm.
* Its value should be modified only through the call if \a UpdateEvaluationState().
*/
GlobalVector& GetNonCstEvaluationState() noexcept;
private:
......
......@@ -42,6 +42,15 @@ namespace HappyHeart
}
template<class DerivedT>
void VectorsAndMatricesCrtp<DerivedT>::UpdateEvaluationState(Vec a_evaluation_state)
{
auto& evaluation_state = GetNonCstEvaluationState();
evaluation_state.SetFromPetscVec(a_evaluation_state, __FILE__, __LINE__);
evaluation_state.UpdateGhosts(__FILE__, __LINE__);
}
template<class DerivedT>
inline const GlobalVector& VectorsAndMatricesCrtp<DerivedT>::GetForce() const noexcept
{
......
......@@ -219,7 +219,7 @@ namespace HappyHeart
* \brief Update the content of all the vectors and matrices relevant to the computation of the tangent
* and the residual.
*/
void UpdateVectorsAndMatrices();
void UpdateVectorsAndMatrices(const Vec& a_evaluation_state);
//! An helper method of \a UpdateVectorsAndMatrices().
void AssembleVectorsAndMatrices();
......
......@@ -594,9 +594,12 @@ namespace HappyHeart
class DofSourcePolicyT
>
void VariationalFormulationHyperElasticity<LawPolicyT, TimeSchemeT, VolumicIndexT, SurfacicIndexT, DofSourcePolicyT>
::UpdateVectorsAndMatrices()
::UpdateVectorsAndMatrices(const Vec& a_evaluation_state)
{
auto& vm = this->GetNonCstVectorsAndMatrices();
vm.UpdateEvaluationState(a_evaluation_state);
{
// Zero all relevant matrices and vectors.
......@@ -613,7 +616,6 @@ namespace HappyHeart
{
// Update relevant ghosts.
vm.GetNonCstEvaluationState().UpdateGhosts(__FILE__, __LINE__);
vm.GetNonCstDisplacementPreviousTimeIteration().UpdateGhosts(__FILE__, __LINE__);
Private::PreSnesTimeSchemeDependantUpdateGhosts(vm);
}
......
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