Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 67 additions & 0 deletions q
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
* main
master
tutorial-cleanning
v25.12
remotes/appa/main
remotes/appa/master
remotes/appa/tutorial-cleanning
remotes/origin/Dev
remotes/origin/DevPlasticity
remotes/origin/HEAD -> origin/master
remotes/origin/Tutorial
remotes/origin/actuatorBranch
remotes/origin/bakpaul_new_registration_mechanism
remotes/origin/cleanning/clean_scenes
remotes/origin/cosseratExtension-review2
remotes/origin/cosseratExtention-review
remotes/origin/cosseratState
remotes/origin/dev_coaxial_beam_model
remotes/origin/dev_coaxial_beam_model_v2
remotes/origin/feature/comprehensive-improvements
remotes/origin/feature/cosserat-dependency
remotes/origin/feature/cosserat-in-global-frame
remotes/origin/feature/cosserat-tests
remotes/origin/feature/differentiability-refactor
remotes/origin/feature/differentiable-liegroups
remotes/origin/feature/doc-and-quality-improvements
remotes/origin/feature/hookeseraPCS-force-field-v2
remotes/origin/feature/improve-basecosserat-mapping
remotes/origin/feature/lie-groups
remotes/origin/feature/liegroup-based-mappings
remotes/origin/feature/liegroups-python-bindings
remotes/origin/feature/liegroups-sola-improvements
remotes/origin/feature/plugin-reorganization
remotes/origin/feature/reorganize-python-bindings
remotes/origin/fixLinkWithSoftRobot
remotes/origin/guillaume_Samain
remotes/origin/hugtalbot-patch-1
remotes/origin/hugtalbot-patch-2
remotes/origin/hugtalbot-patch-3
remotes/origin/main
remotes/origin/master
remotes/origin/needleModule
remotes/origin/pr-add-tests
remotes/origin/pr-minor-fix-warnings
remotes/origin/pr-refactor-step3
remotes/origin/pr-synchronize-with-sofa-master
remotes/origin/refactor-src-organization
remotes/origin/refactor/mapping-components-cleanup
remotes/origin/revert-38-cosseratState
remotes/origin/testForVincent
remotes/origin/tutorial-june-2025
remotes/origin/update_python_prefabs
remotes/origin/update_python_prefabs_w_master_chpick_pr-add-tests
remotes/origin/update_test_scenes
remotes/origin/updateversion
remotes/origin/v20.12
remotes/origin/v21.12
remotes/origin/v22.06
remotes/origin/v22.12
remotes/origin/v23.06
remotes/origin/v23.12
remotes/origin/v24.06
remotes/origin/v24.12
remotes/origin/v24.12_update_workflow
remotes/origin/v25.06
remotes/origin/v25.12
remotes/origin/v25.12_update_workflow
32 changes: 19 additions & 13 deletions src/Cosserat/forcefield/standard/BeamHookeLawForceField.inl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace sofa::component::forcefield {
d_GA(initData(&d_GA, "GA", "The inertia parameter, GA")),
d_EA(initData(&d_EA, "EA", "The inertia parameter, EA")),
d_EI(initData(&d_EI, "EI", "The inertia parameter, EI")) {
compute_df = false;

compute_df = true;//@appa: initialize compute_df at true (by default)
}

template<typename DataTypes>
Expand All @@ -86,7 +87,7 @@ namespace sofa::component::forcefield {
recalculating the properties related to the cross-section of the beams. It
calculates the area moment of inertia (Iy and Iz), the polar moment of
inertia (J), and the cross-sectional area (A). These calculations depend on
the chosen cross-section shape, either circular or rectangular. T he formulas
the chosen cross-section shape, either circular or rectangular. The formulas
used for these calculations are based on standard equations for these
properties.*/
template<typename DataTypes>
Expand Down Expand Up @@ -153,6 +154,7 @@ namespace sofa::component::forcefield {
SOFA_UNUSED(d_v);
SOFA_UNUSED(mparams);


if (!this->getMState()) {
msg_info("BeamHookeLawForceField") << "No Mechanical State found, no force will be computed..." << "\n";
compute_df = false;
Expand All @@ -171,22 +173,23 @@ namespace sofa::component::forcefield {
compute_df = false;
return;
}

if (!d_variantSections.getValue())
// @todo: use multithread
for (unsigned int i = 0; i < x.size(); i++)
for (unsigned int i = 0; i < x.size(); i++){
// Using the correct matrix type for the datatype
// For Vec3Types, m_K_section should be Mat33
f[i] -= (m_K_section * (x[i] - x0[i])) * this->d_length.getValue()[i];
}
else
// @todo: use multithread
for (unsigned int i = 0; i < x.size(); i++)
f[i] -= (m_K_sectionList[i] * (x[i] - x0[i])) * this->d_length.getValue()[i];

// Debug output if needed

displayForces(f, "addForce - computed forces");
displaySectionMatrix(m_K_section, "addForce - K section matrix");
// Debug output if needed
// displayForces(f, "addForce - computed forces");
// displaySectionMatrix(m_K_section, "addForce - K section matrix");


d_f.endEdit();
Expand All @@ -195,30 +198,33 @@ namespace sofa::component::forcefield {
template<typename DataTypes>
void BeamHookeLawForceField<DataTypes>::addDForce(const MechanicalParams *mparams, DataVecDeriv &d_df,
const DataVecDeriv &d_dx) {

if (!compute_df)
return;

WriteAccessor<DataVecDeriv> df = d_df;
ReadAccessor<DataVecDeriv> dx = d_dx;
Real kFactor = (Real) mparams->kFactorIncludingRayleighDamping(this->rayleighStiffness.getValue());

df.resize(dx.size());
if (!d_variantSections.getValue())
for (unsigned int i = 0; i < dx.size(); i++)
for (unsigned int i = 0; i < dx.size(); i++){
df[i] -= (m_K_section * dx[i]) * kFactor * this->d_length.getValue()[i];
}

else
for (unsigned int i = 0; i < dx.size(); i++)
df[i] -= (m_K_sectionList[i] * dx[i]) * kFactor * this->d_length.getValue()[i];


// Debug output if needed
displayDForces(df, "addDForce - computed differential forces");

// displayDForces(df, "addDForce - computed differential forces");
}

template<typename DataTypes>
double BeamHookeLawForceField<DataTypes>::getPotentialEnergy(const MechanicalParams *mparams,
const DataVecCoord &d_x) const {

SOFA_UNUSED(mparams);
if (!this->getMState())
return 0.0;
Expand Down Expand Up @@ -246,14 +252,14 @@ namespace sofa::component::forcefield {
energy += 0.5 * dot(strain, K * strain) * this->d_length.getValue()[i];
}
}

return energy;
}


template<typename DataTypes>
void BeamHookeLawForceField<DataTypes>::addKToMatrix(const MechanicalParams *mparams,
const MultiMatrixAccessor *matrix) {

MultiMatrixAccessor::MatrixRef mref = matrix->getMatrix(this->mstate);
BaseMatrix *mat = mref.matrix;
unsigned int offset = mref.offset;
Expand All @@ -274,7 +280,7 @@ namespace sofa::component::forcefield {
}

// Debug output if needed
displayKMatrix(matrix, "addKToMatrix - global K matrix");
//displayKMatrix(matrix, "addKToMatrix - global K matrix");

}

Expand Down
40 changes: 26 additions & 14 deletions src/Cosserat/forcefield/standard/HookeSeratPCSForceField.inl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace sofa::component::forcefield {
recalculating the properties related to the cross-section of the beams. It
calculates the area moment of inertia (Iy and Iz), the polar moment of
inertia (J), and the cross-sectional area (A). These calculations depend on
the chosen cross-section shape, either circular or rectangular. T he formulas
the chosen cross-section shape, either circular or rectangular. The formulas
used for these calculations are based on standard equations for these
properties.*/
template<typename DataTypes>
Expand Down Expand Up @@ -182,22 +182,28 @@ namespace sofa::component::forcefield {
return;
}

Vector3 current_strain = Vector3::Zero();
Vector3 rest_strain = Vector3::Zero();
Vector3 strain = Vector3::Zero();
Vector3 _f = Vector3::Zero();


if (!d_variantSections.getValue()) {
// @todo: use multithread
for (unsigned int i = 0; i < x.size(); i++) {
// Using the correct matrix type for the datatype
// For Vec3Types, m_K_section should be Mat33
Vector3 current_strain = Vector3::Map(x[i].data());
Vector3 rest_strain = Vector3::Map(x0[i].data());
Vector3 strain = current_strain - rest_strain;
Vector3 _f = (m_K_section * strain) * this->d_length.getValue()[i];
current_strain = Vector3::Map(x[i].data());
rest_strain = Vector3::Map(x0[i].data());
strain = current_strain - rest_strain;

_f = (m_K_section * strain) * this->d_length.getValue()[i];

for (unsigned int j = 0; j < 3; j++)
f[i][j] -= _f[j];
}
} else {
// @todo: use multithread
Vector3 current_strain, rest_strain, strain, _f;

for (unsigned int i = 0; i < x.size(); i++) {
current_strain = Vector3::Map(x[i].data());
Expand All @@ -210,23 +216,25 @@ namespace sofa::component::forcefield {
}

// Debug output if needed
displayForces(f, "addForce - computed forces");
displaySectionMatrix(m_K_section, "addForce - K section matrix");

// displayForces(f, "addForce - computed forces");
// displaySectionMatrix(m_K_section, "addForce - K section matrix");

d_f.endEdit();
}

template<typename DataTypes>
void HookeSeratPCSForceField<DataTypes>::addDForce(const MechanicalParams *mparams, DataVecDeriv &d_df,
const DataVecDeriv &d_dx) {

if (!compute_df)
return;

WriteAccessor<DataVecDeriv> df = d_df;
ReadAccessor<DataVecDeriv> dx = d_dx;
Real kFactor = (Real) mparams->kFactorIncludingRayleighDamping(this->rayleighStiffness.getValue());
Vector3 d_strain, _df;
Vector3 d_strain = Vector3::Zero();
Vector3 _df= Vector3::Zero();

df.resize(dx.size());
if (!d_variantSections.getValue()) {

Expand All @@ -244,18 +252,21 @@ namespace sofa::component::forcefield {
else
for (unsigned int i = 0; i < dx.size(); i++) {
d_strain = Vector3::Map(dx[i].data());
_df = (m_K_sectionList[i] * d_strain) * this->d_length.getValue()[i];
_df = (m_K_sectionList[i] * d_strain) * kFactor * this->d_length.getValue()[i]; //@appa: kFactor was missing
for (unsigned int j = 0; j < 3; j++)
df[i][j] -= _df[j];
}


// Debug output if needed
displayDForces(df, "addDForce - computed differential forces");
// displayDForces(df, "addDForce - computed differential forces");
}

template<typename DataTypes>
double HookeSeratPCSForceField<DataTypes>::getPotentialEnergy(const MechanicalParams *mparams,
const DataVecCoord &d_x) const {


SOFA_UNUSED(mparams);
if (!this->getMState())
return 0.0;
Expand All @@ -282,14 +293,14 @@ namespace sofa::component::forcefield {
energy += 0.5 * strain.dot(K * strain) * this->d_length.getValue()[i];
}
}

return energy;
}


template<typename DataTypes>
void HookeSeratPCSForceField<DataTypes>::addKToMatrix(const MechanicalParams *mparams,
const MultiMatrixAccessor *matrix) {

MultiMatrixAccessor::MatrixRef mref = matrix->getMatrix(this->mstate);
BaseMatrix *mat = mref.matrix;
unsigned int offset = mref.offset;
Expand All @@ -310,7 +321,8 @@ namespace sofa::component::forcefield {
}

// Debug output if needed
displayKMatrix(matrix, "addKToMatrix - global K matrix");
// displayKMatrix(matrix, "addKToMatrix - global K matrix");

}

template<typename DataTypes>
Expand Down
2 changes: 1 addition & 1 deletion src/Cosserat/mapping/BaseCosseratMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ template class SOFA_COSSERAT_API
template class SOFA_COSSERAT_API
BaseCosseratMapping<sofa::defaulttype::Vec6Types, sofa::defaulttype::Rigid3Types, sofa::defaulttype::Rigid3Types>;

} // namespace cosserat::mapping
} // namespace cosserat::mapping
Loading
Loading