How to get the material properties for defined element using Mechanical API or DPF?
Hello team,
I'm creating a script that gets the stress values in elements defined by element Id and would like to compare the stress values with the ultimate ones for material automatically. So, I wonder how to get the values of material properties for the element with a defined Id using Mechanical API or DPF?
Thanks
Answers
-
The following code:
import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) dataSources = mech_dpf.GetDataSources(2) mat_op = dpf.operators.metadata.material_provider() mat_op.inputs.data_sources.Connect(dataSources) mats = mat_op.outputs.materials.GetData()
bringing error:
Could not find the specified Output Type.
Why showed code doesn't work?
0 -
This example in the PyDPF documentation can be adapted to Mechanical DPF: https://dpf.docs.pyansys.com/version/0.8/examples/00-basic/12-get_material_properties.html
0 -
See this post for a Mechanical implementation: https://discuss.ansys.com/discussion/2554/python-result-example-plot-young-modulus-on-elements/p1?new=1
1 -
@Pernelle Marone-Hitz said:
See this post for a Mechanical implementation: https://discuss.ansys.com/discussion/2554/python-result-example-plot-young-modulus-on-elements/p1?new=1Hello Pernelle,
I used the proposed approach and it worked well but then I tried to run this script in Ansys Mechanical 2021R2 and got the error:
'MeshedRegion' object has no attribute 'GetPropertyField'
The possible reason is that there is no method GetPropertyField("mat") for 'MeshedRegion' object in the 2021R2 release of DPF. What is the best approach to get the values of material properties for the element with a defined ID in the 2021R2 release?Thanks
0 -
Hi @dafedin , unfortunately there is a bug in older versions with GetPropertyField("mat") . Please upgrade to 2023R2. Sorry for the inconvenience.
1 -
Hello Pernelle,
I have already upgraded to 2023R2 but our customers haven't. Maybe there is a way to do it using another API.
Thanks
0 -
Hi, as far as I'm aware there isn't, but I might have missed it. Let's see if some else chimes in.
1 -
@Pernelle Marone-Hitz @dafedin
How about the materials module for Mechanical? This module can be imported and gives access to material properties that are in Workbench/Mechanical. I think this is also covered in the intro to Mechanical scripting course
0 -
@Mike.Thompson @dafedin I thought the question was around DPF. Sure in Mechanical scripting we can use the materials module. There are many examples on the forum (for example, this one: https://discuss.ansys.com/discussion/35/can-you-provide-an-example-of-using-the-materials-module-in-mechanical) This approach would however be more convoluted: in Mechanical the material properties are tied to a body, so to know the materials property for a specific element ID you'll have to use MeshData to link the elem id to the body id.
0