I am trying to export each time step of my analysis (available as rst file) into the VTK format using a python script and ansys.dpf.core. I don't want to save the whole model, but only a selection of elements, which I have as named_selection. This seems to work in general with my script (see below).
The problem I have is that the stress tensor is not written for some reason. It doesn't matter if I write it into fields1 or fields2. I would also like to export other results (e.g. total strain) but the operator only has two variables for fields. Is there a way to save more than two results?
Finally, I would like to assign a name to the results. At the moment the result of the displacement is called e.g. "3_displacement_1.s_()" in the first time step, "3_displacement_2.s_()" in the second time step and "3_displacement_3.s_() in the third time step. Can I rename the result so that the displacement in each time step is called "displacement" or "displ"?
Here is my code so far:
from ansys.dpf import core
from ansys.dpf.core import operators as ops
rst = "model.rst"
model = core.Model(rst)
mesh_scoping = core.mesh_scoping_factory.named_selection_scoping("myElements", model=model)
mesh_op = core.operators.mesh.from_scoping()
mesh_op.inputs.mesh.connect(model.metadata.meshed_region)
mesh_op.inputs.scoping.connect(mesh_scoping)
for time in range(1, model.metadata.time_freq_support.n_sets+1):
results = model.results
displacement = results.displacement(time_scoping = time)
displ_vector = displacement.outputs.fields_container()
stress = results.stress(time_scoping = time)
stress_tensor = stress.outputs.fields_container() # This is somehow not exported
op_export = core.Operator("vtk_export")
op_export.inputs.file_path.connect(f"export_{time}.vtk")
op_export.inputs.mesh.connect(mesh_op)
op_export.inputs.fields1.connect(displ_vector)
op_export.inputs.fields2.connect(stress_tensor)
op_export.run()
Speaking of which: Can i format the code in the post so that it looks pretty?