diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp index de486854..326b44dc 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp @@ -246,6 +246,11 @@ namespace sofapython3 matrix.colsValue.data()); }, sofapython3::doc::forceField::assembleKMatrix); + f.def("getPotentialEnergy", [](ForceField& self) -> SReal + { + return self.getPotentialEnergy(MechanicalParams::defaultInstance()); + }, sofapython3::doc::forceField::getPotentialEnergy); + PythonFactory::registerType>([](sofa::core::objectmodel::Base* object) { return py::cast(dynamic_cast*>(object)); diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField_doc.h b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField_doc.h index 123f781e..d4f79872 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField_doc.h +++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField_doc.h @@ -41,4 +41,11 @@ stiffness_matrix = self.force_field.assembleKMatrix() Returns: A scipy.sparse.csr_matrix object representing the stiffness matrix of the force field )"; + +static constexpr const char* getPotentialEnergy = R"( +Potential energy of the force field, evaluated at its current positions. + +Returns: + The potential energy of the force field, as a float +)"; }