Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mass,MechanicalLoad] Use enumeration to clarify the code #4918

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8daef1a
[Mass] Replace doUpdateInternal by callback: UniformMass
hugtalbot Jun 7, 2023
96908f7
fix initial view in example scene using InteractiveCamera
hugtalbot Jun 7, 2023
a0be3f2
add call to componentState in accFromF and buildMassMatrix
hugtalbot Jun 7, 2023
572579a
Apply suggestions from code review
hugtalbot Jun 7, 2023
afd56eb
Use function isComponentStateValid
alxbilger Mar 29, 2024
a700c53
remove empty override
alxbilger Mar 29, 2024
c55918f
Fix typo in comment
alxbilger Mar 29, 2024
bdcfe71
remove useless comment
alxbilger Mar 29, 2024
9efc3ff
take reviews into account: separate callbacks, add boolean switch
hugtalbot Apr 4, 2024
a56d0ea
minor clean
hugtalbot Apr 4, 2024
8cd9231
additional changes in UniformMass
hugtalbot Apr 4, 2024
23ffce1
update associated test
hugtalbot Apr 4, 2024
0126565
Work on init and callback to get a clean state after init, fix test
hugtalbot Apr 5, 2024
01955c4
Fix tests attempt 1
hugtalbot Apr 5, 2024
3e2c984
fix createRegularGridScene using UniformMass
hugtalbot Apr 5, 2024
102aeaa
fix scene without specifying a mass
hugtalbot Apr 5, 2024
4301271
Remove uses of mass data replaced with vertexMass
hugtalbot Apr 8, 2024
b20193f
Update Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl
hugtalbot Apr 10, 2024
cc557ed
merge with master 20240812
hugtalbot Aug 12, 2024
f6ff564
minor change on ConstantFF comment and config.h.in
hugtalbot Aug 12, 2024
f72c957
remove reinit, add comments and fix typo in UM
hugtalbot Aug 12, 2024
e4fc67f
simplify code regarding SingleStateAccessor
hugtalbot Aug 12, 2024
3b1cc06
[Mass,MechanicalLoad] Use enumeration to clarify the code
hugtalbot Aug 13, 2024
a90bbfd
use enum class, taking reviews into account
hugtalbot Aug 13, 2024
12f327c
fit reviewer expected format
hugtalbot Aug 13, 2024
d50af0c
Apply suggestions from code review
hugtalbot Aug 13, 2024
b7c7293
Remove call to component state to prevent triggering callbacks
hugtalbot Aug 13, 2024
eb53a8d
Fix test
hugtalbot Aug 14, 2024
077a0b4
merge with #3927
hugtalbot Aug 14, 2024
9371ffc
Merge branch 'master' into 202408_generalize_enumeration
hugtalbot Aug 14, 2024
7a86d8c
Merge branch 'master' into 202408_generalize_enumeration
fredroy Aug 19, 2024
d56029b
Remove default instantiation in class declaration
bakpaul Aug 21, 2024
8174abb
Merge branch 'master' into 202408_generalize_enumeration
bakpaul Aug 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ using namespace core::objectmodel;
template<typename DataTypes>
void createUniformMass(simulation::Node::SPtr node, component::statecontainer::MechanicalObject<DataTypes>& /*dofs*/)
{
node->addObject(New<component::mass::UniformMass<DataTypes> >());
typename component::mass::UniformMass<DataTypes>::SPtr uniformMass = New<component::mass::UniformMass<DataTypes> >();
uniformMass->d_totalMass.setValue(1.0);
node->addObject(uniformMass);
}

template <typename _DataTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ using core::objectmodel::New;
template<typename DataTypes>
void createUniformMass(simulation::Node::SPtr node, component::statecontainer::MechanicalObject<DataTypes>& /*dofs*/)
{
node->addObject(New<component::mass::UniformMass<DataTypes> >());
typename component::mass::UniformMass<DataTypes>::SPtr uniformMass = New<component::mass::UniformMass<DataTypes> >();
uniformMass->d_totalMass.setValue(1.0);
node->addObject(uniformMass);
}

