@@ -157,6 +157,7 @@ void ElementHyperelasticityFEMForceField<DataTypes, ElementType>::computeHessian
157157 const std::array<Coord, NumberOfNodesInElement> elementNodesCoordinates = sofa::component::solidmechanics::fem::elastic::extractNodesVectorFromGlobalVector (element, this ->mstate ->readPositions ().ref ());
158158
159159 ElementStiffness& K = *elementStiffnessIt++;
160+ K.clear ();
160161
161162 static constexpr auto quadraturePoints = FiniteElement::quadraturePoints ();
162163 static constexpr auto gradients = sofa::fem::FiniteElementHelper<ElementType, DataTypes>::gradientShapeFunctionAtQuadraturePoints ();
@@ -307,15 +308,18 @@ void ElementHyperelasticityFEMForceField<TDataTypes, TElementType>::computeEleme
307308 sofa::type::vector<ElementForce>& f, const sofa::VecCoord_t<TDataTypes>& x)
308309{
309310 const auto & elements = trait::FiniteElement::getElementSequence (*this ->l_topology );
310- auto restPositionAccessor = this ->mstate ->readRestPositions ();
311+
312+ static constexpr auto quadraturePoints = FiniteElement::quadraturePoints ();
313+ static constexpr auto gradients = sofa::fem::FiniteElementHelper<TElementType, DataTypes>::gradientShapeFunctionAtQuadraturePoints ();
311314
312315 for (std::size_t elementId = range.start ; elementId < range.end ; ++elementId)
313316 {
314317 const auto element = elements[elementId];
315318 const std::array<Coord, NumberOfNodesInElement> elementNodesCoordinates = sofa::component::solidmechanics::fem::elastic::extractNodesVectorFromGlobalVector (element, x);
316319
317- static constexpr auto quadraturePoints = FiniteElement::quadraturePoints ();
318- static constexpr auto gradients = sofa::fem::FiniteElementHelper<TElementType, DataTypes>::gradientShapeFunctionAtQuadraturePoints ();
320+ // access to the force vector in the element. This is the value to compute in this iteration
321+ // force assembly at the DoF level is done in a later function.
322+ auto & elementForce = f[elementId];
319323
320324 for (sofa::Size q = 0 ; q < NumberOfQuadraturePoints; ++q)
321325 {
@@ -341,19 +345,14 @@ void ElementHyperelasticityFEMForceField<TDataTypes, TElementType>::computeEleme
341345 // const DeformationGradient F = computeDeformationGradient2(elementNodesCoordinates, dN_dQ);
342346
343347 Strain<DataTypes> strain (deformationGradient, F);
344-
345348 const auto P = l_material->firstPiolaKirchhoffStress (strain);
346- auto & elementForce = f[elementId];
347349
348- sofa::type::Vec<trait::spatial_dimensions, sofa::Real_t<DataTypes>> nodeForce { sofa::type::NOINIT };
349350 for (sofa::Size i = 0 ; i < trait::NumberOfNodesInElement; ++i)
350351 {
351- elementForce.getsub (i * trait::spatial_dimensions, nodeForce);
352- // elementForce.setsub(i * trait::spatial_dimensions, nodeForce + (detJ_Q * weight) * P * dN_dQ[i]);
353- nodeForce += (detJ_Q * weight) * P * dN_dQ[i];
352+ const auto f_q = (detJ_Q * weight) * P * dN_dQ[i];
354353 for (sofa::Size j = 0 ; j < trait::spatial_dimensions; ++j)
355354 {
356- elementForce[i * trait::spatial_dimensions + j] = nodeForce [j];
355+ elementForce[i * trait::spatial_dimensions + j] += f_q [j];
357356 }
358357 }
359358 }
0 commit comments