How do I compare different mesh densities, mapping results from coarser mesh to denser mesh?

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 505
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭

How do I compare different mesh densities, mapping results from coarser mesh to denser mesh?

Tagged:

Comments

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 505
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    from ansys.dpf import core as dpf
    from ansys.dpf.core.plotter import DpfPlotter
    
    
    map_from = r"D:\Path\to\source\mesh\file.rst"
    map_to = r"D:\Path\to\target\mesh\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
    
    seqv_op = dpf.operators.result.stress_eqv_as_mechanical(data_sources=ds_from)
    seqv = seqv_op.outputs.fields_container.get_data()
    
    # Map to
    mapped_res_op = dpf.operators.mapping.on_coordinates(fields_container=seqv, 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
    
    # Source Mesh
    plot.add_field(
        seqv[0],
        meshed_region=mesh_new_from
    )
    
    # Mapped Mesh Results
    plot.add_field(
        mapped_res[0],
        meshed_region=mesh_to
    )
    
    plot.show_figure()