template <typename _DataTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ using namespace core::objectmodel;
template<typename DataTypes>
void createUniformMass(simulation::Node::SPtr node, component::statecontainer::MechanicalObject<DataTypes>& /*dofs*/)
{
node->addObject(New<component::mass::UniformMass<DataTypes> >());
typename component::mass::UniformMass<DataTypes>::SPtr uniformMass = New<component::mass::UniformMass<DataTypes> >();
uniformMass->d_totalMass.setValue(1.0);
node->addObject(uniformMass);
}

template <typename _DataTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ TEST(SparseLDLSolver, TopologyChangeEmptyMState)
sofa::simpleapi::createObject(root, "PointSetTopologyContainer", {{"position", "0 0 0"}});
sofa::simpleapi::createObject(root, "PointSetTopologyModifier");
sofa::simpleapi::createObject(root, "MechanicalObject", {{"template", "Vec3"}});
sofa::simpleapi::createObject(root, "UniformMass");
sofa::simpleapi::createObject(root, "UniformMass", {{"totalMass", "1.0"}});
sofa::simpleapi::createObject(root, "TopologicalChangeProcessor",
{{"useDataInputs", "true"}, {"timeToRemove", "0.05"},
{"pointsToRemove", "0"}});
Expand Down
19 changes: 14 additions & 5 deletions Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ class UniformMass : public core::behavior::Mass<DataTypes>
Data<SReal> d_totalMass; ///< if >0 : total mass of this body
sofa::core::objectmodel::DataFileName d_filenameMass; ///< a .rigid file to automatically load the inertia matrix and other parameters

/// Visualization-related data
Data<bool> d_showCenterOfGravity; ///< display the center of gravity of the system
Data<float> d_showAxisSize; ///< factor length of the axis displayed (only used for rigids)

Data<bool> d_computeMappingInertia; ///< to be used if the mass is placed under a mapping
Data<bool> d_showInitialCenterOfGravity; ///< display the initial center of gravity of the system

Data<bool> d_showX0; ///< display the rest positions

/// optional range of local DOF indices. Any computation involving only
Expand All @@ -78,6 +77,14 @@ class UniformMass : public core::behavior::Mass<DataTypes>
DataSetIndex d_indices; ///< optional local DOF indices. Any computation involving only indices outside of this list are discarded
Data<bool> d_preserveTotalMass; ///< Prevent totalMass from decreasing when removing particles.

/// Enumeration specifying which data was used for initialization
enum class InitMethod
{
TOTALMASS,
VERTEXMASS
};
InitMethod m_initMethod = InitMethod::TOTALMASS;
bakpaul marked this conversation as resolved.
Show resolved Hide resolved

////////////////////////// Inherited attributes ////////////////////////////
/// https://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html
/// Bring inherited attributes and function in the current lookup context.
Expand All @@ -87,6 +94,7 @@ class UniformMass : public core::behavior::Mass<DataTypes>
using core::objectmodel::BaseObject::getContext;
////////////////////////////////////////////////////////////////////////////


/// Link to be set to the topology container in the component graph.
SingleLink <UniformMass<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;

Expand Down Expand Up @@ -115,21 +123,22 @@ class UniformMass : public core::behavior::Mass<DataTypes>

void loadRigidMass(const std::string& filename);

void reinit() override;
void init() override;
void initDefaultImpl() ;
void doUpdateInternal() override;

/// @name Check and standard initialization functions from mass information
/// @{
virtual bool checkVertexMass();
virtual void initFromVertexMass();

virtual bool checkTotalMass();
virtual void checkTotalMassInit();
virtual void initFromTotalMass();
/// @}

/// Functions updating data
sofa::core::objectmodel::ComponentState updateFromTotalMass();
sofa::core::objectmodel::ComponentState updateFromVertexMass();

void addMDx(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecDeriv& dx, SReal factor) override;
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;
Expand Down
Loading
Loading