Skip to content

WriteState

Write State vectors to file at each timestep.

Target: Sofa.Component.Playback

namespace: sofa::component::playback

parents:

  • BaseObject

Data

Name Description Default value
name object name unnamed
printLog if true, emits extra messages at runtime. 0
tags list of the subsets the objet belongs to
bbox this object bounding box
componentState The state of the component among (Dirty, Valid, Undefined, Loading, Invalid). Undefined
listening if true, handle the events, otherwise ignore the events 0
filename output file name
writeX flag enabling output of X vector 1
writeX0 flag enabling output of X0 vector 0
writeV flag enabling output of V vector 0
writeF flag enabling output of F vector 0
time set time to write outputs (by default export at t=0)
period period between outputs 0
DOFsX set the position DOFs to write
DOFsV set the velocity DOFs to write
stopAt stop the simulation when the given threshold is reached 0
keperiod set the period to measure the kinetic energy increase 0
Name Description Destination type name
context Graph Node containing this object (or BaseContext::getDefault() if no graph is used) BaseContext
slaves Sub-objects used internally by this object BaseObject
master nullptr for regular objects, or master object for which this object is one sub-objects BaseObject

Examples

WriteState.scn

<?xml version="1.0"?>
<Node name="root" dt="0.01" gravity="0 -9.81 0">
    <Node name="plugins">
        <RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedProjectiveConstraint] -->
        <RequiredPlugin name="Sofa.Component.LinearSolver.Direct"/> <!-- Needed to use components [SparseLDLSolver] -->
        <RequiredPlugin name="Sofa.Component.LinearSolver.Iterative"/> <!-- Needed to use components [CGLinearSolver] -->
        <RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [UniformMass] -->
        <RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] -->
        <RequiredPlugin name="Sofa.Component.Playback"/> <!-- Needed to use components [WriteState] -->
        <RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [TetrahedronFEMForceField] -->
        <RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
        <RequiredPlugin name="Sofa.Component.Topology.Container.Grid"/> <!-- Needed to use components [RegularGridTopology] -->
        <RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] -->
    </Node>

    <VisualStyle displayFlags="showForceFields showBehaviorModels showVisual showInteractionForceFields" />
    <DefaultAnimationLoop/>

    <!-- Beam under gravity -->
    <Node name="Beam">
        <EulerImplicitSolver/>                
        <SparseLDLSolver />

        <MechanicalObject name="beamMO" template="Vec3" />
        <RegularGridTopology nx="3" ny="3" nz="7" xmin="0" xmax="3" ymin="0" ymax="3" zmin="0" zmax="7" />
        <UniformMass totalMass="10" />

        <!-- WriteState: finds automatically the Mechanical within its node/context -->
        <!-- Export positions (X) every 0.01 (each time step) -->
        <WriteState name="StateWriter" filename="beamGravity.txt.gz" period="0.01" writeX="1" writeV="0" writeF="0" time="0"/>

        <FixedProjectiveConstraint indices="0-8" />
        <TetrahedronFEMForceField name="FEM" youngModulus="100" poissonRatio="0.3" method="large" />
    </Node>
</Node>
def createScene(root_node):

   root = root_node.addChild('root', dt="0.01", gravity="0 -9.81 0")

   plugins = root.addChild('plugins')

   plugins.addObject('RequiredPlugin', name="Sofa.Component.Constraint.Projective")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.LinearSolver.Direct")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.LinearSolver.Iterative")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.Mass")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.ODESolver.Backward")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.Playback")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.SolidMechanics.FEM.Elastic")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.StateContainer")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.Topology.Container.Grid")
   plugins.addObject('RequiredPlugin', name="Sofa.Component.Visual")

   root.addObject('VisualStyle', displayFlags="showForceFields showBehaviorModels showVisual showInteractionForceFields")
   root.addObject('DefaultAnimationLoop', )

   beam = root.addChild('Beam')

   beam.addObject('EulerImplicitSolver', )
   beam.addObject('SparseLDLSolver', )
   beam.addObject('MechanicalObject', name="beamMO", template="Vec3")
   beam.addObject('RegularGridTopology', nx="3", ny="3", nz="7", xmin="0", xmax="3", ymin="0", ymax="3", zmin="0", zmax="7")
   beam.addObject('UniformMass', totalMass="10")
   beam.addObject('WriteState', name="StateWriter", filename="beamGravity.txt.gz", period="0.01", writeX="1", writeV="0", writeF="0", time="0")
   beam.addObject('FixedProjectiveConstraint', indices="0-8")
   beam.addObject('TetrahedronFEMForceField', name="FEM", youngModulus="100", poissonRatio="0.3", method="large")