Is there a simple method to convert Ansys rst results to Paraviewer results?

M
M Member, Employee Posts: 241
50 Answers 100 Comments 100 Likes Second Anniversary
✭✭✭✭
edited October 17 in Structures

Yes, this is possible using the Ansys pydpf package.
https://dpf.docs.pyansys.com/version/stable/

The script example (below) requires pydpf and easygui (just to request the file to open) that are not part of a standard python installation, so you will have to pip install them:

  • pydpf
  • easygui

This example is for a simple static example. It will use pydpf to read in the results from the .rst you select and will then write out a .vtk file (currently set to 'D://' for a test).

If you already have paraview installed, you can add the path to the executable in the path2paraview parameter and then paraview should automatically open the result.

This demo script will only convert the von mises stress and deformation. To add more, read the docs and add lines to that code block.

from ansys.dpf import core as dpf
import os
import easygui
import subprocess

paraview_open = True # Yes/No if you have paraview installed. If True, input location below
path2paraview = r"C:\Program Files\ParaView 5.13.1\bin\paraview.exe"

result_directory ='D://' # where you want your .vtk file to end up
path2rst = easygui.fileopenbox(msg="Choose a file", default="*.rst",filetypes='*.rst')

file_name = path2rst.split(os.sep)[-1].split('.')[0] # get the name of the result file
# ###############################################################################
# Create a model targeting a file.rst result file
model = dpf.Model(path2rst)
mesh = model.metadata.meshed_region

displacement_fields = model.results.displacement().outputs.fields_container()[0]

## Set the type of results to convert ##
vm_stress_op = dpf.operators.result.stress_von_mises()  
vm_stress_op.inputs.data_sources.connect(model)
stress_fields = vm_stress_op.outputs.fields_container()#[0]
vm_stress_nodal_field = stress_fields[0]
#vm_stress_nodal_field.plot() # Nodal results 

path2vtk = os.path.join(result_directory,file_name + '.vtk')
op = dpf.operators.serialization.vtk_export(
    file_path = path2vtk,
    export_type=0,
    mesh=mesh,
    fields1=displacement_fields,
    fields2=vm_stress_nodal_field,
)
op.run()
model.metadata.release_streams()

if paraview_open:
    paraview_call = path2paraview + ' ' + path2vtk
    subprocess.call(paraview_call)

This solution relies on some good ideas from @Vishnu that we discussed and I simplified for an easy example. Also see link