diff --git a/src/SoftRobots/component/constraint/SurfacePressureConstraint.cpp b/src/SoftRobots/component/constraint/SurfacePressureConstraint.cpp index 9e1c678a..e19c26b9 100644 --- a/src/SoftRobots/component/constraint/SurfacePressureConstraint.cpp +++ b/src/SoftRobots/component/constraint/SurfacePressureConstraint.cpp @@ -29,6 +29,7 @@ #include #include +#include namespace softrobots::constraint { @@ -56,26 +57,21 @@ void SurfacePressureConstraintResolution::init(int line, SReal**w, SReal*force) void SurfacePressureConstraintResolution::resolution(int line, SReal** w, SReal* d, SReal* force, SReal* dfree) { SOFA_UNUSED(w); - SOFA_UNUSED(d); SOFA_UNUSED(dfree); - double volumeGrowth = m_wActuatorActuator*m_imposedPressure + d[line]; + const double volumeGrowth = m_wActuatorActuator*m_imposedPressure + d[line]; if(volumeGrowthm_maxVolumeGrowth) + else if(volumeGrowth>m_maxVolumeGrowth) { - volumeGrowth = m_maxVolumeGrowth; - force[line] -= (d[line]-volumeGrowth) / m_wActuatorActuator ; + force[line] -= (d[line] - m_maxVolumeGrowth) / m_wActuatorActuator ; } else force[line] = m_imposedPressure ; - - } ///////////////////////////////////////////////////////////////////////////////////////////////////// @@ -106,10 +102,8 @@ void VolumeGrowthConstraintResolution::resolution(int line, SReal** w, SReal* d, // da=Waa*(lambda_a) + Sum Wai * lambda_i = m_imposedVolumeGrowth lambda[line] -= (d[line]-m_imposedVolumeGrowth) / m_wActuatorActuator ; - if(lambda[line]m_maxPressure) - lambda[line] = m_maxPressure; + lambda[line] = std::max(m_minPressure, lambda[line]); + lambda[line] = std::min(m_maxPressure, lambda[line]); } ///////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/SoftRobots/component/constraint/model/SurfacePressureModel.h b/src/SoftRobots/component/constraint/model/SurfacePressureModel.h index 387e1e44..e5b72a06 100644 --- a/src/SoftRobots/component/constraint/model/SurfacePressureModel.h +++ b/src/SoftRobots/component/constraint/model/SurfacePressureModel.h @@ -150,6 +150,7 @@ class SOFA_SOFTROBOTS_API SurfacePressureModel : virtual public SoftRobotsConstr void drawValue(const sofa::core::visual::VisualParams* vparams); void computeEdges(); + Real getTetrahedronVolume(const Coord& p0, const Coord& p1, const Coord& p2); }; extern template class SurfacePressureModel; diff --git a/src/SoftRobots/component/constraint/model/SurfacePressureModel.inl b/src/SoftRobots/component/constraint/model/SurfacePressureModel.inl index c2a2171c..2dce337d 100644 --- a/src/SoftRobots/component/constraint/model/SurfacePressureModel.inl +++ b/src/SoftRobots/component/constraint/model/SurfacePressureModel.inl @@ -263,6 +263,12 @@ void SurfacePressureModel::internalInit() } +template +typename SurfacePressureModel::Real SurfacePressureModel::getTetrahedronVolume(const Coord& p0, const Coord& p1, const Coord& p2) +{ + return ((p1[1]-p0[1])*(p2[2]-p0[2])-(p2[1]-p0[1])*(p1[2]-p0[2]))*(p0[0]+p1[0]+p2[0])/6; +} + template SReal SurfacePressureModel::getCavityVolume(const VecCoord& positions) { @@ -272,31 +278,17 @@ SReal SurfacePressureModel::getCavityVolume(const VecCoord& positions ReadAccessor>> triangles = d_triangles; ReadAccessor>> quads = d_quads; - Coord p0, p1, p2; Real volume = 0; for (unsigned int t=0; t