Export Results As VTK
Export Results as VTK format. Before running the code, define
pathToRst = r’path to rst file’
result_type = ‘all’ # ‘all’ / ‘vonMises’ / ‘stressTensor’ / ‘displacement’ /
VTK_PATH = r’C:\Temp\fieldVTK.vtk’
Result post processing in (Open Source) Paraview.
from ansys.dpf import core as dpf
############################### user inputs
pathToRst = r'C:\Temp\Export Results As VTK_files\dp0\SYS\MECH\file.rst'
result_type = 'all'
VTK_PATH = r'C:\Temp\fieldVTK.vtk'
model = dpf.Model(pathToRst)
mesh_set = model.metadata.meshed_region
tdata = list(model.metadata.time_freq_support.time_frequencies.data)
if result_type == 'vonMises':
result_operator = dpf.operators.result.stress_von_mises()
result_operator.inputs.data_sources.connect(model)
result_operator.inputs.requested_location.connect('Nodal')
result_operator.inputs.time_scoping.connect(tdata)
nodal_result = result_operator.outputs.fields_container()
elif result_type == 'stressTensor':
result_operator = dpf.operators.result.stress()
result_operator.inputs.requested_location.connect('Nodal')
result_operator.inputs.data_sources.connect(model)
result_operator.inputs.time_scoping.connect(tdata)
nodal_result = result_operator.outputs.fields_container()[0]
elif result_type == 'displacement':
result_operator = dpf.operators.result.displacement()
result_operator.inputs.data_sources.connect(model)
result_operator.inputs.time_scoping.connect(tdata)
nodal_result = result_operator.outputs.fields_container()[0]
elif result_type == 'all':
resVec = []
result_operator = dpf.operators.result.stress_von_mises()
result_operator.inputs.requested_location.connect('Nodal')
result_operator.inputs.data_sources.connect(model)
result_operator.inputs.time_scoping.connect(tdata)
nodal_result_von_mises = result_operator.outputs.fields_container()
resVec.append(nodal_result_von_mises)
result_operator = dpf.operators.result.stress()
result_operator.inputs.requested_location.connect('Nodal')
result_operator.inputs.data_sources.connect(model)
result_operator.inputs.time_scoping.connect(tdata)
nodal_result_stress = result_operator.outputs.fields_container()
resVec.append(nodal_result_stress)
result_operator = dpf.operators.result.displacement()
result_operator.inputs.data_sources.connect(model)
result_operator.inputs.time_scoping.connect(tdata)
nodal_result_displacement = result_operator.outputs.fields_container()
resVec.append(nodal_result_displacement)
else: pass
# EXPORT FIELD/FIELDS CONTAINER TO VTK!
op = dpf.operators.serialization.vtk_export()
op.inputs.file_path.connect(VTK_PATH)
op.inputs.mesh.connect(mesh_set)
if result_type == 'all':
for index, result_child in enumerate(resVec): op.connect(index+2, result_child)
else: op.inputs.fields1.connect(nodal_result)
op.run()