Usage of DPF operator vtk to fields

kanchan_cadfem Member Posts: 15
10 Comments 5 Likes First Answer Name Dropper
edited June 27 in Structures

Hi all,

I am using pyDPF

I am trying to get the data from a VTK file, and combine it with results of RST file.

I found the operator "vtk_to_fields"

unfofortinately I could not figure out how to use this operator.

I have already looked at the example as well as the tests in github but did not find anything useful.

could you please help me to understand, how to create a data source for a VTK file and give it to this operator

PS: RST and VTK files have different meshes



  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 42
    10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member
    edited July 19


    You might have faced the challenge because field_name pin is mentioned optional but it is a compulsory pin.

    You can get the field name from the vtk file by opening it in text pad.

    If the vtk file is big and you do not want to open in text pad then you can use pyvista APIs to get the field names.

    import pyvista
    mesh ='D:/vtk_file.vtk')
    fields_available = mesh.array_names #Return field_name lists ( including node_ids and elements_ids)

    Once you know the field_name then you can use below script. Below script include export and reimport of the vtk file data.

    Hope it helps.

    from ansys.dpf import core as dpf
    from ansys.dpf.core import examples
    model = dpf.Model(examples.find_simple_bar())
    results = model.results
    displacements = results.displacement()
    fields = displacements.outputs.fields_container()
    field = fields[0]
    vtk_op = dpf.operators.serialization.vtk_export(
    vtk_datasource = dpf.DataSources(result_path="D:/vtk_file.vtk")
    vkt_field_op = dpf.operators.serialization.vtk_to_fields(
    result_fields_container = vkt_field_op.eval()