How can I use DPF to retrieve stress data on surface coating elements and plot those results in Mechanical ?
First, it is important to understand that there are two options to create surface coating elements in Mechanical.
Option 1: Define a surface coating object at the geometry level
Option 2: Add a Mesh Edit / Pull / Surface coating object Once generated, this will create a new surface body in the geometry:
To post-process the results through the Mechanical UI, the procedure will be different based on how these surface coating elements were generated:
Option 1: Add a result and use the geometry scoping
Option 2: Add a result but this time set scoping method to "Surface coating"
As the surface coating objects are created differently, the way to retrieve the result data through DPF will slightly differ:
The rest of the method is very similar:
The main Python Result function define_dpf_workflow() will slighlty differ for the two options:
def define_dpf_workflow(analysis): # import DPF and define data sources import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) dataSource = dpf.DataSources(analysis.ResultFileName) model = dpf.Model(dataSource) # retrieve entire mesh whole_mesh = model.Mesh # retrieve nodal Von Mises stress seqv = dpf.operators.result.stress_von_mises() seqv.inputs.data_sources.Connect(dataSource) seqv.inputs.requested_location.Connect(dpf.locations.nodal) # identify surface coating elements surface_coating = ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.SurfaceCoating)[0] solver_data = analysis.Solution.SolverData coating_data = solver_data.GetObjectData(surface_coating) matid_sc_1 = coating_data.MaterialId.ToString() surface_coating_elements = solver_data.ElementIdsByMaterialId(matid_sc_1) # define mesh scoping for surface coating elements mesh_scoping=dpf.Scoping() mesh_scoping.Location = dpf.locations.elemental mesh_scoping.Ids=surface_coating_elements # restrict stress results to surface coating elements seqv.inputs.mesh_scoping.Connect(mesh_scoping) # get mesh for surface coating elements only mesh_from_scoping = dpf.operators.mesh.from_scoping() mesh_from_scoping.inputs.scoping.Connect(mesh_scoping) mesh_from_scoping.inputs.mesh.Connect(whole_mesh) my_mesh = mesh_from_scoping.outputs.getmesh() dpf_workflow = dpf.Workflow() dpf_workflow.Add(seqv) # plot on restricted mesh dpf_workflow.SetOutputMesh(my_mesh) dpf_workflow.SetOutputContour(seqv) dpf_workflow.Record('wf_id', False) this.WorkflowId = dpf_workflow.GetRecordedId()
def define_dpf_workflow(analysis): # import DPF and define data sources import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) dataSource = dpf.DataSources(analysis.ResultFileName) model = dpf.Model(dataSource) # retrieve entire mesh whole_mesh = model.Mesh # retrieve nodal Von Mises stress seqv = dpf.operators.result.stress_von_mises() seqv.inputs.data_sources.Connect(dataSource) seqv.inputs.requested_location.Connect(dpf.locations.nodal) # identify surface coating elements surface_coating = ExtAPI.DataModel.GetObjectsByName('Surface body from mesh edit pull')[0] solver_data = analysis.Solution.SolverData coating_data = solver_data.GetObjectData(surface_coating) matid_sc_1 = coating_data.MaterialIds[0].ToString() surface_coating_elements = solver_data.ElementIdsByMaterialId(matid_sc_1) # define mesh scoping for surface coating elements mesh_scoping=dpf.Scoping() mesh_scoping.Location = dpf.locations.elemental mesh_scoping.Ids=surface_coating_elements # restrict stress results to surface coating elements seqv.inputs.mesh_scoping.Connect(mesh_scoping) # get mesh for surface coating elements only mesh_from_scoping = dpf.operators.mesh.from_scoping() mesh_from_scoping.inputs.scoping.Connect(mesh_scoping) mesh_from_scoping.inputs.mesh.Connect(whole_mesh) my_mesh = mesh_from_scoping.outputs.getmesh() dpf_workflow = dpf.Workflow() dpf_workflow.Add(seqv) # plot on restricted mesh dpf_workflow.SetOutputMesh(my_mesh) dpf_workflow.SetOutputContour(seqv) dpf_workflow.Record('wf_id', False) this.WorkflowId = dpf_workflow.GetRecordedId()
In both cases we are able to get the same results as in Mechanical:
Option 1:
Option 2: