Usage of DPF operator vtk to fields

kanchan_cadfem
kanchan_cadfem Member Posts: 20
10 Comments First Anniversary 5 Likes First Answer
**
edited June 2023 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

Tagged:

Comments

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 90
    Second Anniversary 10 Comments 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭
    edited July 2023

    @kanchan_cadfem

    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 = pyvista.read('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]
    field.plot()
    
    vtk_op = dpf.operators.serialization.vtk_export(
        export_type=0,
        file_path="D:/vtk_file.vtk",
        fields1=fields,
        mesh=field.meshed_region
    )
    vtk_op.run()
    
    vtk_datasource = dpf.DataSources(result_path="D:/vtk_file.vtk")
    vkt_field_op = dpf.operators.serialization.vtk_to_fields(
        field_name="2_displacement_1.s_(m)",
        data_sources=vtk_datasource,
        server=model.metadata._server
    )
    result_fields_container = vkt_field_op.eval()
    result_fields_container[0].plot()