Sensor: Evaluate

Model ElementA Sensor_Evaluate element is always associated with one or more Sensor_Event modeling elements. When a Sensor_Event becomes "active", a Sensor_Evaluate may be optionally called to define a scalar value based on the current value of the system states. This value is not re-evaluated until one of the parent Sensor_Event's becomes active again.


Thus, Sensor_Evaluate may be used to store information to the system states when the Sensor_Event is active.

Two types of Sensor_Evaluate elements are supported:
  • MotionSolve expression-based.
  • MotionSolve user-subroutine based.

An expression-based Sensor_Evaluate evaluates the expression it contains and stores its value. A user subroutine based Sensor_Evaluate invokes the user subroutine, SEVSUB, when the sensor is active. SEVSUB calculates and stores its value. In both cases, the MotionSolve function SENVAL(ID) can be used to retrieve this value.

An expression based measure is used when the quantity being calculated is relatively simple. A user subroutine based measure is used when the quantity being calculated is complex and involves many logical decisions. In this case, the full power of a programming language can be used to efficiently calculate the quantity of interest.


    id                   = "integer"    
  [ label                = "string" ]
{   type                 = "EXPRESSION"
    expr                 = "motionsolve_expression"    
  | type                 = "USERSUB"
    usrsub_dll_name      = "valid_path_name"
    usrsub_param_string  = "USER([[par_1[,...][,par_n]])" } >
    usrsub_fnc_name      = "custom_fnc_name"  >    
  | type                 = "USERSUB"
    script_name          = valid_path_name
    interpreter          = "PYTHON" | "MATLAB"
    usrsub_param_string  = "USER([[par_1[,...][,par_n]])"
    usrsub_fnc_name      = "custom_fnc_name" >
</ Sensor_Evaluate>


Element identification number (integer>0). This number is unique among all Sensor_Evaluate elements.
The name of the Sensor_Evaluate element.

Select from EXPRESSION and USERSUB. Specifies the expression to be evaluated when the Sensor_Event is activated.

The EXPRESSION option specifies that the event value is a MotionSolve expression that can be evaluated at run-time. The USERSUB option indicates that the value of the event is specified in a user defined subroutine. The parameters usrsub_param_string and usrsub_dll_name/script_name are used to provide more information about the user defined subroutine.

Defines an expression that defines the sensor event. Use this parameter only when type = EXPRESSION. Any valid run-time MotionSolve expression can be provided as input.
The list of parameters that are passed from the data file to the user defined SEVSUB. Use this keyword only when type = USERSUB is selected.
Specifies the path and name of the DLL or shared library containing the user subroutine. MotionSolve uses this information to load the user subroutine SEVSUB in the DLL at run time.
Specifies an alternative name for the user-written subroutine SEVSUB.
Specifies the path and name of the user written script that contains the routine specified by usrsub_fnc_name.
Specifies the interpreted language that the user script is written in. Valid choices are MATLAB or PYTHON.


The example below demonstrates how Sensor_Evaluate can be used to store the state of a hydraulic system.

The system can operate in two different configurations: check valve open and check valve closed. The user is interested in printing out how often this occurs in a simulation. A differential equation Diff/1021 is used to model the pressure in the circuit. When the pressure goes below a threshold value, the check valve closes. When the pressure goes above the threshold value, the check valve opens. A Sensor_Evaluate monitoring the pressure detects these occurrences and instructs MotionSolve to call Sensor_Evaluate/100.

Sensor_Evaluate/100 measures the pressure in the system. If it is above the threshold value of 7.7, it stores 0 (valve is open), otherwise it stores 1 (valve is closed).

SENVAL(100) can be used in a Request measure statement. Then, the valve opening and closing can be plotted as a function of time.

  id                  = "100"
  type                = "EXPRESSION"
  expr                = "IF (DIF(1021)-7.7) 1, 1, 0">

The second example shown below is exactly the same as the first, except the Sensor_Evaluate calculation is done in a user subroutine.

Notice that the ID of the Diff, 1021, and the threshold value, 7.7, are passed as a parameter so the user defined subroutine can work for many Sensor_Evaluate modeling elements.

  id                  = "100"
  type                = "USERSUB"
  usrsub_param_string = "USER(1021, 7.7)"
  usrsub_dll_name     = " C:\jsnow\Desktop\test\sensor\sensor.dll">


Sensor_Evaluate may be used to define the value of a discrete variable. The associated Sensor_Event determines the sampling interval for the discrete state and Sensor_Evaluate defines the discrete value of the variable.