Skip to content

Commit

Permalink
Merge branch 'master' into fix_find_assimp_cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
bakpaul authored Jan 11, 2024
2 parents c850cb0 + 4abcbe6 commit 594132f
Show file tree
Hide file tree
Showing 798 changed files with 17,869 additions and 221,520 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/pr-timing-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Check PR Age
on:
pull_request:
types:
- synchronize
- opened
- reopened
- labeled
- unlabeled


jobs:

check_labels:
name: Check labels
runs-on: ubuntu-latest
steps:
- name: Check Labels and Age
id: check_labels_and_comment
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get PR labels
const labels = context.payload.pull_request.labels.map(label => label.name);
// Define the fast merge label
const fastMergeFlag = ['pr: fast merge'];
// Check if any label fits fast merge
const isFastMerge = labels.some(label => fastMergeFlag.includes(label));
// If regular PR (not fast merge), check PR age
if (!isFastMerge) {
const creationDate = new Date(context.payload.pull_request.created_at);
const currentDate = new Date();
// Check if the PR is more than 7 days old
const daysDiff = Math.floor((currentDate - creationDate) / (1000 * 60 * 60 * 24));
if (daysDiff < 7) {
core.setFailed("PR is less than 7 days old and it is not flagged as 'pr: fast merge'");
} else {
console.log('PR is more than 7 days old');
}
} else {
console.log("PR is flagged as 'pr: fast merge'");
}
32 changes: 32 additions & 0 deletions .github/workflows/stale_github_discussions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Stale GitHub Discussions

on:
workflow_dispatch:
schedule:
- cron: '0 6 * * 1' # Every Monday at 6:00 AM UTC (8:00 AM CET)

jobs:
run:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10' # Use the desired Python version

- name: Install dependencies
run: |
pip install python-graphql-client
pip install python-dateutil
working-directory: ${{ github.workspace }}

