From 4465bdf588cfb48f7060da98de2d493bf1bf6b29 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 16 Sep 2025 19:42:12 +0200 Subject: [PATCH 1/2] Update timer example introducing the Newton Raphson --- examples/advanced_timer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/advanced_timer.py b/examples/advanced_timer.py index 6551a6a4..5506a6de 100644 --- a/examples/advanced_timer.py +++ b/examples/advanced_timer.py @@ -28,10 +28,10 @@ def onAnimateEndEvent(self, event): step_time = records['solve']['Mechanical (meca)']['total_time'] print(f"Step took {step_time:.2f} ms") - nb_iterations = records['solve']['Mechanical (meca)']['StaticSolver::Solve']['nb_iterations'] + nb_iterations = records['solve']['Mechanical (meca)']['NewtonStep']['StaticSolver::Solve']['nb_iterations'] for i in range(int(nb_iterations)): - total_time = records['solve']['Mechanical (meca)']['StaticSolver::Solve']['NewtonStep'][i]['total_time'] - CG_iterations = records['solve']['Mechanical (meca)']['StaticSolver::Solve']['NewtonStep'][i]['MBKSolve']['CG iterations'] + total_time = records['solve']['Mechanical (meca)']['NewtonStep']['StaticSolver::Solve'][i]['total_time'] + CG_iterations = records['solve']['Mechanical (meca)']['NewtonStep']['StaticSolver::Solve'][i]['MBKSolve']['CG iterations'] print(f" Newton iteration #{i} took {total_time:.2f} ms using {int(CG_iterations)} CG iterations") if not self.use_sofa_profiler_timer: @@ -70,7 +70,8 @@ def createScene(root): # Create our mechanical node root.addChild("meca") - root.meca.addObject("StaticSolver", newton_iterations=5, printLog=False) + root.meca.addObject("NewtonRaphsonSolver", name="newtonSolver_springs", maxNbIterationsNewton=5, maxNbIterationsLineSearch=1, warnWhenLineSearchFails=False, printLog=False) + root.meca.addObject("StaticSolver", newtonSolver="@newtonSolver_springs") root.meca.addObject("CGLinearSolver", iterations=25, tolerance=1e-5, threshold=1e-5) root.meca.addObject('MechanicalObject', name='mo', position='@../grid.position') From 2110c52923ed87ea4eaa3ee8686edaeb5ab4da9d Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 16 Sep 2025 20:10:03 +0200 Subject: [PATCH 2/2] fix timer end --- examples/advanced_timer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/advanced_timer.py b/examples/advanced_timer.py index 5506a6de..a7c13f0e 100644 --- a/examples/advanced_timer.py +++ b/examples/advanced_timer.py @@ -34,7 +34,9 @@ def onAnimateEndEvent(self, event): CG_iterations = records['solve']['Mechanical (meca)']['NewtonStep']['StaticSolver::Solve'][i]['MBKSolve']['CG iterations'] print(f" Newton iteration #{i} took {total_time:.2f} ms using {int(CG_iterations)} CG iterations") - if not self.use_sofa_profiler_timer: + if self.use_sofa_profiler_timer: + Timer.end("Animate") + else: Timer.end("cg_timer")