Contour Plots on Changed Mesh (NLAD) using Python Result object (DPF) in Mechanical

George Tzortzopoulos
George Tzortzopoulos Member, Employee Posts: 8
10 Comments Name Dropper Photogenic

How could I generate contour plots of custom results on a changed mesh (NLAD) during the solution in Mechanical?


  • George Tzortzopoulos
    George Tzortzopoulos Member, Employee Posts: 8
    10 Comments Name Dropper Photogenic
    edited October 18

    In order to generate such contour plots, the Python Result object in Mechanical should be used.
    As postprocessing tools for results with adaptive (NLAD) mesh haven't been implemented in DPF yet, the ACT reader should be employed to extract mesh data, necessary to create the contour plot.

    Python Result Script

    def define_dpf_workflow(analysis):
        import mech_dpf
        import Ans.DataProcessing as dpf
        dataSource = dpf.DataSources(analysis.ResultFileName)
        resultSet = 58
        rdr = analysis.GetResultsData() # use ACT reader
        rdr.CurrentResultSet = resultSet # select preferred result set
        act_mesh = rdr.CreateMeshData() # read data of the changed mesh for the above result set
        node_Ids = act_mesh.NodeIds # get node IDs for the changed mesh
        u_results = rdr.GetResult("U") # read displacements
        u_results.SelectComponents(["X", "Y", "Z"]) # select all the components X, Y, Z
        u_vals = u_results.GetNodeValues(node_Ids) # get nodal displacements (for displaying the deformed mesh)
        u_results.SelectComponents(["Y"]) # select only the Y component
        uy_vals = u_results.GetNodeValues(node_Ids) # get nodal displacements ("custom" result)
        # convert ACT mesh to DPF mesh
        mesh_op = dpf.operators.mesh.acmo_mesh_provider()
        dpf_mesh = mesh_op.outputs.getmeshes_container()[0]
        dpf_mesh.Unit = "mm"
        # create a scalar DPF field for the "custom" nodal result
        my_uy = dpf.FieldsFactory.CreateScalarField(len(node_Ids),'Nodal')
        my_uy.Scoping.Ids = node_Ids
        my_uy.Data = uy_vals
        my_uy.Unit = "mm"
        op = dpf.operators.utility.forward()
        # create a 3D vector DPF field for displaying the result at the deformed mesh      
        my_u = dpf.FieldsFactory.Create3DVectorField(len(node_Ids),'Nodal')
        my_u.Scoping.Ids = node_Ids
        my_u.Data = u_vals
        my_u.Unit = "mm"
        # create a DPF Fields Container and set Time Scoping
        my_u_fc = dpf.FieldsContainer()
        my_u_fc.Labels = ["time"]
        my_u_fc.Add(my_u, {"time": resultSet})
        tfs = dpf.operators.metadata.time_freq_provider()
        dpf_workflow = dpf.Workflow()
        dpf_workflow.Add(op) # add the operator which contains the "custom" result
        dpf_workflow.SetOutputContour(op) # set the contour of the "custom" result
        dpf_workflow.SetOutputMesh(dpf_mesh) # set the changed mesh (NLAD)
        dpf_workflow.SetOutputWarpField(my_u_fc) # set the 3D vector fields container for defining the deformed mesh
        dpf_workflow.Record('wf_id', False)
        this.WorkflowId = dpf_workflow.GetRecordedId()