How do I plot difference in results using PyDPF?

Options
Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 510
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭
edited June 16 in Structures

I need to plot difference in results between two models, with same geometry but different mesh.

Tagged:

Comments

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 510
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    edited June 16

    The following code maps results from the coarser mesh to the finer mesh and then plots differences between the mapped and real results on the finer mesh.

        from ansys.dpf import core as dpf
        from ansys.dpf.core.plotter import DpfPlotter
    
    
        map_to = r"\Path \to\model1\file.rst"
        map_from = r"\Path \to\model2\file.rst"
    
        model_from = dpf.Model(map_from)
        ds_from = dpf.DataSources(map_from)
    
        model_to = dpf.Model(map_to)
    
        mesh_from = model_from.metadata.meshed_region
        mesh_to = model_to.metadata.meshed_region
    
        sx_from_op = dpf.operators.result.stress_X(data_sources=ds_from)
        sx_from = sx_from_op.outputs.fields_container.get_data()
    
        # Map to
        mapped_res_op = dpf.operators.mapping.on_coordinates(fields_container=sx_from, coordinates=mesh_to.nodes.coordinates_field)
        mapped_res = mapped_res_op.outputs.fields_container.get_data()
    
        plot = DpfPlotter()
    
        # Create a new mesh and translate it along the x axis.
        mesh_new_from = mesh_from.deep_copy()
        overall_field = dpf.fields_factory.create_3d_vector_field(1, dpf.locations.overall)
        overall_field.append([50.0, 0.0, 0.0], 1)  # Translate by 50.0mm
        coordinates_to_update = mesh_new_from.nodes.coordinates_field
        add_operator = dpf.operators.math.add(coordinates_to_update, overall_field)
        coordinates_updated = add_operator.outputs.field()
        coordinates_to_update.data = coordinates_updated.data
    
        # Calculate Delta
        ds_to = dpf.DataSources(map_to)
        targ_res_sx_op = dpf.operators.result.stress_X(data_sources=ds_to)
        targ_res_sx = targ_res_sx_op.outputs.fields_container.get_data()
    
        field_lc1 = targ_res_sx[0]
        field_lc2 = mapped_res[0]
    
        # Scale LC2 to -1.
        field_lc2_sc = dpf.operators.math.scale(field=field_lc2, weights=-1.0)
    
        # Delta
        delta_op = dpf.operators.math.add(fieldA=field_lc1, fieldB=field_lc2_sc)
        delta = delta_op.outputs.field.get_data()
    
        # Plot Delta results
        plot.add_field(
            delta,
            meshed_region=mesh_to
        )
    
        plot.show_figure()