Sensor

Model ElementSensor defines an event sensor in the model. Once an event of interest occurs, you can take action to respond to the event.

Class Name

Sensor

Description

For instance, the lateral acceleration of a car body may be monitored to determine whether the car is going out of control during a vehicle simulation. If this quantity becomes larger than a threshold value, you may like to stop the simulation.

Attribute Summary

Name Property Modifiable by command? Designable?
id Int ()   No
label Str () Yes
value Double ()  
error Double ()  
operator Enum ("LE EQ GE", default="EQ") Yes
dt Double ()  
hmax Double ()  
halt Bool ()  
print_ Bool ()  
restart Bool ()  
return_ Bool ()  
stepsize Double ()  
zero_crossing Double ()  
function Function ("SENSUB") Yes
routine Routine ()  
evaluate Function ("SEVSUB")  
evaluate_routine Routine ()  
active Bool () Yes

Usage

Three alternative implementations of Sensor_Event are available in MotionSolve.
#1: Sensor event is specified in a MotionSolve expression
Sensor (value=double, function=expressionString, optional_arguments)

#2: Sensor event is specified in a compiled user-subroutine
Sensor (value=double, function=userString, routine=string, optional_arguments)

#3: Sensor event is specified in a Python function
Sensor (value=double, function=userString, routine=functionPointer, optional_arguments)

Attributes

Sensor event is specified in a MotionSolve expression
value
Double
The sensor event threshold. An event is said to occur when the Sensor expression or user subroutine meets the comparison criterion with respect to value.
function
String defining a valid MotionSolve expression.
Specifies the MotionSolve expression that defines the Sensor value. Any valid run-time MotionSolve expression can be provided as input.
The function attribute is mandatory.
Sensor event is specified in a compiled user-subroutine
value
Double
The sensor event threshold. An event is said to occur when the Sensor expression or user subroutine meets the comparison criterion with respect to value.
function
String defining a valid user function MotionSolve expression.
The list of parameters that are passed from the data file to the user defined subroutine where the Sensor is defined.
The function attribute is mandatory.
routine
String
Specifies an alternative name for the user subroutine. The name consists of two pieces of information, separated by "::". The first is the pathname to the shared library containing the function that computes the response of the user-defined Variable. The second is the name of the function in the shared library that does the computation.

An example is: routine="/staff/Altair/engine.dll::mySensor"

  • "/staff/Altair/ engine.dll is the DLL
  • mySensor is the function within this DLL that performs the calculations
The attribute routine is optional.
When not specified, routine defaults to SENSUB.
Sensor event is specified in a Python function
value
Double
The sensor event threshold. An event is said to occur when the Sensor expression or user subroutine meets the comparison criterion with respect to value.
function
String defining a valid user function MotionSolve expression.
The list of parameters that are passed from the data file to the user defined subroutine where the Sensor is defined.
The function attribute is mandatory.
routine
Pointer to a callable function in Python.
An example is: routine=mySensub
  • mySensub is a Python function or method that can be called from wherever the model resides.
The attribute routine is optional.
When not specified, routine defaults to SENSUB.
Optional attributes - Available to all variants
id
Integer
Specifies the element identification number. This number must be unique among all the Sensor objects in the model.
This attribute is optional. MotionSolve will automatically create an ID when one is not specified.
Range of values: id > 0
label
String
Specifies the name of the Sensor object.
This attribute is optional. When not specified, MotionSolve will create a label for you.
operator
String
Defines the comparison operator.
Select from "GE", "EQ", or "LE". The comparison operator is used to detect when an event has occurred. It is implemented as follows:
  • GE: SensorValue ≥ value - error
  • EQ: SensorValue ≥ value - error && SensorValue ≤ value + error
  • LE: SensorValue < value + error
