diff --git a/MaterialLib/SolidModels/MFront/MFront.cpp b/MaterialLib/SolidModels/MFront/MFront.cpp index b8baa8a94e3a17d5d08aa872470bb952d8018a93..2da3ad27ae90fbd525e45581423bb590b77cbcee 100644 --- a/MaterialLib/SolidModels/MFront/MFront.cpp +++ b/MaterialLib/SolidModels/MFront/MFront.cpp @@ -249,9 +249,10 @@ MFront<DisplacementDim>::integrateStress( { assert( dynamic_cast<MaterialStateVariables const*>(&material_state_variables)); - auto& behaviour_data = - static_cast<MaterialStateVariables const&>(material_state_variables) - ._behaviour_data; + // New state, copy of current one, packed in unique_ptr for return. + auto state = std::make_unique<MaterialStateVariables>( + static_cast<MaterialStateVariables const&>(material_state_variables)); + auto& behaviour_data = state->_behaviour_data; // TODO add a test of material behaviour where the value of dt matters. behaviour_data.dt = dt; @@ -305,14 +306,14 @@ MFront<DisplacementDim>::integrateStress( KelvinMatrix C = MFrontToOGS(Eigen::Map<KelvinMatrix>(behaviour_data.K.data())); - // TODO avoid copying the state - auto state_copy = std::make_unique<MaterialStateVariables>( - static_cast<MaterialStateVariables const&>(material_state_variables)); - std::unique_ptr< - typename MechanicsBase<DisplacementDim>::MaterialStateVariables> - state_upcast(state_copy.release()); - - return {std::make_tuple(std::move(sigma), std::move(state_upcast), std::move(C))}; + return boost::make_optional( + std::make_tuple<typename MFront<DisplacementDim>::KelvinVector, + std::unique_ptr<typename MechanicsBase< + DisplacementDim>::MaterialStateVariables>, + typename MFront<DisplacementDim>::KelvinMatrix>( + std::move(sigma), + std::move(state), + std::move(C))); } template <int DisplacementDim> diff --git a/MaterialLib/SolidModels/MFront/MFront.h b/MaterialLib/SolidModels/MFront/MFront.h index 68e9a480866b0db7626050a2dbc3f411db4b4521..78d074825f60d4b33534633413f70c6ea2710d51 100644 --- a/MaterialLib/SolidModels/MFront/MFront.h +++ b/MaterialLib/SolidModels/MFront/MFront.h @@ -67,8 +67,7 @@ public: return operator=(static_cast<MaterialStateVariables const&>(state)); } - // TODO fix: this has to be mutable. - mutable mgis::behaviour::BehaviourData _behaviour_data; + mgis::behaviour::BehaviourData _behaviour_data; }; using KelvinVector =