HyperWorks Solvers

Custom Statements

Custom Statements

Previous topic Next topic No expanding text in this topic  

Custom Statements

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

Custom statements allow advanced users to expand the set of MotionSolve model elements by adding new standard model element vocabulary. Custom statements can be mapped to one or more model elements.

Custom statements can be mapped to elements of the same type or of different types.  You can choose the element name as well as the attribute names.

When a custom element has the same name as a pre-defined MotionSolve model element, the custom model element takes precedence.  In other words, custom model elements override pre-defined model elements.

For instance, consider a PID controller:

PIDController

A block diagram of a PID controller

The PID controller calculation involves three separate parameters: proportional, integral, and derivative values:

1.Proportional value determines the reaction to the current error and is represented by:

custstateeq1

2.Integral value determines the reaction based on the sum of recent errors:

custstateeq2

3.Write this equation in another form:
custstateeq3
4.Derivative value determines the reaction based on the rate at which the error has been changing, having two parts:

custstateeq4

5.Alternatively:

custstateeq5

6.And:

custstateeq6

7.Alternatively:

custstateeq7

8.The weighted sum of these three actions is used to adjust the process via a control element, such as the position of a control valve:

custstateeq8

The proportional, integral, and derivative terms are summed to calculate the output of the PID controller.

Thus, you get the custom element (8) with three Control_Diffs (one explicit and two implicit) and one Reference_Variable.

To create a custom function:

1.Edit the mapping file.

An entry is made to the mapping file declaring the custom function as shown in the image below:

custom_func_mapping

custom_func_mapping2

Editing the mapping file to declare a custom function

The general syntax for the CustomElement element is as follows:

<CustomFunction

  SYMBOL              = "string"

 <Attribute

   ID                 = "integer"

   NAME               = "string"

   TYPE               = "string"

   DEFAULT            = "real"

 />

… (to be repeated for each attribute)

 <Component

   ID                 = "integer"

   CTYPE              = "string"

[In addition, all attributes needed to define the Component completely based on its type]

/>

… (to be repeated for each component)

/>

Children

ATTRIBUTE - Specifies the definition of a particular attribute of the custom element.


Attributes


ID

Attribute identification number, (integer>0).  This is a number that is unique among all attributes of the custom element.


NAME

Name of the attribute that needs to be used in the MotionSolve XML.


TYPE

Specifies the data type for the value of the attribute.


DEFAULT

Specifies the default value to be used for the attribute.

COMPONENT - Specifies the definition of a particular component of the custom element.

 

Attributes

 

ID

Component identification number, (integer>0).  This is a number that is unique among all components of the custom element.

 

CTYPE

Specifies the type of the component.

Supported Component Types:

Non-Usersub Cases

GRAPHICS
MARKER      
PART
POINT_MASS
STRING      

Single Usersub Cases            

GFOSUB
VFOSUB
VTOSUB
SFOSUB
FIESUB
CURSUB
SURSUB
UCOSUB
GCOSUB
MOTSUB
REQSUB
VARSUB
DIFSUB
SENSUB
SEVSUB
SPLINE_READ
GRASUB

Multiple Usersub Cases

CNFSUB, CFFSUB [either one is good (and equivalent)]
COUSUB [maps to COUSUB/COUXX/COUXX2]
GSESUB
2.Define the path to the mapping file.

Modify the environment variable Variable name: as MS_CUSTOM_MAPPING_FILE to point to the mapping file, as shown in the image below:

edit_user_variable2

Set the environment variable

3.Create VARSUB and DIFSUB-like user-written subroutines and build a DLL as shown in the image below:

sub_dll_xml

sub_dll_xml2

User defined subroutine, DLL, and corresponding XML files

From this point forward, the VARSUB function name for the PID controller is VAR_PID and the DIFSUB function names are DIF_PID1, DIF_PID2, and DIF_PID3.  These are the custom functions that can be used in models just like pre-defined MotionSolve functions.  You can use them anywhere in a model as you would a standard, MotionSolve model element.

For instance, the element on the left in the image below is internally interpreted by MotionSolve into the set of elements shown on the right.

inter_cust_rep

Internal and custom representations

MotionSolve internally interprets custom elements using a combination of standard elements, according to the instructions in the mapping file.  You can use <Save/> to check the resultant mapping.

See Also:

Custom Functions

Custom Messaging

Custom Results Output

Custom Translation Rules from ADAMS to XML Translation