Use Mechanical DPF to define a "path" and calculate/integrate stress along it

Mike.Thompson Member, Employee Posts: 239
First Anniversary First Comment 5 Likes Ansys Employee
edited June 2023 in Structures

How can we define a conceptual path (not an actual path + result in the tree) in DPF in Mechanical. I want to define the path with start+end points and # of divisions. I then want to map a stress result to those path points and then possibly also do a length-normalized average or integration along that path.

Anybody have examples of this?


Best Answer

  • M
    M Member, Employee Posts: 199
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    edited May 2023 Answer ✓
    # example to create 1 path and generate multiple stress results on it ~~~~~~~~~~~
    import os
    import matplotlib.pyplot as plt
    from ansys.dpf import core as dpf
    from ansys.dpf.core import operators as ops
    from ansys.dpf.core.plotter import DpfPlotter
    import numpy as np
    result_dict = {} # not used, customer wanted only 1st/last result
    path2rst = r'mypath'
    example_path = os.path.join(path2rst,'file.rst')  
    model = dpf.Model(example_path)
    mesh = model.metadata.meshed_region
    stress_fc = model.results.stress().eqv().eval()
    stressX = model.results.stress().X().eval() 
    stressY = model.results.stress().Y().eval()
    stressZ = model.results.stress().Z().eval()
    stresses = {'X':stressX, 'Y': stressY , 'Z': stressZ , 'EQV': stress_fc}
    # Here you can use any coordinates for the start/end. Robust, doesn't care if you are in the model or not!
    startCoordinate = [0,0,0]
    endCoordinate = [1000,500,1000]
    ipoints = 100  # in between points, must be >= 0 obviously
    dxyz = (np.array(endCoordinate) - np.array(startCoordinate))/(ipoints+1) # delta for xyz
    pathCoordinates = [startCoordinate]
    for i in range(1,ipoints+2):
        pathCoordinates.append((startCoordinate + i * dxyz).tolist())
    field_coord = dpf.fields_factory.create_3d_vector_field(len(pathCoordinates)) = pathCoordinates
    field_coord.scoping.ids = list(range(1, len(pathCoordinates) + 1))
    for stress in stresses:
        stressModel = stresses[stress]
        mapping_operator = ops.mapping.on_coordinates(
        fields_container=stressModel, coordinates=field_coord, create_support=True, mesh=mesh)
        fields_mapped = mapping_operator.outputs.fields_container()
        field_m = fields_mapped[0]
        mesh_m = field_m.meshed_region
        pl = DpfPlotter()
        pl.add_field(field_m, mesh_m)
        pl.add_mesh(mesh, style="surface", show_edges=True, color="w", opacity=0.3)
        # Plot the result.