- name: Run script comment-close-old-discussions.py
run: |
python scripts/comment-close-old-discussions.py
working-directory: ${{ github.workspace }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

<br/>

[![Documentation](https://img.shields.io/badge/doc-on_website-green.svg)](https://www.sofa-framework.org/community/doc/)
[![Support](https://img.shields.io/badge/support-on_GitHub_Discussions-blue.svg)](https://github.com/sofa-framework/sofa/discussions)
[![Gitter](https://img.shields.io/badge/chat-on_Gitter-ff69b4.svg)](https://gitter.im/sofa-framework/sofa)
[![Contact](https://img.shields.io/badge/contact-on_website-orange.svg)](https://www.sofa-framework.org/consortium/contact/)
[![Documentation](https://img.shields.io/badge/doc-on_website-brightgreen.svg)](https://www.sofa-framework.org/community/doc/)
[![Support](https://img.shields.io/badge/support-on_GitHub_Discussions-orange.svg)](https://github.com/sofa-framework/sofa/discussions)
[![Gitter](https://img.shields.io/badge/chat-on_Gitter-darkred.svg)](https://gitter.im/sofa-framework/sofa)

<a href="https://twitter.com/intent/follow?original_referer=https%3A%2F%2Fpublish.twitter.com%2F%3FbuttonType%3DFollowButton%26query%3Dhttps%253A%252F%252Ftwitter.com%252FSofaFramework%26widget%3DButton&ref_src=twsrc%5Etfw&region=follow_link&screen_name=SofaFramework&tw_p=followbutton"><img src="https://img.shields.io/twitter/follow/SofaFramework?label=Follow%20%40SofaFramework&style=social"></a>
[![Contact](https://img.shields.io/badge/contact-on_website-brightgreen.svg)](https://www.sofa-framework.org/consortium/contact/)
[![we're hiring](https://img.shields.io/badge/we're%20hiring!-join%20us-orange)](https://www.sofa-framework.org/about/jobs/)

## What is SOFA

SOFA is an open source framework targeted at interactive physics simulation, with an emphasis on medical simulation and robotics.
SOFA is an open source framework targeted at interactive physics simulation based on the Finite Element Method (FEM), with an emphasis on medical simulation and robotics.
It is mainly intended for the research community to help foster newer algorithms, but can also be used as an efficient prototyping tool.
SOFA's advanced software architecture allows:
- the creation of complex and evolving simulations by combining new algorithms with existing algorithms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <sofa/core/collision/Contact.h>
#include <sofa/core/collision/Intersection.h>
#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/component/constraint/lagrangian/model/UnilateralInteractionConstraint.h>
#include <sofa/component/constraint/lagrangian/model/UnilateralLagrangianConstraint.h>
#include <sofa/component/collision/response/mapper/BaseContactMapper.h>
#include <sofa/component/collision/response/contact/ContactIdentifier.h>

Expand Down Expand Up @@ -60,7 +60,7 @@ class FrictionContact : public core::collision::Contact, public ContactIdentifie
mapper::ContactMapper<CollisionModel1,DataTypes1> mapper1;
mapper::ContactMapper<CollisionModel2,DataTypes2> mapper2;

constraint::lagrangian::model::UnilateralInteractionConstraint<sofa::defaulttype::Vec3Types>::SPtr m_constraint;
constraint::lagrangian::model::UnilateralLagrangianConstraint<sofa::defaulttype::Vec3Types>::SPtr m_constraint;
core::objectmodel::BaseContext* parent;

Data<double> mu; ///< friction coefficient (0 for frictionless contacts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void FrictionContact<TCollisionModel1,TCollisionModel2,ResponseDataTypes>::activ
{
mmodel2 = mapper2.createMapping(getName().c_str());
}
m_constraint = sofa::core::objectmodel::New<constraint::lagrangian::model::UnilateralInteractionConstraint<defaulttype::Vec3Types> >(mmodel1, mmodel2);
m_constraint = sofa::core::objectmodel::New<constraint::lagrangian::model::UnilateralLagrangianConstraint<defaulttype::Vec3Types> >(mmodel1, mmodel2);
m_constraint->setName( getName() );
setInteractionTags(mmodel1, mmodel2);
m_constraint->setCustomTolerance( tol.getValue() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <sofa/core/collision/Contact.h>
#include <sofa/core/collision/Intersection.h>
#include <sofa/component/constraint/lagrangian/model/BilateralInteractionConstraint.h>
#include <sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h>
#include <sofa/helper/Factory.h>
#include <sofa/component/collision/response/mapper/BaseContactMapper.h>
#include <sofa/component/collision/response/contact/ContactIdentifier.h>
Expand Down Expand Up @@ -58,7 +58,7 @@ class StickContactConstraint : public core::collision::Contact, public ContactId
mapper::ContactMapper<CollisionModel1,DataTypes1> mapper1;
mapper::ContactMapper<CollisionModel2,DataTypes2> mapper2;

constraint::lagrangian::model::BilateralInteractionConstraint<sofa::defaulttype::Vec3Types>::SPtr m_constraint;
constraint::lagrangian::model::BilateralLagrangianConstraint<sofa::defaulttype::Vec3Types>::SPtr m_constraint;
core::objectmodel::BaseContext* parent;

std::vector< sofa::core::collision::DetectionOutput* > contacts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void StickContactConstraint<TCollisionModel1,TCollisionModel2>::activateMappers(
msg_info() << "Creating StickContactConstraint bilateral constraints";
MechanicalState1* mstate1 = mapper1.createMapping(mapper::GenerateStringID::generate().c_str());
MechanicalState2* mstate2 = mapper2.createMapping(mapper::GenerateStringID::generate().c_str());
m_constraint = sofa::core::objectmodel::New<constraint::lagrangian::model::BilateralInteractionConstraint<defaulttype::Vec3Types> >(mstate1, mstate2);
m_constraint = sofa::core::objectmodel::New<constraint::lagrangian::model::BilateralLagrangianConstraint<defaulttype::Vec3Types> >(mstate1, mstate2);
m_constraint->setName( getName() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_CORRECTION_API void UncoupledConstraintCorr
massValue = um->getVertexMass();
usedComp.push_back(odeFactor / massValue.mass);
msg_info() << "Compliance matrix is evaluated using the UniformMass";

}
else
{
Expand All @@ -109,6 +108,8 @@ SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_CORRECTION_API void UncoupledConstraintCorr
usedComp.push_back( odeFactor * massValue.invInertiaMassMatrix[1][2]);
usedComp.push_back( odeFactor * massValue.invInertiaMassMatrix[2][2]);
compliance.setValue(usedComp);

msg_info() << "\'compliance\' equals: " << compliance.getValue();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <sofa/linearalgebra/BaseMatrix.h>
#include <sofa/core/topology/TopologyData.inl>
#include <sofa/core/ConstraintParams.h>
#include <sofa/type/isRigidType.h>

namespace sofa::component::constraint::lagrangian::correction
{
Expand Down Expand Up @@ -110,6 +111,68 @@ UncoupledConstraintCorrection<DataTypes>::UncoupledConstraintCorrection(sofa::co
, l_topology(initLink("topology", "link to the topology container"))
, m_pOdeSolver(nullptr)
{
// Check defaultCompliance and entries of the compliance vector are not zero
core::objectmodel::Base::addUpdateCallback("checkNonZeroComplianceInput", {&defaultCompliance, &compliance}, [this](const core::DataTracker& t)
{
// Update of the defaultCompliance data
if(t.hasChanged(defaultCompliance))
{
if(defaultCompliance.getValue() == 0.0)
{
msg_error() << "Zero defaultCompliance is set: this will cause the constraint resolution to diverge";
return sofa::core::objectmodel::ComponentState::Invalid;
}
return sofa::core::objectmodel::ComponentState::Valid;
}
// Update of the compliance data
else
{
// Case: soft body
if constexpr (!sofa::type::isRigidType<DataTypes>())
{
const VecReal &comp = compliance.getValue();
if (std::any_of(comp.begin(), comp.end(), [](const Real c) { return c == 0; }))
{
msg_error() << "Zero values set in the compliance vector: this will cause the constraint resolution to diverge";
return sofa::core::objectmodel::ComponentState::Invalid;
}
}
// Case: rigid body
else
{
const VecReal &comp = compliance.getValue();
sofa::Size compSize = comp.size();

if (compSize % 7 != 0)
{
msg_error() << "Compliance vector should be a multiple of 7 in rigid case (1 for translation dofs, and 6 for the rotation matrix)";
return sofa::core::objectmodel::ComponentState::Invalid;
}

for(auto i = 0; i < comp.size() ; i += 7)
{
if(comp[i] == 0.)
{
msg_error() << "Zero compliance set on translation dofs: this will cause the constraint resolution to diverge (compliance[" << i << "])";
return sofa::core::objectmodel::ComponentState::Invalid;
}
// Check if the translational compliance and the diagonal values of the rotation compliance matrix are non zero
// In Rigid case, the inertia matrix generates this 3x3 rotation compliance matrix
// In the compliance vector comp, SOFA stores:
// - the translational compliance (comp[0])
// - the triangular part of the rotation compliance matrix: r[0,0]=comp[1],r[0,1],r[0,2],r[1,1]=comp[4],r[1,2],r[2,2]=comp[6]
if(comp[i+1] == 0. || comp[i+4] == 0. || comp[i+6] == 0.)
{
msg_error() << "Zero compliance set on rotation dofs (matrix diagonal): this will cause the constraint resolution to diverge (compliance[" << i << "])";
return sofa::core::objectmodel::ComponentState::Invalid;
}
}
}
return sofa::core::objectmodel::ComponentState::Valid;
}

}, {}
);
}

template<class DataTypes>
Expand All @@ -123,7 +186,7 @@ void UncoupledConstraintCorrection<DataTypes>::init()
{
Inherit::init();

if( !defaultCompliance.isSet() && !compliance.isSet() )
if (!defaultCompliance.isSet() && !compliance.isSet())
{
msg_warning() << "Neither the \'defaultCompliance\' nor the \'compliance\' data is set, please set one to define your compliance matrix";
}
Expand Down Expand Up @@ -205,6 +268,8 @@ void UncoupledConstraintCorrection<DataTypes>::init()
}
d_useOdeSolverIntegrationFactors.setReadOnly(true);
}

this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
}

template <class DataTypes>
Expand All @@ -216,6 +281,9 @@ void UncoupledConstraintCorrection<DataTypes>::reinit()
template<class DataTypes>
void UncoupledConstraintCorrection<DataTypes>::getComplianceWithConstraintMerge(linearalgebra::BaseMatrix* Wmerged, std::vector<int> &constraint_merge)
{
if(!this->isComponentStateValid())
return;

helper::WriteAccessor<Data<MatrixDeriv> > constraintsData = *this->mstate->write(core::MatrixDerivId::constraintJacobian());
MatrixDeriv& constraints = constraintsData.wref();

Expand Down Expand Up @@ -286,6 +354,9 @@ void UncoupledConstraintCorrection<DataTypes>::getComplianceWithConstraintMerge(
template<class DataTypes>
void UncoupledConstraintCorrection<DataTypes>::addComplianceInConstraintSpace(const sofa::core::ConstraintParams * cparams, sofa::linearalgebra::BaseMatrix *W)
{
if(!this->isComponentStateValid())
return;

const MatrixDeriv& constraints = cparams->readJ(this->mstate)->getValue() ;
VecReal comp = compliance.getValue();
Real comp0 = defaultCompliance.getValue();
Expand Down Expand Up @@ -402,6 +473,9 @@ void UncoupledConstraintCorrection<DataTypes>::addComplianceInConstraintSpace(co
template<class DataTypes>
void UncoupledConstraintCorrection<DataTypes>::getComplianceMatrix(linearalgebra::BaseMatrix *m) const
{
if(!this->isComponentStateValid())
return;

const VecReal& comp = compliance.getValue();
const Real comp0 = defaultCompliance.getValue();
const unsigned int s = this->mstate->getSize(); // comp.size();
Expand Down Expand Up @@ -438,6 +512,9 @@ void UncoupledConstraintCorrection<DataTypes>::computeMotionCorrection(const cor
{
SOFA_UNUSED(cparams);

if(!this->isComponentStateValid())
return;

auto writeDx = sofa::helper::getWriteAccessor( *dx[this->getMState()].write() );
const Data<VecDeriv>& f_d = *f[this->getMState()].read();
computeDx(f_d, writeDx.wref());
Expand All @@ -447,6 +524,8 @@ void UncoupledConstraintCorrection<DataTypes>::computeMotionCorrection(const cor
template<class DataTypes>
void UncoupledConstraintCorrection<DataTypes>::applyMotionCorrection(const core::ConstraintParams *cparams, Data< VecCoord > &x_d, Data< VecDeriv > &v_d, Data<VecDeriv>& dx_d, const Data< VecDeriv > &correction_d)
{
if(!this->isComponentStateValid())
return;

auto dx = sofa::helper::getWriteAccessor(dx_d);
auto correction = sofa::helper::getReadAccessor(correction_d);
Expand Down Expand Up @@ -479,6 +558,9 @@ void UncoupledConstraintCorrection<DataTypes>::applyMotionCorrection(const core:
template<class DataTypes>
void UncoupledConstraintCorrection<DataTypes>::applyPositionCorrection(const core::ConstraintParams *cparams, Data< VecCoord > &x_d, Data< VecDeriv >& dx_d, const Data< VecDeriv > &correction_d)
{
if(!this->isComponentStateValid())
return;

auto dx = sofa::helper::getWriteAccessor(dx_d);
auto correction = sofa::helper::getReadAccessor(correction_d);

Expand All @@ -504,6 +586,9 @@ void UncoupledConstraintCorrection<DataTypes>::applyPositionCorrection(const cor
template<class DataTypes>
void UncoupledConstraintCorrection<DataTypes>::applyVelocityCorrection(const core::ConstraintParams *cparams, Data< VecDeriv > &v_d, Data<VecDeriv>& dv_d, const Data< VecDeriv > &correction_d)
{
if(!this->isComponentStateValid())
return;

auto dx = sofa::helper::getWriteAccessor(dv_d);
auto correction = sofa::helper::getReadAccessor(correction_d);

Expand All @@ -529,6 +614,9 @@ void UncoupledConstraintCorrection<DataTypes>::applyVelocityCorrection(const cor
template<class DataTypes>
void UncoupledConstraintCorrection<DataTypes>::applyContactForce(const linearalgebra::BaseVector *f)
{
if(!this->isComponentStateValid())
return;

helper::WriteAccessor<Data<VecDeriv> > forceData = *this->mstate->write(core::VecDerivId::externalForce());
VecDeriv& force = forceData.wref();
const MatrixDeriv& constraints = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue();
Expand Down Expand Up @@ -657,6 +745,9 @@ void UncoupledConstraintCorrection<DataTypes>::addConstraintDisplacement(SReal *
/// constraint_force contains the force applied on dof involved with the contact
/// TODO : compute a constraint_disp that is updated each time a new force is provided !

if(!this->isComponentStateValid())
return;

const MatrixDeriv& constraints = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue();

for (int id = begin; id <= end; id++)
Expand Down
23 changes: 18 additions & 5 deletions Sofa/Component/Constraint/Lagrangian/Model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,30 @@ set(HEADER_FILES
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/StopperConstraint.inl
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UniformConstraint.h
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UniformConstraint.inl
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UnilateralConstraintResolution.h
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UnilateralInteractionConstraint.h
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UnilateralInteractionConstraint.inl

${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/BilateralLagrangianConstraint.h
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/BilateralLagrangianConstraint.inl
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/SlidingLagrangianConstraint.h
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/SlidingLagrangianConstraint.inl
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/StopperLagrangianConstraint.h
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/StopperLagrangianConstraint.inl
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UniformLagrangianConstraint.h
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UniformLagrangianConstraint.inl
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UnilateralLagrangianConstraint.h
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UnilateralLagrangianConstraint.inl
)

set(SOURCE_FILES
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/init.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/BilateralInteractionConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/SlidingConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/StopperConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UniformConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UnilateralInteractionConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/BilateralLagrangianConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/SlidingLagrangianConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/StopperLagrangianConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UniformLagrangianConstraint.cpp
${SOFACOMPONENTCONSTRAINTLAGRANGIANMODEL_SOURCE_DIR}/UnilateralLagrangianConstraint.cpp

)

sofa_find_package(Sofa.Simulation.Core REQUIRED)
Expand Down
Loading

0 comments on commit 594132f

Please sign in to comment.