Invoking actions
An action definition is a type of occurrence definition that specifies what an action is and how it can be performed. An action usage is a type of occurrence usage that represents the actual use of one or more action definitions within a particular situation or context.
You can invoke action definitions and action usages as described below.
To invoke an action definition or action usage
- Create and define an action definition or action usage. For instructions, refer to the SysML v2 Plugin documentation.
- Create an expression that invokes the action, for example, by defining an attribute whose value is computed through the action invocation.
- Access a specific output of the action invocation in one of the following ways:
- Use the dot notation in the invocation expression.Example
action def calculateCircleParameters {
in radius : Real;
out diameter : Real = radius * 2;
out circumference : Real = diameter * 3.14;
out area : Real = radius * radius * 3.14;
}
part wheel {
attribute radius : Real = 12;
attribute area : Real = calculateCircleParameters(radius).area;
} - Create a feature that stores the invocation result, e.g., actionInvoke, and then select specific outputs using dot notation.Example
action def calculateCircleParameters {
in radius : Real;
out diameter : Real = radius * 2;
out circumference : Real = diameter * 3.14;
out area : Real = radius * radius * 3.14;
}
part wheel {
attribute radius : Real = 12;
actionInvoke = calculateCircleParameters(radius);
attribute area : Real = actionInvoke.area;
attribute perimeter : Real = actionInvoke.circumference;
}
- Use the dot notation in the invocation expression.
- Evaluate an element whose value depends on the action invocation (e.g., the area or perimeter attribute in the above examples). For more information, see Evaluating model elements.
The evaluation results are displayed in the SysML v2 Model Evaluation console.
Defining calculation return in other script languages
When defining an action using a textual representation element, you can implement its behavior using an external scripting language. Supported languages include JavaScript, Groovy, Beanshell, Python (via Jython), and MATLAB. Only primitive types such as Integer, Real, Boolean, and String are supported as input and output parameters.
Using MATLAB
To evaluate scripts defined in the MATLAB syntax:
- MATLAB must be integrated with your modeling tool.
- The language must be specified as "MATLAB" (case sensitive).
action def counter {
inout count : Real := 0;
language "groovy" /* count=count+1 */ }
}
attribute startCount : Integer = counter().count //The result will be 1 because there is no input
attribute continueCount : Integer = counter(startCount).count //The result will be 2. Input overrides the initial value set in the parameter.
Actions also support "ToolExecution", which allows mapping features with different names between the SysML v2 model and MATLAB scripts.
action computeStoppingDistance {
private import AnalysisTooling::*;
@ToolExecution {
:>> toolName = "MATLAB";
:>> uri = "run('C:/custom/path/to/StoppingAnalysisExec.m')";
}
in mass : Real = vehicle.grossMass / 4 {@ToolVariable { name = "m"; }};
in speed : Real = vehicle.speed / 3.6 {@ToolVariable { name = "v0"; }};
out Distance : Real = vehicle.stoppingDistance {@ToolVariable { name = "stoppingDistance"; }};
out kineticEnergy : Real = vehicle.kineticEnergy {@ToolVariable { name = "e"; }};