-
Notifications
You must be signed in to change notification settings - Fork 341
[Spring] Add fixed weak constraint and examples #4750
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
Open
bakpaul
wants to merge
31
commits into
sofa-framework:master
Choose a base branch
from
bakpaul:add_fixed_weak_constraint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
7ec50b2
Add fixed weak constraint and examples
bakpaul 01f9faf
Remove nasty using
bakpaul bc1916b
WIP
bakpaul 066c42e
Merge branch 'master' into add_fixed_weak_constraint
bakpaul 01dab0f
Fix compilation
bakpaul f6bb00b
Added base virtualization for restShape spring forcefield. Still need…
bakpaul 19b33f6
Merge branch 'master' into add_fixed_weak_constraint
bakpaul 5daad92
Merge branch 'master' into add_fixed_weak_constraint
bakpaul 06090ff
WIP: SQtill need to unify inint, reinit, bwdinint, enables fixAll and…
bakpaul 909c760
Factorise every method in the FixedWeakConstraint object. Need to spe…
bakpaul 937acc8
Apply changes to RestShapeSpringForceField
bakpaul 0754eb8
apply changes to scenes
bakpaul a3c9866
Merge branch 'master' into add_fixed_weak_constraint
bakpaul a13b3ca
Remove duplication of the topology link in RestShapeSpringForceField
bakpaul 885e980
Squashed commit of the following:
bakpaul aba4fb2
Merge branch 'master' into add_fixed_weak_constraint
bakpaul 21a6198
Merge branch 'master' into add_fixed_weak_constraint
bakpaul 5e455e4
Fix compilation
bakpaul 1985599
Try to fix windows compilation
bakpaul b4e8d43
Avoid using an intermediate expression and directly use the right term
bakpaul eada37f
Squashed commit of the following:
bakpaul bb78caf
Fix compilaiton
bakpaul d00d06c
Merge branch 'master' into add_fixed_weak_constraint
bakpaul ab24025
Use FixedWeakConstraint when possible
bakpaul 70c5c4a
Remove RestshapeSpringFF test because it only tested the FixedWeakCon…
bakpaul 5688b58
Forgot CMakeLists.txt
bakpaul 7542160
Fix one unit test
bakpaul 22ce57b
Merge branch 'master' into add_fixed_weak_constraint
bakpaul fb44a3d
Merge branch 'master' into add_fixed_weak_constraint
bakpaul 2936387
Merge branch 'master' into add_fixed_weak_constraint
bakpaul 46612ef
Fix tests
bakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...nt/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FixedWeakConstraint.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /****************************************************************************** | ||
| * SOFA, Simulation Open-Framework Architecture * | ||
| * (c) 2006 INRIA, USTL, UJF, CNRS, MGH * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify it * | ||
| * under the terms of the GNU Lesser General Public License as published by * | ||
| * the Free Software Foundation; either version 2.1 of the License, or (at * | ||
| * your option) any later version. * | ||
| * * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT * | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * | ||
| * for more details. * | ||
| * * | ||
| * You should have received a copy of the GNU Lesser General Public License * | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
| ******************************************************************************* | ||
| * Authors: The SOFA Team and external contributors (see Authors.txt) * | ||
| * * | ||
| * Contact information: contact@sofa-framework.org * | ||
| ******************************************************************************/ | ||
| #define SOFA_COMPONENT_FORCEFIELD_RESTSHAPESPRINGSFORCEFIELD_CPP | ||
|
|
||
| #include <sofa/component/solidmechanics/spring/FixedWeakConstraint.inl> | ||
|
|
||
| #include <sofa/helper/visual/DrawTool.h> | ||
| #include <sofa/core/ObjectFactory.h> | ||
| #include <sofa/core/behavior/MultiMatrixAccessor.h> | ||
|
|
||
|
|
||
| namespace sofa::component::solidmechanics::spring | ||
| { | ||
|
|
||
| using namespace sofa::type; | ||
| using namespace sofa::defaulttype; | ||
|
|
||
| int FixedWeakConstraintClass = core::RegisterObject("Elastic springs generating forces on degrees of freedom between their current and rest shape position") | ||
| .add< FixedWeakConstraint<Vec6Types> >() | ||
| .add< FixedWeakConstraint<Vec3Types> >() | ||
| .add< FixedWeakConstraint<Vec2Types> >() | ||
| .add< FixedWeakConstraint<Vec1Types> >() | ||
| .add< FixedWeakConstraint<Rigid3Types> >() | ||
|
|
||
| ; | ||
|
|
||
| template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<Vec6Types>; | ||
| template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<Vec3Types>; | ||
| template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<Vec2Types>; | ||
| template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<Vec1Types>; | ||
| template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<Rigid3Types>; | ||
|
|
||
|
|
||
| } // namespace sofa::component::solidmechanics::spring | ||
109 changes: 109 additions & 0 deletions
109
...nent/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FixedWeakConstraint.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /****************************************************************************** | ||
| * SOFA, Simulation Open-Framework Architecture * | ||
| * (c) 2006 INRIA, USTL, UJF, CNRS, MGH * | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify it * | ||
| * under the terms of the GNU Lesser General Public License as published by * | ||
| * the Free Software Foundation; either version 2.1 of the License, or (at * | ||
| * your option) any later version. * | ||
| * * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT * | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * | ||
| * for more details. * | ||
| * * | ||
| * You should have received a copy of the GNU Lesser General Public License * | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
| ******************************************************************************* | ||
| * Authors: The SOFA Team and external contributors (see Authors.txt) * | ||
| * * | ||
| * Contact information: contact@sofa-framework.org * | ||
| ******************************************************************************/ | ||
| #pragma once | ||
| #include <sofa/component/solidmechanics/spring/config.h> | ||
|
|
||
| #include <sofa/type/RGBAColor.h> | ||
|
|
||
| #include <sofa/core/behavior/ForceField.h> | ||
| #include <sofa/core/objectmodel/Data.h> | ||
| #include <sofa/core/topology/TopologySubsetIndices.h> | ||
| #include <sofa/type/vector.h> | ||
| #include <sofa/linearalgebra/EigenSparseMatrix.h> | ||
|
|
||
|
|
||
| namespace sofa::component::solidmechanics::spring | ||
| { | ||
|
|
||
| /** | ||
| * @brief This class describes a simple elastic springs ForceField between DOFs positions and rest positions. | ||
| * | ||
| * Springs are applied to given degrees of freedom between their current positions and their rest shape positions. | ||
| * An external MechanicalState reference can also be passed to the ForceField as rest shape position. | ||
| */ | ||
| template<class DataTypes> | ||
| class FixedWeakConstraint : public core::behavior::ForceField<DataTypes> | ||
| { | ||
| public: | ||
| SOFA_CLASS(SOFA_TEMPLATE(FixedWeakConstraint, DataTypes), SOFA_TEMPLATE(core::behavior::ForceField, DataTypes)); | ||
|
|
||
| typedef core::behavior::ForceField<DataTypes> Inherit; | ||
| typedef typename DataTypes::VecCoord VecCoord; | ||
| typedef typename DataTypes::VecDeriv VecDeriv; | ||
| typedef typename DataTypes::Coord Coord; | ||
| typedef typename DataTypes::CPos CPos; | ||
| typedef typename DataTypes::Deriv Deriv; | ||
| typedef typename DataTypes::Real Real; | ||
| typedef type::vector< sofa::Index > VecIndex; | ||
| typedef sofa::core::topology::TopologySubsetIndices DataSubsetIndex; | ||
| typedef type::vector< Real > VecReal; | ||
|
|
||
| static constexpr sofa::Size spatial_dimensions = Coord::spatial_dimensions; | ||
| static constexpr sofa::Size coord_total_size = Coord::total_size; | ||
|
|
||
| typedef core::objectmodel::Data<VecCoord> DataVecCoord; | ||
| typedef core::objectmodel::Data<VecDeriv> DataVecDeriv; | ||
|
|
||
| typedef sofa::core::topology::TopologySubsetIndices SetIndex; | ||
|
|
||
| SetIndex d_indices; | ||
| Data<bool> d_fixAll; | ||
| Data< Real > d_stiffness; ///< stiffness values between the actual position and the rest shape position | ||
| Data< Real > d_angularStiffness; ///< angularStiffness assigned when controlling the rotation of the points | ||
| Data< bool > d_drawSpring; ///< draw Spring | ||
| Data< sofa::type::RGBAColor > d_springColor; ///< spring color. (default=[0.0,1.0,0.0,1.0]) | ||
|
|
||
| linearalgebra::EigenBaseSparseMatrix<typename DataTypes::Real> matS; | ||
| /// Link to be set to the topology container in the component graph. | ||
| SingleLink<FixedWeakConstraint<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; | ||
|
|
||
| protected: | ||
| FixedWeakConstraint(); | ||
| bool checkOutOfBoundsIndices(); | ||
|
|
||
| public: | ||
| virtual void init() override; | ||
|
|
||
| /// Add the forces. | ||
| void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override; | ||
| void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& df, const DataVecDeriv& dx) override; | ||
| SReal getPotentialEnergy(const core::MechanicalParams* mparams, const DataVecCoord& x) const override; | ||
|
|
||
| /// Brings ForceField contribution to the global system stiffness matrix. | ||
| void addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) override; | ||
| void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; | ||
| void buildDampingMatrix(core::behavior::DampingMatrix* matrix) override; | ||
|
|
||
| void draw(const core::visual::VisualParams* vparams) override; | ||
|
|
||
|
|
||
| }; | ||
|
|
||
| #if !defined(SOFA_COMPONENT_FORCEFIELD_RESTSHAPESPRINGSFORCEFIELD_CPP) | ||
| extern template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<sofa::defaulttype::Vec6Types>; | ||
| extern template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<sofa::defaulttype::Vec3Types>; | ||
| extern template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<sofa::defaulttype::Vec2Types>; | ||
| extern template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<sofa::defaulttype::Vec1Types>; | ||
| extern template class SOFA_COMPONENT_SOLIDMECHANICS_SPRING_API FixedWeakConstraint<sofa::defaulttype::Rigid3Types>; | ||
| #endif | ||
|
|
||
| } // namespace sofa::component::solidmechanics::spring |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.