@@ -67,11 +67,13 @@ def compute(nodes, topology):
6767 return compute
6868
6969def build_beam_scene (rootNode , mms , element , L = 1.0 , E = 1e6 , nu = 0.3 ,
70- nx = 10 , ny = 10 , with_visual = True , dim = "2d" ):
70+ nx = 10 , ny = 10 , with_visual = True , dim = "2d" ,
71+ force_field = "LinearSmallStrainFEMForceField" ):
7172 """Build a SOFA scene for `mms` on the 2D `element` strategy.
7273
7374 dim : "2d" → Vec2d template / plane stress
7475 "3d" → Vec3d template / plane strain (z coordinate fixed at 0)
76+ force_field : name of the FEM force field to test
7577 Returns (dofs, topology). Nodes and connectivity become available
7678 after `Sofa.Simulation.init(root)` runs, via
7779 `dofs.rest_position.array()` and `element.read_connectivity(topology)`.
@@ -125,7 +127,7 @@ def build_beam_scene(rootNode, mms, element, L=1.0, E=1e6, nu=0.3,
125127
126128 topology = element .add_topology (Beam )
127129
128- Beam .addObject ("LinearSmallStrainFEMForceField" , name = "FEM" , template = tmpl ,
130+ Beam .addObject (force_field , name = "FEM" , template = tmpl ,
129131 youngModulus = E , poissonRatio = nu , topology = "@topology" )
130132
131133 mms .apply_bcs (Beam , nodes_2d , L , dim )
@@ -150,11 +152,13 @@ def build_beam_scene(rootNode, mms, element, L=1.0, E=1e6, nu=0.3,
150152# Simulation runner
151153# ─────────────────────────────────────────────────────────────────────────────
152154
153- def solve_beam (elem , mms , L , E , nu , nx , ny , dim = "2d" ):
155+ def solve_beam (elem , mms , L , E , nu , nx , ny , dim = "2d" ,
156+ force_field = "LinearSmallStrainFEMForceField" ):
154157 """Build, init, and run one static step. Returns a BeamSolution2D snapshot."""
155158 root = Sofa .Core .Node ("root" )
156159 dofs , topology = build_beam_scene (
157- root , mms , elem , L = L , E = E , nu = nu , nx = nx , ny = ny , with_visual = False , dim = dim
160+ root , mms , elem , L = L , E = E , nu = nu , nx = nx , ny = ny , with_visual = False , dim = dim ,
161+ force_field = force_field
158162 )
159163 Sofa .Simulation .init (root )
160164 # Read topology back from SOFA now that init has populated it.
@@ -246,9 +250,10 @@ def run_reference_scene(elem, mms):
246250 L , E = cfg ["length" ], cfg ["youngModulus" ]
247251 nu , dim = ref ["nu" ], ref ["dim" ]
248252 nx = ny = ref ["nx" ]
253+ ff = cfg ["forceField" ]
249254 hyp = "plane strain" if dim == "3d" else "plane stress"
250255
251- sol = solve_beam (elem , mms , L , E , nu , nx , ny , dim = dim )
256+ sol = solve_beam (elem , mms , L , E , nu , nx , ny , dim = dim , force_field = ff )
252257 l2 = elem .compute_l2 (sol , mms , L )
253258 h1 = elem .compute_h1 (sol , mms , L )
254259
@@ -281,6 +286,7 @@ def createScene(rootNode):
281286 build_beam_scene (rootNode , mms , element ,
282287 L = cfg ["length" ], E = cfg ["youngModulus" ],
283288 nu = ref ["nu" ], nx = ref ["nx" ], ny = ref ["nx" ],
284- with_visual = True , dim = ref ["dim" ])
289+ with_visual = True , dim = ref ["dim" ],
290+ force_field = cfg ["forceField" ])
285291 return rootNode
286292 return createScene
0 commit comments