Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
02a2ff8
First commit
hugtalbot May 13, 2022
df4aeae
Create a separate gravity FF
hugtalbot May 14, 2022
86e8a5e
Make gravity as DPos to keep only axis dofs
hugtalbot May 15, 2022
b3fb5ff
deprecated and remove Gravity
hugtalbot May 18, 2022
62c6b19
remove Gravity.cpp
hugtalbot May 18, 2022
c4f9c34
Rename and update scene for GravityForceField
hugtalbot May 18, 2022
6ce62fa
estetic change
hugtalbot May 18, 2022
e9038b1
Temporarily moving GravityForceField into Core to avoid CMake dirty d…
hugtalbot May 19, 2022
58b5c50
add forgotten file in the move
hugtalbot May 19, 2022
d2e0797
Removing the addMDxToVector function related to the gravity
hugtalbot May 24, 2022
9c90034
fix typo missing .cpp in CMakeLists
hugtalbot May 29, 2022
190ab9c
Clean in OdeSolver.cpp
hugtalbot May 29, 2022
e6a910c
Improve transition comment messages for GravityForceField
hugtalbot May 29, 2022
0a5ce88
Create automatic creation of GravityForceField from create function o…
hugtalbot May 29, 2022
e4cca6c
Add warning in Node to present using the data gravity and refer PR
hugtalbot May 29, 2022
4f09c05
minor typo of version in ComponentChange
hugtalbot May 29, 2022
28261e9
Update PR number in the code deprecation
hugtalbot May 29, 2022
96e8969
merge master 20220529
hugtalbot May 29, 2022
421b68f
Add PR correct number.
damienmarchal Jun 8, 2022
50b9207
fix header wrong msg
hugtalbot Jul 12, 2022
9269595
check non null pointer in getPotentialEnergy
hugtalbot Jul 12, 2022
c47251f
Merge branch 'master' into new_gravityforcefield_202205
hugtalbot Jul 18, 2022
333d660
Separate Mass from ForceField API - experimental
hugtalbot Jul 12, 2022
485c742
merge master 05-09-2022
hugtalbot Sep 5, 2022
a74c586
Move GravityForceField into MechanicalLoad
hugtalbot Sep 5, 2022
52eaca1
mark addMDxToVector in UniformMass as delete
hugtalbot Sep 8, 2022
94bdb1e
remove useless SOFA_ATTRIBUTE and remove unneeded addKToMatrix overload
hugtalbot Sep 8, 2022
c91395a
fix code and warning
hugtalbot Sep 8, 2022
5d357cf
clean Mass.h witout SOFA_ATTRIBUTE and unncessary insert/removeInNode…
hugtalbot Sep 8, 2022
a771e1b
remove useless protected
hugtalbot Sep 9, 2022
43797c1
update dates in disabled message
hugtalbot Sep 9, 2022
aaf7989
reformat warning emssage from UniformMass
hugtalbot Sep 9, 2022
1bac38b
fix warning due to missing return in HexahedralFEMForceFieldAndMass
hugtalbot Sep 9, 2022
6a1b993
rename dataname for user into worldGravity in Node/Context and add co…
hugtalbot Sep 9, 2022
327be9a
Gravity(deprecated) : update dates in disabled message
hugtalbot Sep 9, 2022
234de4d
Introduce new gravity mechanism
hugtalbot Sep 9, 2022
a5c90ac
add using to use the proper canCreate
hugtalbot Sep 9, 2022
e264f11
Add DataTypes available for SP3
hugtalbot Sep 9, 2022
6d4f2ef
Keep gravity as default name in node and update c++ data name
hugtalbot Sep 21, 2022
94f9224
merge master
hugtalbot Feb 24, 2023
6c5edde
Remove option possibly activating ExternalBehaviorModel when legacy h…
hugtalbot Feb 26, 2023
7dca22e
Fix Windows compilation due to ambiguous types
hugtalbot Feb 27, 2023
e369b6a
Fix SofaCUDA plugin compilation
hugtalbot Feb 28, 2023
e764d59
Fix CudaUniformMass::getGravitationalPotentialEnergy
hugtalbot Feb 28, 2023
73a6c83
fix Windows template ambiguity
hugtalbot Feb 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,17 @@ using namespace sofa::defaulttype;

