On a layer element in the Mechanical tree, you can create an ACT result object to access the elemental stress (bending stress and membrane stress) and display it as a custom result.
The following XML file adds a toolbar with a single button for creating a custom stress result on a layer element.
<extension version="1" minorversion="0" name="ACTResult"> <author>Ansys Inc.</author> <description>ACT layer result</description> <guid shortid="ACTResults">****</guid> <script src="main.py" /> <interface context="Mechanical"> <images>images</images> <toolbar name="ACTResults" caption="ACTResults"> <entry name="LayerStressElem" icon="LayerActRes"> <callbacks> <onclick>CreateLayerStressElem</onclick> </callbacks> </entry> </toolbar> </interface> <simdata context="Mechanical"> <result name="LayerStressElem" version="1" caption="LayerStressElem" unit="Stress" icon="result" location="element" type="scalar" class="ActResController"> <property name="Geometry" caption="Geometry" control="scoping"></property> <property name="Layer" caption="Layer" control="integer" default="0"></property> <property name="StressStyle" caption="Stress Style" control="select" default="Membrane"> <attributes options="Membrane,Bending"></attributes> </property> <property name="Orientation" caption="Orientation" control="select" default="Longitudinal"> <attributes options="Longitudinal,Transverse,InPlanShear"></attributes> </property> <callbacks> <evaluate>EvaluateLayerStressElem</evaluate> </callbacks> </result> </simdata> </extension>
In this file, the element <script>
references the
IronPython script main.py
. The element
<interface>
defines the toolbar and a button.
In the child element <callbacks>
, the single
callback <onclick>
invokes the function
CreateLayerStressElem
, which creates and adds the
result to the simulation environment.
The element <simdata>
defines the result.
The attributes in the child element
<result>
provide the name, version, caption, unit, and icon that apply to the result. These properties display in the Details view of Mechanical when the result is selected in the Outline view. The Details view shows each property with the corresponding names and result values.In the child element
<callbacks>
, the single callback<evaluate>
invokes the functionEvaluateLayerStressElem
when Mechanical requests an evaluation. The output of this function is sent directly to Mechanical, which displays the result.
The IronPython script main.py
follows. This sample
code shows how to create the result object, calculate the result, and set up
the result reader. For more information on the result reader, see Retrieving Mechanical Results More Efficiently.
def CreateLayerStressElem(analysis): analysis.CreateResultObject("LayerStressElem",ExtAPI.ExtensionManager.CurrentExtension) def EvaluateLayerStressElem(result, stepInfo, collector): result.Controller.EvaluateLayerStressElem(result, stepInfo, collector) class ActResController: def __init__(self, api, result): pass def EvaluateLayerStressElem(self, result, stepInfo, collector): reader = result.Analysis.GetResultsData() # get the layer number and set up the reader reader.Layer = result.Properties["Layer"].Value # get the LayeredSolidStressStyle stressStyle_value = result.Properties["StressStyle"].Value stress_style = self.stressStyle(stressStyle_value) reader.LayeredSolidStressStyle = stress_style #get the shell stress orientation orientation_value = result.Properties["Orientation"].Value shell_orientation = self.shellStressOrientation(orientation_value) reader.CurrentResultSet = stepInfo.Set if (stress_style == StressStyle.Bending): stress_result = reader.GetResult("BENDING_STRESS") stress_result.SelectComponents([shell_orientation]) elif (stress_style == StressStyle.Membrane): stress_result = reader.GetResult("MEMBRANE_STRESS") stress_result.SelectComponents([shell_orientation]) for id in collector.Ids: values = stress_result.GetElementValues(id) collector.SetValues(id,values) def stressStyle(self,argument): switcher = { "Membrane":StressStyle.Membrane, "Bending":StressStyle.Bending } return switcher.get(argument, StressStyle.TopAndBottom) def shellStressOrientation(self,argument): switcher = { "Longitudinal":"_LONGITUDINAL", "Transverse":"_TRANSVERSE", "InPlaneShear":"_IN_PLANE_SHEAR" } return switcher.get(argument, "_LONGITUDINAL")