Skip to content

Commit eada37f

Browse files
committed
Squashed commit of the following:
commit 0806b07 Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Fri Feb 21 15:55:34 2025 +0100 [github] Use token for performance regression launching (sofa-framework#5287) Try fixing action commit 9f56fca Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Fri Feb 21 15:16:12 2025 +0100 [github] Add workflow for performance testing launch (sofa-framework#5286) * Add workflow for performance testing launch * Fix github token and sha commit 700b6cd Author: Olivier Roussel <olivier.roussel@inria.fr> Date: Thu Feb 20 23:27:00 2025 +0100 [IO.Mesh] Fix missing `iomanip` header in tests (sofa-framework#5279) Fix missing header commit 5307e85 Author: Hugo <hugo.talbot@sofa-framework.org> Date: Wed Feb 19 14:25:24 2025 +0100 [ODESolver] Update data comment in EulerImplicit (sofa-framework#5282) commit fee9657 Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Wed Feb 19 13:48:07 2025 +0100 [ODESolver] Add option to compute residual at the end of the solving (sofa-framework#5263) commit a229972 Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Wed Feb 19 12:20:51 2025 +0100 [Helper] Deprecate findOrCreateAValidPath and introduce clearer functions (sofa-framework#5264) * [Helper] Fix findOrCreateAValidPath when given a file path * [Helper] Fix findOrCreateAValidPath when given a file path * Introduce clearer function names * deprecate findOrCreateAValidPath * restore previous findOrCreateAValidPath commit 4ee24f6 Author: Frederick Roy <fredroy@users.noreply.github.com> Date: Wed Feb 19 20:15:38 2025 +0900 [All] Fix compilation with FLOATING_POINT_TYPE=float (sofa-framework#5269) fix compilation with FLOATING_POINT_TYPE=float commit ef7ff21 Author: Hugo <hugo.talbot@sofa-framework.org> Date: Wed Feb 19 09:52:47 2025 +0100 [SceneUtility] Remove *AliasComponent (sofa-framework#5241) * [SceneUtility] Remove *AliasComponent * Update in the ComponentChange so that it appears as Removed * remove associated scenes commit aa36098 Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Wed Feb 19 00:04:17 2025 +0100 [SceneChecking] Check if a Node has an empty name (sofa-framework#5276) commit f2f0b10 Author: EulalieCoevoet <eulalie.coevoet@gmail.com> Date: Wed Feb 12 12:14:48 2025 +0100 [visual] Adds features to LineAxis and DrawTools (sofa-framework#5258) * [visual-gl] LineAxis & DrawTool: - fixes usage of thickness - new feature: infinite lines - new feature: vanishing infinite line - fixes typo * [visual] LineAxis: cleaning commit b4e8b98 Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Wed Feb 12 09:35:16 2025 +0100 [GUI] Remove Qt and make SofaImGUI as default viewer (sofa-framework#5176) * Add possibility to fetch and add by default for external plugins and set SofaGLFW as ON by default * Remove Qt-based GUI from sources * Add way to pull and build Sofa.Qt plugin * Fix compilation * Change order so SofaGLFW and SofaIMGUI are already in the target stack when runSofa produce the plugin_list.cong.default * Merge master * Make the packaging possible without Qt * Remove GuiDataRepository that was Qt specific -> will need to include it to the Qt gui plugin * Add fetchable Qt commit d2f194d Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Wed Feb 12 07:26:17 2025 +0100 [Contact] Clean FrictionContact (sofa-framework#5261) * [Contact] Replace double by SReal * add override keyword on destructor commit 62264fb Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Mon Feb 10 14:20:15 2025 +0100 [StateContainer] Allow coord difference in vOp for rigids (sofa-framework#5253) * [StateContainer] Allow coord difference in vOp for rigids * check that DataTypes support coordDifference commit 5120328 Author: erik pernod <erik.pernod@gmail.com> Date: Mon Feb 10 14:19:28 2025 +0100 [Topology.Container] Add new method computeSegmentTriangleIntersectionInPlane in TriangleSetGeometryAlgorithm (sofa-framework#5188) * Update TriangleSetGeometryAlgorithms.h * Update TriangleSetGeometryAlgorithms.inl * [TopologyTest] Add comments * [Topology.Dynamic_test] factorize some code in TriangleSetTopology_test * [Topology.Dynamic_test] Add some tests in TriangleSetTopology_test to test adding and removing triangles * typo errors * [Topology.Dynamic_test] Add tests in TriangleSetTopology_test tto test TriangleSegmentIntersection inside same plane or with projection * Update TriangleSetTopology_test.cpp * Update TriangleSetTopology_test.cpp * Update TriangleSetTopology_test.cpp * Fix namespace commit 5448a14 Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Fri Jan 31 15:10:05 2025 +0100 [StateContainer] Extend the possible vector operations in vOp (sofa-framework#5237) * missing test * remove duplicated test * [StateContainer] Extend the possible vector operations in vOp --------- Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com> commit 6af25d5 Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Fri Jan 31 15:04:36 2025 +0100 [Simulation] Trigger warning when Node already contains component (sofa-framework#5212) * [Simulation] Trigger error when Node already contains component * also mention the class name * convert error to warning * fix STLExporter_test commit 9ceb6dc Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Fri Jan 31 15:04:21 2025 +0100 [SofaCUDA] Print CUDA standard at init of the module (sofa-framework#5166) * [SofaCUDA] Print CUDA standard at init of the module * add an empty scene loading the plugin * compiler output * remove empty scene commit 3eecf8f Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Wed Jan 29 22:18:50 2025 +0100 Bump version of Tracy from v0.9.1 to v0.11.1 (sofa-framework#5249) commit 3659403 Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Wed Jan 29 21:39:51 2025 +0100 [Core] Remove some static functions create (sofa-framework#5239) commit 989a885 Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Wed Jan 29 21:03:59 2025 +0100 [StateContainer] Extensive tests of MechanicalObject::vOp (sofa-framework#5233) * [StateContainer] Extensive tests of MechanicalObject::vOp * fix wrong name * fix test * Use variable for the coefficients * missing test * remove duplicated test commit 38c295d Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Wed Jan 29 19:54:39 2025 +0100 [Playback] Remove deprecated macro (sofa-framework#5231) commit ffddff7 Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Wed Jan 29 19:48:23 2025 +0100 [CMake] Add possibility to remove auto installing of resource files (sofa-framework#5230) Add possibility to remove auto installing of ressource files commit 7c6bddc Author: Alex Bilger <alxbilger@users.noreply.github.com> Date: Fri Jan 24 14:24:02 2025 +0100 [ODESolver] Remove repeated class name in log messages (sofa-framework#5242)
1 parent b4e8d43 commit eada37f

File tree

230 files changed

+2380
-33470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+2380
-33470
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Launch performance testing
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
run:
8+
runs-on: ubuntu-latest
9+
if: ${{ github.repository_owner == 'sofa-framework' }}
10+
11+
steps:
12+
- name: Launch performance regression test
13+
run: |
14+
sudo apt install curl
15+
16+
curl -L -X POST \
17+
-H "Accept: application/vnd.github+json" \
18+
-H "Authorization: Bearer ${{ secrets.PERF_REG_TOKEN }}" \
19+
-H "X-GitHub-Api-Version: 2022-11-28" \
20+
https://api.github.com/repos/sofa-framework/PerformanceRegression/dispatches \
21+
-d '{"event_type":"Launch perf test from SOFA commit","client_payload":{"branch":"master","commit_hash":"${{ github.sha }}"}}'

Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/AugmentedLagrangianResponse.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ AugmentedLagrangianResponse<TCollisionModel1,TCollisionModel2,ResponseDataTypes>
4242
template < class TCollisionModel1, class TCollisionModel2, class ResponseDataTypes >
4343
AugmentedLagrangianResponse<TCollisionModel1,TCollisionModel2,ResponseDataTypes>::AugmentedLagrangianResponse(CollisionModel1* model1, CollisionModel2* model2, Intersection* intersectionMethod)
4444
: BaseUnilateralContactResponse<TCollisionModel1, TCollisionModel2, constraint::lagrangian::model::AugmentedLagrangianContactParameters, ResponseDataTypes>(model1,model2,intersectionMethod)
45-
, d_mu (initData(&d_mu, 0.0, "mu", "Friction coefficient (0 for frictionless contacts)"))
46-
, d_epsilon (initData(&d_epsilon, 0.0, "epsilon", "Penalty parameter. It can be think of as a proportional controller, the Lagrange multiplier is augmented by the violation multiplied by this factor at each solving iteration."))
45+
, d_mu (initData(&d_mu, 0.0_sreal, "mu", "Friction coefficient (0 for frictionless contacts)"))
46+
, d_epsilon (initData(&d_epsilon, 0.0_sreal, "epsilon", "Penalty parameter. It can be thought of as a proportional controller, the Lagrange multiplier is augmented by the violation multiplied by this factor at each solving iteration."))
4747
{
4848

4949
}

Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/FrictionContact.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ class FrictionContact : public BaseUnilateralContactResponse<TCollisionModel1,
4949
typedef core::behavior::MechanicalState<DataTypes1> MechanicalState1;
5050
typedef core::behavior::MechanicalState<DataTypes2> MechanicalState2;
5151

52-
Data<double> d_mu; ///< friction parameter
52+
Data<SReal> d_mu; ///< friction parameter
5353

5454
FrictionContact();
5555
FrictionContact(CollisionModel1* model1, CollisionModel2* model2, Intersection* intersectionMethod);
5656

57-
virtual ~FrictionContact() = default;
57+
~FrictionContact() override = default;
5858

5959
virtual constraint::lagrangian::model::UnilateralLagrangianContactParameters getParameterFromDatas() const override;
6060
virtual void setupConstraint(MechanicalState1 *,MechanicalState2 *) override;

Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/FrictionContact.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ FrictionContact<TCollisionModel1,TCollisionModel2,ResponseDataTypes>::FrictionCo
4242
template < class TCollisionModel1, class TCollisionModel2, class ResponseDataTypes >
4343
FrictionContact<TCollisionModel1,TCollisionModel2,ResponseDataTypes>::FrictionContact(CollisionModel1* model1, CollisionModel2* model2, Intersection* intersectionMethod)
4444
: BaseUnilateralContactResponse<TCollisionModel1, TCollisionModel2, constraint::lagrangian::model::UnilateralLagrangianContactParameters, ResponseDataTypes>(model1,model2,intersectionMethod)
45-
, d_mu (initData(&d_mu, 0.8, "mu", "Friction coefficient (0 for frictionless contacts)"))
45+
, d_mu (initData(&d_mu, 0.8_sreal, "mu", "Friction coefficient (0 for frictionless contacts)"))
4646
{
4747

4848
}

Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralConstraintResolution.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BilateralConstraintResolution3Dof : public ConstraintResolution
6868
{
6969
public:
7070

71-
BilateralConstraintResolution3Dof(sofa::type::Vec3d* vec = nullptr)
71+
BilateralConstraintResolution3Dof(sofa::type::Vec3* vec = nullptr)
7272
: ConstraintResolution(3)
7373
, _f(vec)
7474
{
@@ -130,7 +130,7 @@ class BilateralConstraintResolution3Dof : public ConstraintResolution
130130

131131
protected:
132132
sofa::type::Mat<3,3,SReal> invW;
133-
sofa::type::Vec3d* _f;
133+
sofa::type::Vec3* _f;
134134
};
135135

136136
class BilateralConstraintResolutionNDof : public ConstraintResolution

Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ using sofa::core::ConstraintParams ;
4949
using sofa::core::ConstVecCoordId;
5050

5151
using sofa::linearalgebra::BaseVector ;
52-
using sofa::type::Vec3d;
52+
using sofa::type::Vec3;
5353
using sofa::type::Quat ;
5454

5555
using sofa::defaulttype::Rigid3Types ;
@@ -123,7 +123,7 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint<DataTypes
123123
SingleLink<BilateralLagrangianConstraint<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology1; ///< Link to be set to the first topology container in order to support topological changes
124124
SingleLink<BilateralLagrangianConstraint<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology2; ///< Link to be set to the second topology container in order to support topological changes
125125

126-
std::vector<Vec3d> prevForces;
126+
std::vector<Vec3> prevForces;
127127

128128
BilateralLagrangianConstraint(MechanicalState* object1, MechanicalState* object2) ;
129129
BilateralLagrangianConstraint(MechanicalState* object) ;

Sofa/Component/IO/Mesh/tests/MeshExporter_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* *
2020
* Contact information: contact@sofa-framework.org *
2121
******************************************************************************/
22+
#include <iomanip>
23+
2224
#include <vector>
2325
using std::vector;
2426

Sofa/Component/IO/Mesh/tests/STLExporter_test.cpp

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,22 @@ class STLExporter_test : public BaseSimulationTest {
9090
}
9191
}
9292

93-
void checkBasicBehavior(const std::string& filename, std::vector<std::string> pathes){
93+
void checkBasicBehavior(const std::string& filename, std::vector<std::string> pathes)
94+
{
9495
dataPath = pathes ;
9596

9697
EXPECT_MSG_NOEMIT(Error, Warning) ;
97-
std::stringstream scene1;
98-
scene1 <<
99-
"<?xml version='1.0'?> \n"
100-
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > \n"
101-
" <DefaultAnimationLoop/> \n"
102-
" <MechanicalObject position='0 1 2 3 4 5 6 7 8 9'/> \n"
103-
" <MeshOBJLoader name='loader' filename='mesh/liver-smooth.obj'/> \n"
104-
" <VisualModel src='@loader'/> \n"
105-
" <STLExporter name='exporter1' printLog='false' filename='"<< filename << "' exportAtBegin='true' /> \n"
106-
"</Node> \n" ;
107-
108-
const Node::SPtr root = SceneLoaderXML::loadFromMemory("testscene", scene1.str().c_str());
109-
110-
ASSERT_NE(root.get(), nullptr) << scene1.str() ;
111-
root->init(sofa::core::execparams::defaultInstance()) ;
98+
99+
const Node::SPtr root = sofa::simpleapi::createRootNode(sofa::simulation::getSimulation(), "root", {{"gravity", "0 0 0"}});
100+
sofa::simpleapi::createObject(root, "DefaultAnimationLoop");
101+
sofa::simpleapi::createObject(root, "MechanicalObject", {{"position", "0 1 2 3 4 5 6 7 8 9"}});
102+
sofa::simpleapi::createObject(root, "MeshOBJLoader", {{"name", "loader"}, {"filename", "mesh/liver-smooth.obj"}});
103+
const Node::SPtr visualNode = sofa::simpleapi::createChild(root, "Visual");
104+
sofa::simpleapi::createObject(visualNode, "VisualModel", {{"src", "@../loader"}});
105+
sofa::simpleapi::createObject(visualNode, "STLExporter", {{"name", "exporter1"}, {"filename", filename}, {"exportAtBegin", "true"}});
106+
107+
ASSERT_NE(root.get(), nullptr);
108+
sofa::simulation::node::initRoot(root.get());
112109

113110
// SimulationInitDoneEvent is used to trigger exportAtBegin
114111
SimulationInitDoneEvent endInit;
@@ -119,32 +116,27 @@ class STLExporter_test : public BaseSimulationTest {
119116

120117
for(auto& pathToCheck : pathes)
121118
{
122-
EXPECT_TRUE( FileSystem::exists(pathToCheck) ) << "Problem with '" << pathToCheck << "'"<< std::endl
123-
<< "================= scene dump ==========================="
124-
<< scene1.str() ;
119+
EXPECT_TRUE( FileSystem::exists(pathToCheck) );
125120
}
126121
}
127122

128123

129-
void checkSimulationWriteEachNbStep(const std::string& filename, std::vector<std::string> pathes, unsigned int numstep){
124+
void checkSimulationWriteEachNbStep(const std::string& filename, std::vector<std::string> pathes, unsigned int numstep)
125+
{
130126
dataPath = pathes ;
131127

132128
EXPECT_MSG_NOEMIT(Error, Warning) ;
133-
std::stringstream scene1;
134-
scene1 <<
135-
"<?xml version='1.0'?> \n"
136-
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > \n"
137-
" <DefaultAnimationLoop/> \n"
138-
" <MechanicalObject position='0 1 2 3 4 5 6 7 8 9'/> \n"
139-
" <MeshOBJLoader name='loader' filename='mesh/liver-smooth.obj'/> \n"
140-
" <VisualModel src='@loader'/> \n"
141-
" <STLExporter name='exporterA' printLog='false' filename='"<< filename << "' exportEveryNumberOfSteps='5' /> \n"
142-
"</Node> \n" ;
143-
144-
const Node::SPtr root = SceneLoaderXML::loadFromMemory("testscene", scene1.str().c_str());
129+
130+
const Node::SPtr root = sofa::simpleapi::createRootNode(sofa::simulation::getSimulation(), "root", {{"gravity", "0 0 0"}});
131+
sofa::simpleapi::createObject(root, "DefaultAnimationLoop");
132+
sofa::simpleapi::createObject(root, "MechanicalObject", {{"position", "0 1 2 3 4 5 6 7 8 9"}});
133+
sofa::simpleapi::createObject(root, "MeshOBJLoader", {{"name", "loader"}, {"filename", "mesh/liver-smooth.obj"}});
134+
const Node::SPtr visualNode = sofa::simpleapi::createChild(root, "Visual");
135+
sofa::simpleapi::createObject(visualNode, "VisualModel", {{"src", "@../loader"}});
136+
sofa::simpleapi::createObject(visualNode, "STLExporter", {{"name", "exporterA"}, {"filename", filename}, {"exportEveryNumberOfSteps", "5"}});
145137

146138
ASSERT_NE(root.get(), nullptr) ;
147-
root->init(sofa::core::execparams::defaultInstance()) ;
139+
sofa::simulation::node::initRoot(root.get());
148140

149141
for(unsigned int i=0;i<numstep;i++)
150142
{

Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/EulerImplicitSolver.cpp

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <sofa/core/ObjectFactory.h>
2929
#include <sofa/helper/ScopedAdvancedTimer.h>
3030

31+
#include <iomanip>
3132

3233
namespace sofa::component::odesolver::backward
3334
{
@@ -44,36 +45,44 @@ EulerImplicitSolver::EulerImplicitSolver()
4445
, d_trapezoidalScheme( initData(&d_trapezoidalScheme,false,"trapezoidalScheme","Boolean to use the trapezoidal scheme instead of the implicit Euler scheme and get second order accuracy in time (false by default)") )
4546
, d_solveConstraint(initData(&d_solveConstraint, false, "solveConstraint", "Apply ConstraintSolver (requires a ConstraintSolver in the same node as this solver, disabled by by default for now)") )
4647
, d_threadSafeVisitor(initData(&d_threadSafeVisitor, false, "threadSafeVisitor", "If true, do not use realloc and free visitors in fwdInteractionForceField."))
48+
, d_computeResidual(initData(&d_computeResidual, false, "computeResidual", "If true, the residual is computed at the end of the solving"))
49+
, d_residual(initData(&d_residual, std::numeric_limits<SReal>::max(), "residual", "Residual norm at the end of the free-motion solving"))
4750
{
4851
f_rayleighStiffness.setOriginalData(&d_rayleighStiffness);
4952
f_rayleighMass.setOriginalData(&d_rayleighMass);
5053
f_velocityDamping.setOriginalData(&d_velocityDamping);
5154
f_firstOrder.setOriginalData(&d_firstOrder);
5255
f_solveConstraint.setOriginalData(&d_solveConstraint);
53-
5456
}
5557

5658
void EulerImplicitSolver::init()
5759
{
60+
sofa::core::behavior::OdeSolver::init();
61+
sofa::core::behavior::LinearSolverAccessor::init();
62+
5863
if (!this->getTags().empty())
5964
{
60-
msg_info() << "EulerImplicitSolver: responsible for the following objects with tags " << this->getTags() << " :";
65+
msg_info() << "Responsible for the following objects with tags " << this->getTags() << " :";
6166
type::vector<core::objectmodel::BaseObject*> objs;
6267
this->getContext()->get<core::objectmodel::BaseObject>(&objs,this->getTags(),sofa::core::objectmodel::BaseContext::SearchDown);
6368
for (const auto* obj : objs)
6469
{
6570
msg_info() << " " << obj->getClassName() << ' ' << obj->getName();
6671
}
6772
}
68-
sofa::core::behavior::OdeSolver::init();
69-
sofa::core::behavior::LinearSolverAccessor::init();
73+
74+
simulation::common::VectorOperations vop(sofa::core::execparams::defaultInstance(), this->getContext());
75+
reallocSolutionVector(&vop);
76+
reallocRightHandSideVector(&vop);
7077
}
7178

7279
void EulerImplicitSolver::cleanup()
7380
{
74-
// free the locally created vector x (including eventual external mechanical states linked by an InteractionForceField)
81+
// free the locally created vectors (including eventual external mechanical states linked by an InteractionForceField)
7582
sofa::simulation::common::VectorOperations vop( core::execparams::defaultInstance(), this->getContext() );
7683
vop.v_free(x.id(), !d_threadSafeVisitor.getValue(), true);
84+
vop.v_free(b.id(), !d_threadSafeVisitor.getValue(), true);
85+
vop.v_free(m_residual.id(), !d_threadSafeVisitor.getValue(), true);
7786
}
7887

7988
void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::core::MultiVecCoordId xResult, sofa::core::MultiVecDerivId vResult)
@@ -86,7 +95,6 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
8695
MultiVecCoord pos(&vop, core::vec_id::write_access::position );
8796
MultiVecDeriv vel(&vop, core::vec_id::write_access::velocity );
8897
MultiVecDeriv f(&vop, core::vec_id::write_access::force );
89-
MultiVecDeriv b(&vop, true, core::VecIdProperties{"RHS", GetClass()->className});
9098
MultiVecCoord newPos(&vop, xResult );
9199
MultiVecDeriv newVel(&vop, vResult );
92100

@@ -98,8 +106,8 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
98106
MultiVecDeriv dx(&vop, core::vec_id::write_access::dx);
99107
dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true);
100108

101-
x.realloc(&vop, !d_threadSafeVisitor.getValue(), true, core::VecIdProperties{"solution", GetClass()->className});
102-
109+
reallocSolutionVector(&vop);
110+
reallocRightHandSideVector(&vop);
103111

104112
#ifdef SOFA_DUMP_VISITOR_INFO
105113
sofa::simulation::Visitor::printCloseNode("SolverVectorAllocation");
@@ -125,7 +133,7 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
125133
// compute the net forces at the beginning of the time step
126134
mop.computeForce(f); //f = Kx + Bv
127135

128-
msg_info() << "EulerImplicitSolver, initial f = " << f;
136+
msg_info() << "initial f = " << f;
129137
}
130138

131139
{
@@ -141,7 +149,7 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
141149
// force in the current configuration
142150
b.eq(f); // b = f
143151

144-
msg_info() << "EulerImplicitSolver, f = " << f;
152+
msg_info() << "f = " << f;
145153

146154
// add the change of force due to stiffness + Rayleigh damping
147155
mop.addMBKv(b, core::MatricesFactors::M(-d_rayleighMass.getValue()),
@@ -152,11 +160,11 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
152160
b.teq(h); // b = h(f + ( rm M + (h+rs) K ) v )
153161
}
154162

155-
msg_info() << "EulerImplicitSolver, b = " << b;
163+
msg_info() << "b = " << b;
156164

157165
mop.projectResponse(b); // b is projected to the constrained space
158166

159-
msg_info() << "EulerImplicitSolver, projected b = " << b;
167+
msg_info() << "projected b = " << b;
160168
}
161169

162170
{
@@ -299,10 +307,38 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
299307
mop.projectVelocity(newVel);
300308
mop.propagateX(newPos);
301309
mop.propagateV(newVel);
302-
msg_info() << "EulerImplicitSolver, final x = " << newPos;
303-
msg_info() << "EulerImplicitSolver, final v = " << newVel;
310+
msg_info() << "final x = " << newPos;
311+
msg_info() << "final v = " << newVel;
312+
mop.computeForce(f);
313+
msg_info() << "final f = " << f;
314+
}
315+
316+
if (d_computeResidual.getValue())
317+
{
318+
reallocResidualVector(&vop);
319+
320+
// r = 0
321+
vop.v_clear(m_residual);
322+
323+
// r += M (v - v_n)
324+
{
325+
core::behavior::MultiVecDeriv tmp(&vop);
326+
327+
vop.v_eq(tmp, newVel);
328+
vop.v_peq(tmp, vel, -1);
329+
mop.addMdx(m_residual, tmp);
330+
}
331+
332+
// r += - dt * F
304333
mop.computeForce(f);
305-
msg_info() << "EulerImplicitSolver, final f = " << f;
334+
vop.v_peq(m_residual, f, -dt);
335+
336+
mop.projectResponse(m_residual);
337+
338+
vop.v_dot(m_residual, m_residual);
339+
d_residual.setValue(vop.finish());
340+
341+
msg_info() << "Residual norm: " << std::setw(6) << vop.finish();
306342
}
307343
}
308344

@@ -338,13 +374,29 @@ SReal EulerImplicitSolver::getSolutionIntegrationFactor(int outputDerivative) co
338374

339375
SReal EulerImplicitSolver::getSolutionIntegrationFactor(int outputDerivative, SReal dt) const
340376
{
341-
const SReal vect[3] = { dt, 1, 1/dt};
377+
const SReal vect[3] = {dt, 1, 1 / dt};
342378
if (outputDerivative >= 3)
343379
return 0;
344380
else
345381
return vect[outputDerivative];
346382
}
347383

384+
void EulerImplicitSolver::reallocSolutionVector(sofa::simulation::common::VectorOperations* vop)
385+
{
386+
x.realloc(vop, !d_threadSafeVisitor.getValue(), true,
387+
core::VecIdProperties{.label = "solution", .group = GetClass()->className});
388+
}
389+
void EulerImplicitSolver::reallocRightHandSideVector(sofa::simulation::common::VectorOperations* vop)
390+
{
391+
b.realloc(vop, !d_threadSafeVisitor.getValue(), true,
392+
core::VecIdProperties{.label = "RHS", .group = GetClass()->className});
393+
}
394+
void EulerImplicitSolver::reallocResidualVector(sofa::simulation::common::VectorOperations* vop)
395+
{
396+
m_residual.realloc(vop, !d_threadSafeVisitor.getValue(), true,
397+
core::VecIdProperties{.label = "residual", .group = GetClass()->className});
398+
}
399+
348400
void registerEulerImplicitSolver(sofa::core::ObjectFactory* factory)
349401
{
350402
factory->registerObjects(core::ObjectRegistrationData("Time integrator using implicit backward Euler scheme.")

0 commit comments

Comments
 (0)