HMath-5000: Using HyperMath in HyperView Results Math |
![]() |
![]() |
![]() |
![]() |
|
HMath-5000: Using HyperMath in HyperView Results Math |
![]() |
![]() |
![]() |
![]() |
In this tutorial, you will learn how to create a new derived results type using a HyperMath script.
Step 1: Launch HyperMath and create a script.
1. | After launching HyperMath, create a file titled HyperMath_Brittle.hml with the content shown below: |
function Hml_BrittleMatFailureTheory()
{
id = GetID();
partid = GetPartID();
t1 = GetTensor("P1");
t3 = GetTensor("P3");
p1 = t1[1];
p3 = t3[1];
ns = 0.0;
sut = 0.67
suc = -0.97
// Calculate failure value
if (p1 > 0 && p3 < 0) then
ns = 1/( (p1/sut) - (p3/suc) )
elseif ( p3 >= 0 && p1 > 0) then
ns = sut/p1
elseif ( p1 <= 0 && p3 > 0) then
ns = suc/p3;
end
// Add the value
AddRecord(id, ns);
}
2. | The script identifies the elements which fail the brittle material failure theory. The script works as follows: |
a. | HyperView passes the element ID, which is stored as the variable id. |
b. | The part ID, which the element belongs to, is stored as the variable partid. |
c. | The Maximum (P1) and Minimum principal (P3) stress tensor of the element is initially stored as vectors t1 and t3, respectively. It is then extracted as a number and stored as variables p1 and p3. |
d. | The maximum stress for tension and compression is identified with the variables sut and suc, respectively. |
e. | The failure values are calculated and assigned to variable ns |
f. | The element ID and failure value is sent back to HyperView using the AddRecord statement. |
Step 2: Register the script using a preference file.
1. | Create a post_rmath.mvw file in any text editor with the content shown below: |
*Id("HyperStudy v11.0")
*BeginDefaults()
{rmath_template_dir = getenv("ALTAIR_HOME") + "/io/result_readers/rmxml"}
*BeginGraphicDefaults()
*RegisterResultMathPlugin(Brittle_Calcs, "Brittle failure theory", HYPERMATH, "<your_location>/HyperMath_Brittle.hml", SCALAR, ELEM, "", "Hml_BrittleMatFailureTheory", "")
*RegisterResultMathTemplate("Standard", {rmath_template_dir + "/standard.xml"})
*RegisterResultMathTemplate("Advanced", {rmath_template_dir + "/advanced.xml"})
*RegisterResultMathTemplate("NVH", {rmath_template_dir + "/nvh.xml"})
*RegisterResultMathTemplate("Composite", {rmath_template_dir + "/composite.xml"})
*DefaultResultMathTemplate("Standard")
*ResultMathState("On")
*EndGraphicDefaults()
*EndDefaults()
2. | In the example above, modify the highlighted part to reflect the path of HyperMath_Brittle.hml (from Step 1) on your computer (for example, 'c:/demo/HyperMath_Brittle.hml’). |
3. | Save the file. |
Step 3: Launch HyperView
1. | From the File Menu, select Load > Preference File. |
2. | Click Register and select the file created in Step 2: post_rmath.mvw. |
3. | From the Preferences dialog, highlight the file post_rmath.mvw. |
4. | Right-click on the highlighted filename and press Load. |
The preference file is now loaded and the Preferences dialog should automatically close.
5. | Click Open and load bullet_local.h3d or bullet_local.op2 file as both the model and results. The file is located in the animation folder |
6. | Make sure the Result-Math template: is set to Advanced. |
7. | Click Apply. |
8. | From the Results Menu, select Create > Derived Results. |
9. | In the Expression Builder window, change Label: to Brittle. |
10. | Make sure the Output: is set to All loadcase. |
11. | Change the Library: to Plugins. |
12. | Highlight the Brittle_Calcs plugin and double-click on it to add to the Expression: window. The dialog box should look like as shown below. |
13. | For Table:, use the drop-down menu and select Stress. |
14. | Retain Table component: and Layer: as Select.... |
15. | Click in the Expression: window between the two round braces after Brittle_Calcs(). |
16. | Click Insert so that the Expression: window contains Brittle_Calcs(T2). |
The Expression: window should look as shown below.
17. | Click OK to close the Expression Builder. |
Step 4: Contour brittle results.
1. | From the Results menu, select Plot > Contour. |
2. | From the Result type: drop-down menu, select Brittle. |
3. | Click Apply to contour the results. |
4. | In the same dialog, under Legend threshold: click Edit Legend.... |
5. | From the Edit Legend dialog, change the Number of levels: to 3. |
6. | Under Values, click and change the second and third values to +1.0 and -1.0, respectively. Also, click the color and change the second color to green, so that all values greater than 1.0 are red and all values less than -1.0 are blue. |
7. | Click OK. The final contour is shown below: |
HyperMath API List
API |
Description |
Inputs |
Output Type |
---|---|---|---|
GetID |
Gets the record ID. |
No inputs needed. |
A number. |
GetPartID |
Gets the associated part ID. |
No inputs needed. |
A number. |
GetResultData() |
Gets the data of the current entity. This is a generic API applicable to any data type. |
No inputs needed. |
A vector of elements. The length depends on the data type and entity. |
GetTensorResult(formerly namedGetTensor) |
Gets tensor data type result. The input specifies the specified component. |
Name of the stress type as a string. The valid inputs are: "P1" - major "P2" - mid "P3" - minor "VON" - vonMises |
A vector of one element. |
GetVectorResult*† |
Gets vector data type result. The input specifies the desired component. |
"MAG" - magnitude 1 – 1st component 2 – 2nd component 3 – 3rd component |
A vector of one element. |
GetScalarResult**† |
Gets the scalar data type. |
No inputs needed. |
A vector of one element. |
GetRecordInfo |
This is the equivalent of the Tcl plug-in API, supported for legacy purposes. It provides the same Get functionalities as the above items in a single API. Please see the Tcl Plug-in section of HyperWorks Result Math help documentation for details. Note: The ‘config’ option not supported. |
Takes two strings, the first one specifies the entity type and the second one applies only for specific entities. The pair makes this API equivalent to one of the above Get APIs. |
The output will depend on the entity type queried. It matches the output of the equivalent Get API above. |
AddRecord |
Adds data to the current record. |
Record ID – A scalar. Data - A scalar or a vector. |
Boolean – true on success. |
*Available in release 11.0.120.
**Available in release 11.0.130.
† This function does not validate the data type and therefore care must be taken, since it can return values even when the data is of a different type.
HMath-1000: Editing, Executing, Saving, and Plotting in HyperMath
HMath-1010: Working with HyperMath Authoring Mode
HMath-1020: Working with HyperMath Debugging Mode
HMath-2000: Working with HyperMath – Arithmetic and Relational Expressions and Control Structures
HMath-2010: Working with HyperMath – Logical and Relational Expressions and Control Structures
HMath-2020: Working with HyperMath – Functions and Matrix Operators
HMath-2030: Working with HyperMath – Plot Commands
HMath-3000: Working with HyperMath – String Library
HMath-3010: Working with HyperMath – Input/Output Library
HMath-3020: Working with HyperMath – Input/Output Library Continued
HMath-3030: Working with HyperMath – Batch Mode
HMath-4000: Using HyperMath Functions for Curve Fitting
HMath-4001: Using HyperMath for Material Characterization
HMath-4010: Solving Ordinary Differential Equations
HMath-4020: Solving Differential Algebraic Equations
HMath-4030: Optimization Algorithms in HyperMath
HMath-5001: Post Processing Results from FEA
HMath-5002: Registering a Function in HyperGraph 2D
HMath-5003: HyperMesh-HyperMath Cross Execution of a Tcl Script
HMath-5004: HyperMesh-HyperMath Cross-debugging of a Tcl Script