A calculation specifies a reusable computation that returns a result in the result parameter. In addition to its parameters, a calculation may have features that are calculation or action usages, which carry out steps in the computation of the calculation result. A calculation always has a result parameter, which can be declared as an out parameter using the keyword return instead of out.

You can invoke calculation definitions and calculation usages as described below.

To invoke a calculation definition or calculation usage


  1. Create and define a calculation definition or calculation usage. For instructions, refer to the SysML v2 Plugin documentation.
  2. Create an invocation expression, e.g., an attribute, whose value is the result of the calculation.
  3. Assign the created calculation to the invocation expression and define the calculation inputs.

    When defining the calculation inputs, keep in mind that they will be taken in the same order as defined in the calculation.

    Example

    calc def Area {
                in length : Real;
                in width : Real;
                return result : Real;
                result = length * width;
     }      
     part pad {
                attribute surfaceArea : Real = Area(centerLength, width);
     }

  4. Evaluate the invocation expression (e.g., the surfaceArea attribute in the above example). 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 specifying the return of a calculation, you can use a textual representation element to evaluate scripts defined in other script languages. Supported languages include Javascript, Groovy, Beanshell, Python (Python support is based on Jython), and MATLAB. Only primitive input and output types, e.g., String, Real, Boolean, etc., are supported.

Example

calc def Area15 {
        in length : Real;
        in width : Real;
        return result : Real;
        language "beanshell" /* result=length * width */

}

Using MATLAB

To evaluate scripts defined in the MATLAB syntax: