Margin of safety > Custom methods
Custom method example
The following example shows how to implement two custom methods using a single Visual Basic routine. Both methods evaluate the margin of safety for Beltrami's energy theory and the Tresca criterion.
In one method, you select the components of stress that the software uses to calculate the working strain energy density for Beltrami's energy theory and the working maximum shear stress for the Tresca criterion.
In the other method, you select nodes or elements for which the software retrieves strain energy density and maximum shear stress results that it uses directly as the working strain energy density and the working maximum shear stress.
An XML file is required for each method.
Beltrami's energy theory
The Beltrami's energy theory states that yielding of a ductile material initiates when the strain energy density equals the strain energy density at yield in a uniaxial tension test.
The strain energy density at yield in a uniaxial tension test is:
{\left( {{U_o}} \right)_{yield}} = \frac{1}{2}{\sigma _{yield}}{\varepsilon _{yield}} = \frac{1}{{2E}}{\sigma _{yield}}^2
where σyield and εyield are the axial stress and strain at yield, respectively, and E is Young's modulus.
Selection of stress component methodIn this implementation of Beltrami's energy theory, you select the stresses that the software uses to calculate the working strain energy density, rather than the software using strain energy density results directly.The advantages of selecting the stresses that the software uses to compute the working strain energy density are as follows:You can use values for Young’s modulus and Poisson's ratio that are different from those used in the FEM.You can select values for the working stresses that the software uses to calculate the working strain energy density from different nodes or elements.The disadvantage is that the method is valid for plane stress only, although a more elaborate implementation to generalize its application is possible.For plane stress, the working strain energy density is:{\left( {{U_o}} \right)_{working}} = \frac{1}{{2E}}\left[ {\sigma _x^2 + \sigma _y^2 - 2\nu {\sigma _x}{\sigma _y} + 2\left( {1 + \nu } \right)\tau _{xy}^2} \right]where σx, σy, and τxy are the in-plane working stresses, E is Young's modulus, and ν is Poisson's ratio.
Direct methodIn this implementation of Beltrami's energy theory, you select the nodes or elements for which the software retrieves strain energy density results that it uses directly as the working strain energy density.The advantage of the direct method is that it is valid for all stress states, rather than just plane stress.
Because the stress and strain vary linearly with the load, the strain energy density varies to the square of the load. Thus, the margin of safety is calculated as follows:
MS = \frac{{{P_{yield}}}}{{{P_{working}}}} - 1 = \sqrt {\frac{{{{\left( {{U_o}} \right)}{yield}}}}{{{{\left( {{U_o}} \right)}{working}}}}} - 1
where Pyield and Pworking are the load at yield and working load, respectively.
Note:
Beltrami's energy theory accounts for both hydrostatic and deviatoric strain energy. In practice it has been obsoleted by the von Mises criterion which accounts for deviatoric strain energy only.
Tresca criterion
The Tresca criterion states that yielding of a ductile material initiates when the maximum shear stress equals the maximum shear stress at yield in a uniaxial tension test.
The maximum shear stress at yield in a uniaxial tension test is:
{\left( {{\tau {\max }}} \right){yield}} = \frac{{{\sigma _{yield}}}}{2}
where σyield is the axial normal stress at yield.
Selection methodIn this implementation of the Tresca criterion, you select the stresses that the software uses to calculate the working maximum shear stress, rather than the software using maximum shear stress results directly.The advantage of selecting the stresses that the software uses to calculate the working maximum shear stress is that you have the flexibility to select values for the working stresses from different nodes or elements.The disadvantage is that the method is valid for plane stress only, although a more elaborate implementation to generalize its application is possible.For plane stress, the in-plane maximum and minimum working stresses are:{\sigma _{\max }} = \left( {\frac{{{\sigma _x} + {\sigma _y}}}{2}} \right) + \sqrt {{{\left( {\frac{{{\sigma _x} - {\sigma _y}}}{2}} \right)}^2} + \tau _{xy}^2} {\sigma _{\min }} = \left( {\frac{{{\sigma _x} + {\sigma _y}}}{2}} \right) - \sqrt {{{\left( {\frac{{{\sigma _x} - {\sigma _y}}}{2}} \right)}^2} + \tau _{xy}^2} where σx, σy, and τxy are the in-plane working stresses.With regard to ordering the principal stresses, σ1 > σ2 > σ3, three cases are possible:σmax > σmin > 0. For this case, σ1 = σmax, σ2 = σmin, and σ3 = 0.σmax > 0 > σmin. For this case, σ1 = σmax, σ2 = 0, and σ3 = σmin.0 > σmax > σmin. For this case, σ1 = 0, σ2 = σmax, and σ3 = σmin.The working maximum shear stress is:{\left( {{\tau {\max }}} \right){working}} = \left( {\frac{{{\sigma _1} - {\sigma _3}}}{2}} \right)
Direct methodIn this implementation of the Tresca criterion, you select the nodes or elements for which the software retrieves maximum shear stress results that it uses directly as the working maximum shear stress.
Because stress varies linearly with the loads, the margin of safety is calculated as follows:
MS = \frac{{{P_{yield}}}}{{{P_{working}}}} - 1 = \frac{{{{\left( {{\tau {\max }}} \right)}{yield}}}}{{{{\left( {{\tau {\max }}} \right)}{working}}}} - 1
XML file for the selection method
For the selection method, the implementation of Beltrami's energy theory requires the input of yield strength, Young's modulus, and Poisson's ratio for the material, and the extraction of the three in-plane working stresses. The implementation of the Tresca criterion requires the input of yield strength and the extraction of the three in-plane working stresses.
<?xml version="1.0" encoding="UTF-8" ?><method id="SelectionMethod" uiname="Selection Method" category="Examples/Visual Basic" docurl="html/SelectionMethod.html"> <description>Computes margins of safety based on Beltrami's energy theory and the Tresca criterion for plane stress.The working strain energy density and maximum shear stress are calculated from individually selected stress components. </description> <failmodes> <mode id="beltrami" uiname="Beltrami"/> <mode id="tresca" uiname="Tresca"/> </failmodes> <input> <parameter id="Syield" uiname="Yield Strength (Syield)" type="scalar" measure="Stress"/> <parameter id="Emod" uiname="Elastic Modulus (Emod)" type="scalar" measure="Stress"/> <parameter id="nu" uiname="Poisson Ratio (nu)" type="scalar" measure="Unitless"/> <parameter id="Sx" uiname="Normal Stress in X-direction (Sx)" type="load_extraction" aggregation="user" measure="Stress"/> <parameter id="Sy" uiname="Normal Stress in Y-direction (Sy)" type="load_extraction" aggregation="user" measure="Stress"/> <parameter id="Sxy" uiname="Shear Stress in XY-plane (Sxy)" type="load_extraction" aggregation="user" measure="Stress"/> </input></method>
XML file for the direct method
For the direct method, the implementation of Beltrami's energy theory requires the input of yield strength and Young's modulus for the material, and the extraction of the working strain energy density. The implementation of the Tresca criterion requires the input of yield strength, and the extraction of the working maximum shear stress.
<?xml version="1.0" encoding="UTF-8" ?><method id="DirectMethod" uiname="Direct Method" category="Examples/Visual Basic" docurl="html/DirectMethod.html"> <description>Computes margins of safety based on Beltrami's energy theory and the Tresca criterion for plane stress.The working strain energy density and maximum shear stress are obtained directly from the results. </description> <failmodes> <mode id="beltrami" uiname="Beltrami"/> <mode id="tresca" uiname="Tresca"/> </failmodes> <input> <parameter id="Syield" uiname="Yield Strength (Syield)" type="scalar" measure="Stress"/> <parameter id="Emod" uiname="Elastic Modulus (Emod)" type="scalar" measure="Stress"/> <parameter id="strain_energy_density" uiname="Strain Energy Density (strain_energy_density)" type="load_extraction" aggregation="user" measure="Stress"/> <parameter id="max_shear_stress" uiname="Maximum Shear Stress (max_shear_stress)" type="load_extraction" aggregation="user" measure="Stress"/> </input></method>
Visual Basic file
The Visual Basic routine contains the calculations for all four failure modes with the user-selected stress component methods in one class and the direct methods in another class.
'HEAD CustomMethod VB AEROSTRUCT */'===========================================================================' Description'===========================================================================' This routine computes margins of safety based on Beltrami's energy theory' and the Tresca criterion. Two approaches to each failure mode are coded.' One approach constructs the working loads from components of stress that' the user selects. The other approach uses results for the nodes or elements' directly as the working loads. Each approach is implemented as a separate' class.' Method inputs' Syield Yield strength for the material' Emod Elastic modulus for the material' nu Poisson's ratio for the material' Sx Normal stress in x-direction' Sy Normal stress in y-direction' Sxy Shear stress in the xy-plane' Method outputs' MS_Beltrami Margin of safety based upon Beltrami's energy theory' MS_Tresca Margin of safety based on the Tresca criterion' Import the NXOpen modules required by SimCenter AerostructuresImports SystemImports NXOpenImports NXOpen.UtilitiesImports ObjMgr = NXOpen.Utilities.NXObjectManagerImports Author = NXOpen.CAE.AeroStructures.Author' Define a class with one Evaluate method. The name of the class must' match the method id defined in the method's xml descriptorPublic Class SelectionMethod Public Function Evaluate(ByRef calculationContext As Author.CalculationContext) ' Obtain session and part objects Dim theSession As NXOpen.Session = NXOpen.Session.GetSession() Dim workSimPart As NXOpen.CAE.SimPart = CType(theSession.Parts.BaseWork, NXOpen.CAE.SimPart) Dim displaySimPart As NXOpen.CAE.SimPart = CType(theSession.Parts.BaseDisplay, NXOpen.CAE.SimPart) Dim abb As Author.ABB = Author.ABB.GetABB(theSession) ' Define the identifiers of the computed failure modes. Must match the failmodes ids from the xml file. Dim BeltramiFailureMode As String = "beltrami" Dim TrescaFailureMode As String = "tresca" ' Get input and output parameters from context. Parameter names are defined in the xml file. Dim Syield_Param As Author.InputScalar = CType(calculationContext.GetInput("Syield"), Author.InputScalar) Dim Emod_Param As Author.InputScalar = CType(calculationContext.GetInput("Emod"), Author.InputScalar) Dim nu_Param As Author.InputScalar = CType(calculationContext.GetInput("nu"), Author.InputScalar) Dim Sx_Param As Author.InputLoad = CType(calculationContext.GetInput("Sx"), Author.InputLoad) Dim Sy_Param As Author.InputLoad = CType(calculationContext.GetInput("Sy"), Author.InputLoad) Dim Sxy_Param As Author.InputLoad = CType(calculationContext.GetInput("Sxy"), Author.InputLoad) Dim MS_Param As Author.OutputScalar = CType(calculationContext.GetOutputMs(), Author.OutputScalar) ' Find the number of loadcases in the context Dim loadCases() As NXOpen.CAE.AeroStructures.LoadCase calculationContext.GetLoadCaseArray(loadCases) Dim loadCaseCount As Integer = loadCases.GetLength(0) ' Get stress tables from the extracted load cases Dim Sx_Table As NXOpen.GeneralScalarTable = Sx_Param.Values() Dim Sy_Table As NXOpen.GeneralScalarTable = Sy_Param.Values() Dim Sxy_Table As NXOpen.GeneralScalarTable = Sxy_Param.Values() ' Fetch material properties from the input parameters Dim Syield, Emod, nu As Double Syield = Syield_Param.Value Emod = Emod_Param.Value nu = nu_Param.Value ' Do some parameter checking If (Syield <= 0) Then calculationContext.Error("SelectionMethod", -1, "Yield strength must be positive") Return False End If If (Emod <= 0) Then calculationContext.Error("SelectionMethod", -1, "Elastic modulus must be positive") Return False End If If (nu < 0 Or nu > 0.5) Then calculationContext.Error("SelectionMethod", -1, "Poisson ratio must be in [0,0.5] range") Return False End If ' Compute the two MS values (Beltrami and Tresca) for each load case and store them into the output parameter For loadcaseIndex As Integer = 0 To loadCaseCount - 1 Dim Smax, Smin, S1, S3, Sx, Sy, Sxy, Uwork, MS_Beltrami, MS_Tresca As Double ' Fetch input stresses for each load case. ' In case of a load extraction with user aggregation, the table of ' values has only a single column, hence 0 as 2nd argument of GetCellValue(). ' (in case of method aggregation, the table of values has as many columns as ' the number of selected elements / nodes of the load extraction input) ' See NXOpen::CAE::Aerostructures::Author::InputLoad for more information. Sx = Sx_Table.GetCellValue(loadcaseIndex, 0) Sy = Sy_Table.GetCellValue(loadcaseIndex, 0) Sxy = Sxy_Table.GetCellValue(loadcaseIndex, 0) calculationContext.Log(BeltramiFailureMode, loadcaseIndex, "Sx=" + Convert.ToString(Sx)) calculationContext.Log(BeltramiFailureMode, loadcaseIndex, "Sy=" + Convert.ToString(Sy)) calculationContext.Log(BeltramiFailureMode, loadcaseIndex, "Sxy=" + Convert.ToString(Sxy)) ' Compute working strain energy density Uwork Uwork = (1 / (2 * Emod)) * (Sx ^ 2 + Sy ^ 2 - 2 * nu * Sx * Sy + 2 * (1 + nu) * (Sxy ^ 2)) calculationContext.Log(BeltramiFailureMode, loadcaseIndex, "Uwork=" + Convert.ToString(Uwork)) ' Compute max/min in-plane working stresses Smax and Smin Dim Si As Double = Math.Sqrt(((Sx - Sy) / 2) ^ 2 + Sxy ^ 2) calculationContext.Log(TrescaFailureMode, loadcaseIndex, "Si=" + Convert.ToString(Si)) Smax = (Sx + Sy) / 2 + Si Smin = (Sx + Sy) / 2 - Si If (Smax > 0 And Smin >= 0) Then S1 = Smax S3 = 0 ElseIf (Smax >= 0 And Smin <= 0) Then S1 = Smax S3 = Smin ElseIf (Smax <= 0 And Smin < 0) Then S1 = 0 S3 = Smin End If ' Compute the two margins of safety MS_Beltrami = Math.Sqrt(((1 / (2 * Emod)) * Syield ^ 2) / Uwork) - 1 MS_Tresca = Syield / (S1 - S3) - 1 ' Add the calculated MS values to the output parameter MS_Param.SetValue(BeltramiFailureMode, loadcaseIndex, MS_Beltrami) MS_Param.SetValue(TrescaFailureMode, loadcaseIndex, MS_Tresca) ' Write the results to the calculation log calculationContext.Log(BeltramiFailureMode, loadcaseIndex, "MS_Beltrami=" + Convert.ToString(MS_Beltrami)) calculationContext.Log(TrescaFailureMode, loadcaseIndex, "MS_Tresca=" + Convert.ToString(MS_Tresca)) Next Return True End FunctionEnd Class' Define a class with one Evaluate method. The name of the class must' match the method id defined in the method's xml descriptorPublic Class DirectMethod Public Function Evaluate(ByRef calculationContext As Author.CalculationContext) ' Obtain session and part objects Dim theSession As NXOpen.Session = NXOpen.Session.GetSession() Dim workSimPart As NXOpen.CAE.SimPart = CType(theSession.Parts.BaseWork, NXOpen.CAE.SimPart) Dim displaySimPart As NXOpen.CAE.SimPart = CType(theSession.Parts.BaseDisplay, NXOpen.CAE.SimPart) Dim abb As Author.ABB = Author.ABB.GetABB(theSession) ' Define the identifiers of the computed failure modes. Must match the failmodes ids from the xml file. Dim BeltramiFailureMode As String = "beltrami" Dim TrescaFailureMode As String = "tresca" ' Get input and output parameters from context. Parameter names are defined in the xml file. Dim Syield_Param As Author.InputScalar = CType(calculationContext.GetInput("Syield"), Author.InputScalar) Dim Emod_Param As Author.InputScalar = CType(calculationContext.GetInput("Emod"), Author.InputScalar) Dim energy_Param As Author.InputLoad = CType(calculationContext.GetInput("strain_energy_density"), Author.InputLoad) Dim shear_Param As Author.InputLoad = CType(calculationContext.GetInput("max_shear_stress"), Author.InputLoad) Dim MS_Param As Author.OutputScalar = CType(calculationContext.GetOutputMs(), Author.OutputScalar) ' Find the number of loadcases in the context Dim loadCases() As NXOpen.CAE.AeroStructures.LoadCase calculationContext.GetLoadCaseArray(loadCases) Dim loadCaseCount As Integer = loadCases.GetLength(0) ' Get tables from the extracted load cases Dim energy_Table As NXOpen.GeneralScalarTable = energy_Param.Values() Dim shear_Table As NXOpen.GeneralScalarTable = shear_Param.Values() ' Fetch material properties from the input parameters Dim Syield, Emod As Double Syield = Syield_Param.Value Emod = Emod_Param.Value ' Do some parameter checking If (Syield <= 0) Then calculationContext.Error("DirectMethod", -1, "Yield strength must be positive") Return False End If ' Compute the two MS values (Beltrami and Tresca) for each load case and store them into the output parameter For loadcaseIndex As Integer = 0 To loadCaseCount - 1 Dim energy_d, max_shear, MS_Beltrami, MS_Tresca As Double ' Fetch input for each load case. ' In case of a load extraction with user aggregation, the table of ' values has only a single column, hence 0 as 2nd argument of GetCellValue(). ' (in case of method aggregation, the table of values has as many columns as ' the number of selected elements / nodes of the load extraction input) ' See NXOpen::CAE::Aerostructures::Author::InputLoad for more information. energy_d = energy_Table.GetCellValue(loadcaseIndex, 0) max_shear = shear_Table.GetCellValue(loadcaseIndex, 0) calculationContext.Log(BeltramiFailureMode, loadcaseIndex, "energy_d=" + Convert.ToString(energy_d)) calculationContext.Log(BeltramiFailureMode, loadcaseIndex, "max_shear=" + Convert.ToString(max_shear)) ' Energy must be positive If (energy_d <= 0) Then calculationContext.Error("DirectMethod", -1, "Strain energy density must be positive") Return False End If ' Compute the two margins of safety MS_Beltrami = Math.Sqrt(((1 / (2 * Emod)) * Syield ^ 2) / energy_d) - 1 MS_Tresca = (Syield / 2) / Math.Abs(max_shear) - 1 ' Add the calculated MS values to the output parameter MS_Param.SetValue(BeltramiFailureMode, loadcaseIndex, MS_Beltrami) MS_Param.SetValue(TrescaFailureMode, loadcaseIndex, MS_Tresca) ' Write the results to the calculation log calculationContext.Log(BeltramiFailureMode, loadcaseIndex, "MS_Beltrami=" + Convert.ToString(MS_Beltrami)) calculationContext.Log(TrescaFailureMode, loadcaseIndex, "MS_Tresca=" + Convert.ToString(MS_Tresca)) Next Return True End FunctionEnd Class
XMD file
The name of the .xmd file must match the file name of the Visual Basic routine.
<?xml version="1.0" encoding="utf-8" ?><module type="script" xmlns:xsi=" xsi:noNamespaceSchemaLocation="aerostructures_module.xsd"> <method path="SelectionMethod.xml" /> <method path="DirectMethod.xml" /></module>
Learn more
Custom methods
Creating tables and groups
Interfacing with external files
Diagrams for custom methods
Specifying default values for parameters
Bulk processing of calculations
Interfacing with external post-processors
Look up more details
Elements and attributes of XML files
Quick links
Command reference
Pre/Post video examples
Bulk Entry Descriptions
Simcenter 3D tutorials
Browse Simcenter 3D help by product area
Margin of Safety methods documentation
Custom method example, Simcenter 3D 2021.1 Series
© 2020 Siemens
window.mainLanguage="en_US"
window.delivId=""
window.projectId=""
MathJax.Hub.Config({ TeX: { extensions: ["autoload-all.js"] }, tex2jax: { displayMath: [ ] }, "SVG": { scale: 125 } });
Source: https://docs.sw.siemens.com/en-US/doc/289054037/PL20200601120302950.advanced/xid1484406 · retrieved 2026-07-17