How do I show results only on a particular Named Selection using PyDPF?

Options
Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 414
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer

How do I show results only on a particular Named Selection using PyDPF?

Tagged:

Comments

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 414
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    edited January 12
    Options

    You need to create a meshed_region for each named selection and then pass it on the result field.

    import os
    
    from ansys.dpf import core as dpf
    from ansys.dpf.core.plotter import DpfPlotter
    
    out_path = r"\PATH\TO\RST"
    rst_path = os.path.join(out_path, "file.rst")
    
    ds = dpf.DataSources(rst_path)
    model = dpf.Model(ds)
    mesh = model.metadata.meshed_region
    
    nsn = ["B1", "B2"]
    for ns in nsn:
        mesh_scoping = dpf.operators.scoping.on_named_selection(named_selection_name=ns,
                                                                data_sources=ds).outputs.mesh_scoping()
        mesh_region = dpf.operators.mesh.from_scoping(scoping=mesh_scoping, mesh=mesh).outputs.mesh()
        elastic_strain = dpf.operators.result.elastic_strain(data_sources=ds, requested_location="Nodal",
                                                             mesh_scoping=mesh_scoping)
        es_f = elastic_strain.outputs.fields_container()[0]
    
        plotter = DpfPlotter()
        sargs = dict(title="Legend", fmt="%.2e", title_font_size=30, label_font_size=20, n_labels=3, n_colors=2)
        plotter.add_field(es_f, meshed_region=mesh_region,
                          label_text_size=15,
                          label_point_size=5,
                          scalar_bar_args=sargs,
                          n_colors=2,
                          n_labels=3)
    
        plotter.show_figure()