This attribute is optional. When not specified, it defaults to "EQ".
error
Double
Defines the error tolerance for detecting an event. When the sensed value is within this tolerance of the threshold value, the solver generates an event.
This attribute is optional. When not specified, it defaults to 0.001.
zero_crossing
Double
Specifies the tolerance for the zero crossing search. The tolerance is defined as the value of zero_crossing multiplied by the current hmax. The search stops when the time reaches the exact time the event happens within this tolerance. See 3 in Sensor: Event for more details.
dt
Double
Specifies the new print interval to be applied when the event occurs.
This attribute is optional. When not specified, the print interval is NOT changed.
hmax
Double
Specifies the value of the maximum step size the solver is allowed to take as soon as the sensor is triggered. This value persists until the end of the simulation unless changed by another sensor.
This attribute is optional. When not specified, the maximum step-size is NOT changed.
halt
Boolean
Set to either True or False.
Stops the simulation when the event occurs and halt=True.
This attribute is optional. When not specified, halt=False.
print
Boolean
Set to either True or False.
Prints an output when the event occurs and print=True.
This attribute is optional. When not specified, print=False.
restart
Boolean
Set to either True or False.
When restart=True and an event is sensed, MotionSolve will restart the integrator. All integrator history of the system is deleted and the integrator starts over.
This attribute is optional. When not specified, restart=False.
return
Boolean
Set to either True or False.
When return=True and an event is sensed, the action is to return control of the program to the command processor so the next command can be processed. If there are no more commands, simulation is halted.
This attribute is optional. When not specified, restart=True.
stepsize
Double
Specifies the maximum step size for the next trial step. This expires after one step.
This attribute is optional. When not specified, the integrator step-size remains unaffected.
evaluate
When specifying a function expression
  • String defining a valid MotionSolve function expression
  • Specifies a regular MotionSolve expression that evaluates to a value
When specifying a user subroutine
  • String defining a valid user function MotionSolve expression
  • Contains the list of parameters that are passed from the data file to the user- defined subroutine where the evaluation is performed.
evaluate_routine
When specifying a compiled user subroutine
  • String

    Specifies an alternative name for the user subroutine. The name consists of two pieces of information, separated by "::". The first is the pathname to the shared library containing the function that computes the response of the user-defined Variable. The second is the name of the function in the shared library that does the computation.

    An example is: routine="/staff/Altair/engine.dll::mySevsub"

    • "/staff/Altair/ engine.dll is the DLL
    • mySevsub is the function within this DLL that performs the calculations
The attribute routine is optional.
When not specified, routine defaults to SEVSUB.
When specifying a Python function
  • Pointer to a callable function in Python.
  • An example is: routine= mySevsub
  • mySevsub is a Python function or method that can be called from wherever the model resides.
The attribute evaluate_routine is optional.
When not specified, routine defaults to SEVSUB.
active
Bool
Select one from True or False.
  • True indicates that the element is active in the model and it affects the behavior of the system
  • False indicates that the element is inactive in the model and it does not affect the behavior of the system. It is almost as if the entity was removed from the model, of course with the exception that can be turned "ON" when desirable.

The attribute active is optional. When not specified, active defaults to True.

Example

XML syntax vs. Python for the same example.
<Sensor_Event
 id        = "100"
 type      = "EXPRESSION"
 expr      = "ABS(ACCX(21,11,21,11))"
 compare   = "GE"
 value     = "5"
 error_tol = "0.0001"
 halt      = "TRUE"
/>
expr = "ABS (ACCX (21,11,21,11))" 
sen1 = Sensor (function=expr, operator="GE", value=5, error=0.001, halt=True)
<Sensor_Event
 id                       = "200"
 type                     = "USERSUB"
 usrsub_param_string      = "USER(22,11)"
 usrsub_dll_name          = "NULL"
 compare                  = "GE"
 value                    = "0"
 evaluate_id              = "200" 
 error_tol                = "0.0001"
 dt                       = "le-2"
/>
expr1 = "USER (22,11)" 
expr2 = "FM (44,33,33)" 
sen2 = Sensor (function=expr1, operator="GE", value=0, error=0.001, dt=1e-2, evaluate=expr2)

Comments

  1. See Properties for an explanation about what properties are, why they are used, and how you can extend these.
  2. For a more detailed explanation about Sensor, see Sensor: Event.