How to plot within a Python result the total stiffness energy in a named selection with ansys dpf ?

Adrien Vet
Adrien Vet Member Posts: 10
Name Dropper Photogenic First Comment
**
edited June 2023 in Structures

Hello everyone,

As the title suggest, I want to plot within a Python result the total stiffness energy in a named selection with ansys dpf.

I made something that plot the stiffness energy by element on a given named selection, and I think I have to use fields operators to plot the total stiffness energy on the named selection, for exemple :

1) by summing all the fields elements (because the total stiffness energy is the sum of all the elemental stiffness energy)

2) by taking the average value of the field and mutliply by the number of element in the named selection, with do the same thing

Here is my code in my Python result :

def post_started(sender, analysis):

  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)

  model = dpf.Model(dataSource)

# I retrieve my named selection by its name in python result custom properties

  R=model.GetNamedSelection(this.GetCustomPropertyByPath("Énergie de déformation modale/Sélection").ValueString)

  E = dpf.operators.result.stiffness_matrix_energy()

# I take the average value of E (I will multiply it by the number of elements once i'm sure this works first wich is not the case yet)

  E_totale = dpf.operators.math.average_over_label_fc(E)

  E.inputs.data_sources.Connect(dataSource)

# I only want to plot it for the named selection

  E.inputs.mesh_scoping.Connect(R)

  dpf_workflow = dpf.Workflow()

  dpf_workflow.Add([E, E_totale])

  dpf_workflow.SetOutputContour(E_totale)

  dpf_workflow.Record('wf_energy', False)

  this.WorkflowId = dpf_workflow.GetRecordedId()


When I "evaluate all results", under my solution (I'm in a modal analysis), I got this error message and ansys mechanical crashes :

Does anyone have any idea to help me ? Thank you,

Adrien