Create a Python result to plot the node ID
![Pernelle Marone-Hitz](https://us.v-cdn.net/6037473/uploads/userpics/4AG2SAGAOHUA/nTB4DQJCWAJV4.jpg)
![Ansys Employee](https://us.v-cdn.net/6037473/uploads/badges/RVRDV39KPJ91.png)
![Solution Developer Community of Practice Member](https://us.v-cdn.net/6037473/uploads/badges/274G8C56SBE6.png)
Do we have an example of Python result to create a new field, assign the node ids to each node and plot this back to the Mechanical model ?
Best Answer
-
The below script can be used. The trick is to use the forward_field() method to send the field to an operator to be able to plot it.
def post_started(sender, analysis):# Do not edit this line define_dpf_workflow(analysis) def define_dpf_workflow(analysis): import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) dataSource = dpf.DataSources(analysis.ResultFileName) # Read mesh in results file mesh_op = dpf.operators.mesh.mesh_provider() # operator instanciation mesh_op.inputs.data_sources.Connect(dataSource) mesh = mesh_op.outputs.mesh.GetData() # retrieve displacement uZ = dpf.operators.result.displacement_Z() uZ.inputs.data_sources.Connect(dataSource) nIds = uZ.outputs.fields_container.GetData()[0].ScopingIds data = uZ.outputs.fields_container.GetData()[0].Data # create new field and assign values my_field = dpf.FieldsFactory.CreateScalarField(numEntities=0, location='Nodal') my_field.MeshedRegionSupport = mesh for i in nIds: my_field.Add(i,[float(i)]) my_field.ScopingIds = nIds #my_field.Data = [0.05 for i in range(0,len(data))] # forward field to an operator to plot it forward = dpf.operators.utility.forward_field() forward.inputs.field.Connect(my_field) dpf_workflow = dpf.Workflow() dpf_workflow.Add(forward) dpf_workflow.SetOutputContour(forward,dpf.enums.GFXContourType.FENodalScoping) dpf_workflow.Record('wf_id', False) this.WorkflowId = dpf_workflow.GetRecordedId()
5
Answers
-
Hey @Pernelle Marone-Hitz how can I use values from user defined plots in python result plot ? mainly for calculations such as sqrt(SXY^2 + SXZ^2) for example?
My end result is to have a certain calculation using stress tensor values (SX,SY,SXY,...) performed on a path (Weld Path). But I need to get the SX,SY.... values form preferably predefined "user defined result plots" which take into account the element orientations as the direction of the stresses need to be aligned to the weld !!
0 -
Hi @Kev , please have a look at this post: https://discuss.ansys.com/discussion/2080/convert-plotdata-of-user-defined-result-to-a-dpf-field-and-plot-it#latest But if what you need is the stress tensor values, you don't need to create a user-defined result, these can be obtained directly in DPF.
0