template <class RigidTypes, class GeometricalTypes>
template <class T>
SReal DiagonalMass<RigidTypes, GeometricalTypes>::getPotentialEnergyRigidImpl( const MechanicalParams* mparams,
const DataVecCoord& x) const
SReal DiagonalMass<RigidTypes, GeometricalTypes>::getGravitationalPotentialEnergyRigidImpl( const MechanicalParams* mparams,
const DataVecCoord& x, const Deriv& g) const
{
SOFA_UNUSED(mparams) ;
SReal e = 0;
const MassVector &masses= d_vertexMass.getValue();
const VecCoord& _x = x.getValue();

// gravity
Vec3d g ( this->getContext()->getGravity() );
Deriv theGravity;
RigidTypes::set( theGravity, g[0], g[1], g[2]);
for (unsigned int i=0; i<_x.size(); i++)
{
e -= getVCenter(theGravity) * masses[i].mass * _x[i].getCenter();
e -= getVCenter(g) * masses[i].mass * _x[i].getCenter();
}
return e;
}
Expand All @@ -65,7 +61,7 @@ void DiagonalMass<RigidTypes, GeometricalTypes>::drawRigid3dImpl(const VisualPar
{
const MassVector &masses= d_vertexMass.getValue();
if (!vparams->displayFlags().getShowBehaviorModels()) return;
const VecCoord& x =mstate->read(core::ConstVecCoordId::position())->getValue();
const VecCoord& x =this->mstate->read(core::ConstVecCoordId::position())->getValue();

if(masses.size() != x.size()) return;

Expand Down Expand Up @@ -113,7 +109,7 @@ void DiagonalMass<RigidTypes, GeometricalTypes>::drawRigid2dImpl(const VisualPar
{
const MassVector &masses= d_vertexMass.getValue();
if (!vparams->displayFlags().getShowBehaviorModels()) return;
const VecCoord& x =mstate->read(core::ConstVecCoordId::position())->getValue();
const VecCoord& x =this->mstate->read(core::ConstVecCoordId::position())->getValue();
for (unsigned int i=0; i<x.size(); i++)
{
if (masses[i].mass == 0) continue;
Expand Down Expand Up @@ -266,17 +262,17 @@ type::Vec6 DiagonalMass<Vec3Types, GeometricalTypes>::getMomentumVec3Impl( const


template <>
SReal DiagonalMass<Rigid3Types>::getPotentialEnergy( const MechanicalParams* mparams,
const DataVecCoord& x) const
SReal DiagonalMass<Rigid3Types>::getGravitationalPotentialEnergy( const MechanicalParams* mparams,
const DataVecCoord& x, const Deriv& g) const
{
return getPotentialEnergyRigidImpl<Rigid3Types>(mparams, x) ;
return getGravitationalPotentialEnergyRigidImpl<Rigid3Types>(mparams, x, g) ;
}

template <>
SReal DiagonalMass<Rigid2Types>::getPotentialEnergy( const MechanicalParams* mparams,
const DataVecCoord& x) const
SReal DiagonalMass<Rigid2Types>::getGravitationalPotentialEnergy( const MechanicalParams* mparams,
const DataVecCoord& x, const Deriv& g) const
{
return getPotentialEnergyRigidImpl<Rigid2Types>(mparams, x) ;
return getGravitationalPotentialEnergyRigidImpl<Rigid2Types>(mparams, x, g) ;
}

template <>
Expand Down
17 changes: 7 additions & 10 deletions Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class DiagonalMass : public core::behavior::Mass<DataTypes>
/// Bring inherited attributes and function in the current lookup context.
/// otherwise any access to the base::attribute would require
/// the "this->" approach.
using core::behavior::ForceField<DataTypes>::mstate ;
using core::objectmodel::BaseObject::getContext;
////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -303,16 +302,14 @@ class DiagonalMass : public core::behavior::Mass<DataTypes>

void accFromF(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) override;

void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override;
void addGravitationalForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v, const Deriv& gravity) override; ///< Mg force in a lumped gravity field

SReal getKineticEnergy(const core::MechanicalParams* mparams, const DataVecDeriv& v) const override; ///< vMv/2 using dof->getV() override
SReal getGravitationalPotentialEnergy(const core::MechanicalParams* mparams, const DataVecCoord& x, const Deriv& gravity) const override; ///< Mgx potential in a uniform gravity field, null at origin

SReal getPotentialEnergy(const core::MechanicalParams* mparams, const DataVecCoord& x) const override; ///< Mgx potential in a uniform gravity field, null at origin
SReal getKineticEnergy(const core::MechanicalParams* mparams, const DataVecDeriv& v) const override; ///< vMv/2 using dof->getV() override

type::Vec6 getMomentum(const core::MechanicalParams* mparams, const DataVecCoord& x, const DataVecDeriv& v) const override; ///< (Mv,cross(x,Mv)+Iw) override

void addGravityToV(const core::MechanicalParams* mparams, DataVecDeriv& d_v) override;

/// Add Mass contribution to global Matrix assembling
void addMToMatrix(const core::MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override;

Expand All @@ -337,8 +334,8 @@ class DiagonalMass : public core::behavior::Mass<DataTypes>

private:
template <class T>
SReal getPotentialEnergyRigidImpl( const core::MechanicalParams* mparams,
const DataVecCoord& x) const ;
SReal getGravitationalPotentialEnergyRigidImpl( const core::MechanicalParams* mparams,
const DataVecCoord& x, const Deriv& g) const ;

template <class T>
void drawRigid3dImpl(const core::visual::VisualParams* vparams) ;
Expand All @@ -363,9 +360,9 @@ class DiagonalMass : public core::behavior::Mass<DataTypes>

// Specialization for rigids
template <>
SReal DiagonalMass<defaulttype::Rigid3Types>::getPotentialEnergy( const core::MechanicalParams* mparams, const DataVecCoord& x) const;
SReal DiagonalMass<defaulttype::Rigid3Types>::getGravitationalPotentialEnergy( const core::MechanicalParams* mparams, const DataVecCoord& x, const Deriv& g) const;
template <>
SReal DiagonalMass<defaulttype::Rigid2Types>::getPotentialEnergy( const core::MechanicalParams* mparams, const DataVecCoord& x) const;
SReal DiagonalMass<defaulttype::Rigid2Types>::getGravitationalPotentialEnergy( const core::MechanicalParams* mparams, const DataVecCoord& x, const Deriv& g) const;
template <>
void DiagonalMass<defaulttype::Rigid3Types>::draw(const core::visual::VisualParams* vparams);
template <>
Expand Down
48 changes: 9 additions & 39 deletions Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,17 @@ SReal DiagonalMass<DataTypes, GeometricalTypes>::getKineticEnergy( const core::M
}

template <class DataTypes, class GeometricalTypes>
SReal DiagonalMass<DataTypes, GeometricalTypes>::getPotentialEnergy( const core::MechanicalParams* /*mparams*/, const DataVecCoord& x ) const
SReal DiagonalMass<DataTypes, GeometricalTypes>::getGravitationalPotentialEnergy( const core::MechanicalParams* mparams, const DataVecCoord& x, const Deriv& gravity ) const
{
SOFA_UNUSED(mparams);

const MassVector &masses= d_vertexMass.getValue();
helper::ReadAccessor< DataVecCoord > _x = x;
SReal e = 0;
// gravity
type::Vec3d g ( this->getContext()->getGravity() );
Deriv theGravity;
DataTypes::set ( theGravity, g[0], g[1], g[2]);

for (unsigned int i=0; i<masses.size(); i++)
{
e -= type::dot(theGravity, _x[i]) * masses[i];
e -= type::dot(gravity, _x[i]) * masses[i];
}
return e;
}
Expand Down Expand Up @@ -1369,48 +1367,20 @@ void DiagonalMass<DataTypes, GeometricalTypes>::doUpdateInternal()
printMass();
}


template <class DataTypes, class GeometricalTypes>
void DiagonalMass<DataTypes, GeometricalTypes>::addGravityToV(const core::MechanicalParams* mparams, DataVecDeriv& d_v)
{
if(mparams)
{
VecDeriv& v = *d_v.beginEdit();
// gravity
sofa::type::Vec3d g ( this->getContext()->getGravity() );
Deriv theGravity;
DataTypes::set ( theGravity, g[0], g[1], g[2]);
Deriv hg = theGravity * typename DataTypes::Real(sofa::core::mechanicalparams::dt(mparams));

for (unsigned int i=0; i<v.size(); i++)
{
v[i] += hg;
}
d_v.endEdit();
}
}


template <class DataTypes, class GeometricalTypes>
void DiagonalMass<DataTypes, GeometricalTypes>::addForce(const core::MechanicalParams* /*mparams*/, DataVecDeriv& f, const DataVecCoord& , const DataVecDeriv& )
void DiagonalMass<DataTypes, GeometricalTypes>::addGravitationalForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v, const Deriv& gravity)
{
//if gravity was added separately (in solver's "solve" method), then nothing to do here
if(this->m_separateGravity.getValue())
return;
SOFA_UNUSED(mparams);
SOFA_UNUSED(x);
SOFA_UNUSED(v);

const MassVector &masses= d_vertexMass.getValue();
helper::WriteOnlyAccessor< DataVecDeriv > _f = f;

// gravity
sofa::type::Vec3d g ( this->getContext()->getGravity() );
Deriv theGravity;
DataTypes::set ( theGravity, g[0], g[1], g[2]);


// add weight and inertia force
for (unsigned int i=0; i<masses.size(); i++)
{
_f[i] += theGravity*masses[i];
_f[i] += gravity*masses[i];
}
}

Expand Down
12 changes: 6 additions & 6 deletions Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Vec6 MeshMatrixMass<Vec3Types>::getMomentum ( const core::MechanicalParams*, con
for( unsigned int i=0 ; i<v.size() ; i++ )
{
Deriv linearMomentum = v[i] * vertexMass[i];
for( Index j=0 ; j<DataTypes::spatial_dimensions ; ++j ) momentum[j] += linearMomentum[j];
for( Index j=0 ; j<Vec3Types::spatial_dimensions ; ++j ) momentum[j] += linearMomentum[j];
Deriv angularMomentum = cross( x[i], linearMomentum );
for( Index j=0 ; j<DataTypes::spatial_dimensions ; ++j ) momentum[3+j] += angularMomentum[j];
for( Index j=0 ; j<Vec3Types::spatial_dimensions ; ++j ) momentum[3+j] += angularMomentum[j];
}

const auto& edges = l_topology->getEdges();
Expand All @@ -58,14 +58,14 @@ Vec6 MeshMatrixMass<Vec3Types>::getMomentum ( const core::MechanicalParams*, con
const MassType m = edgeMass[i] * static_cast<MassType>(0.5);

Deriv linearMomentum = v[v0] * m;
for( Index j=0 ; j<DataTypes::spatial_dimensions ; ++j ) momentum[j] += linearMomentum[j];
for( Index j=0 ; j<Vec3Types::spatial_dimensions ; ++j ) momentum[j] += linearMomentum[j];
Deriv angularMomentum = cross( x[v0], linearMomentum );
for( Index j=0 ; j<DataTypes::spatial_dimensions ; ++j ) momentum[3+j] += angularMomentum[j];
for( Index j=0 ; j<Vec3Types::spatial_dimensions ; ++j ) momentum[3+j] += angularMomentum[j];

linearMomentum = v[v1] * m;
for( Index j=0 ; j<DataTypes::spatial_dimensions ; ++j ) momentum[j] += linearMomentum[j];
for( Index j=0 ; j<Vec3Types::spatial_dimensions ; ++j ) momentum[j] += linearMomentum[j];
angularMomentum = cross( x[v1], linearMomentum );
for( Index j=0 ; j<DataTypes::spatial_dimensions ; ++j ) momentum[3+j] += angularMomentum[j];
for( Index j=0 ; j<Vec3Types::spatial_dimensions ; ++j ) momentum[3+j] += angularMomentum[j];
}

return momentum;
Expand Down
8 changes: 3 additions & 5 deletions Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,14 @@ class MeshMatrixMass : public core::behavior::Mass<DataTypes>

void accFromF(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f) override; // This function can't be used as it use M^-1

void addForce(const core::MechanicalParams*, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override;
void addGravitationalForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v, const Deriv& gravity) override; ///< Mg force in a homogeneous gravity field

SReal getKineticEnergy(const core::MechanicalParams*, const DataVecDeriv& v) const override; ///< vMv/2 using dof->getV() override
SReal getGravitationalPotentialEnergy(const core::MechanicalParams*, const DataVecCoord& x, const Deriv& gravity) const override; ///< Mgx potential in a uniform gravity field, null at origin

SReal getPotentialEnergy(const core::MechanicalParams*, const DataVecCoord& x) const override; ///< Mgx potential in a uniform gravity field, null at origin
SReal getKineticEnergy(const core::MechanicalParams*, const DataVecDeriv& v) const override; ///< vMv/2 using dof->getV() override

type::Vec6 getMomentum(const core::MechanicalParams* mparams, const DataVecCoord& x, const DataVecDeriv& v) const override; ///< (Mv,cross(x,Mv)) override

void addGravityToV(const core::MechanicalParams* mparams, DataVecDeriv& d_v) override;

bool isDiagonal() const override { return isLumped(); }


Expand Down
52 changes: 9 additions & 43 deletions Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2076,25 +2076,18 @@ void MeshMatrixMass<DataTypes, GeometricalTypes>::accFromF(const core::Mechanica


template <class DataTypes, class GeometricalTypes>
void MeshMatrixMass<DataTypes, GeometricalTypes>::addForce(const core::MechanicalParams*, DataVecDeriv& vf, const DataVecCoord& , const DataVecDeriv& )
void MeshMatrixMass<DataTypes, GeometricalTypes>::addGravitationalForce(const core::MechanicalParams* mparams, DataVecDeriv& vf, const DataVecCoord& x, const DataVecDeriv& v, const Deriv& gravity )
{

//if gravity was added separately (in solver's "solve" method), then nothing to do here
if(this->m_separateGravity.getValue())
return ;
SOFA_UNUSED(mparams);
SOFA_UNUSED(x);
SOFA_UNUSED(v);

helper::WriteAccessor< DataVecDeriv > f = vf;

const auto &vertexMass= d_vertexMass.getValue();

// gravity
type::Vec3d g ( this->getContext()->getGravity() );
Deriv theGravity;
DataTypes::set ( theGravity, g[0], g[1], g[2]);

// add weight and inertia force
for (unsigned int i=0; i<f.size(); ++i)
f[i] += theGravity * vertexMass[i] * m_massLumpingCoeff;
f[i] += gravity * vertexMass[i] * m_massLumpingCoeff;
}


Expand Down Expand Up @@ -2130,20 +2123,17 @@ SReal MeshMatrixMass<DataTypes, GeometricalTypes>::getKineticEnergy( const core:


template <class DataTypes, class GeometricalTypes>
SReal MeshMatrixMass<DataTypes, GeometricalTypes>::getPotentialEnergy( const core::MechanicalParams*, const DataVecCoord& vx) const
SReal MeshMatrixMass<DataTypes, GeometricalTypes>::getGravitationalPotentialEnergy( const core::MechanicalParams* mparams, const DataVecCoord& vx, const Deriv& gravity) const
{
SOFA_UNUSED(mparams);

const auto &vertexMass= d_vertexMass.getValue();

helper::ReadAccessor< DataVecCoord > x = vx;

SReal e = 0;
// gravity
type::Vec3d g ( this->getContext()->getGravity() );
Deriv theGravity;
DataTypes::set ( theGravity, g[0], g[1], g[2]);

for (unsigned int i=0; i<x.size(); i++)
e -= dot(theGravity,x[i])*vertexMass[i] * m_massLumpingCoeff;
e -= dot(gravity,x[i])*vertexMass[i] * m_massLumpingCoeff;

return e;
}
Expand All @@ -2157,30 +2147,6 @@ type::Vec6 MeshMatrixMass<DataTypes, GeometricalTypes>::getMomentum ( const core
}



template <class DataTypes, class GeometricalTypes>
void MeshMatrixMass<DataTypes, GeometricalTypes>::addGravityToV(const core::MechanicalParams* mparams, DataVecDeriv& d_v)
{
if(this->mstate && mparams)
{
VecDeriv& v = *d_v.beginEdit();

// gravity
type::Vec3d g ( this->getContext()->getGravity() );
Deriv theGravity;
DataTypes::set ( theGravity, g[0], g[1], g[2]);
Deriv hg = theGravity * (typename DataTypes::Real(sofa::core::mechanicalparams::dt(mparams)));

for (unsigned int i=0; i<v.size(); i++)
v[i] += hg;
d_v.endEdit();
}

}




template <class DataTypes, class GeometricalTypes>
void MeshMatrixMass<DataTypes, GeometricalTypes>::addMToMatrix(const core::MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix)
{
Expand Down
Loading