About Custom Load Functions
When a custom load application is started, exchanges between the application and Mechanism Dynamics are made through direct function calls. Some functions are called from the custom load application by Mechanism Dynamics. Others are provided by Mechanism Dynamics and can be called in by the custom load application. Each function may have a number of optional arguments that you can add to your function definition when needed.
The following information briefly describes the functions specific to the custom load application.
Functions provided by the custom load application and written by the custom load developer:
CLUSEREvalCustomLoad()
CLUSERDefineInit()
CLUSERRunInit()
CLUSERGetStateVariablesSize()
CLUSERInitStateVariables()
CLUSERGetStateVariableDerivatives()
Functions provided by Mechanism Dynamics and callable by the custom load developer:
CLEvalMeasure()
CLEvalStateVariables()
CLUSEREvalCustomLoad() is the only function that must always be present in the custom load application. When a user runs an analysis that references the custom load, this function is called at each time step of the analysis. It returns the value for the custom load at that time. This value is used to calculate forces and accelerations for this time step.
Since CLUSEREvalCustomLoad() passes the custom load name as an argument, many different custom loads may be supported by the same custom load executable.
Within CLUSEREvalCustomLoad(), the user may call CLEvalMeasure(). CLEvalMeasure() takes the name of a measure, that exists in the model, as an input argument. When developing the custom load application, make sure to indicate in your custom load documentation the type of measure you want the user to create in the model.
Since CLUSEREvalCustomLoad() will be called many times during the analysis run, it is important that this function complete as fast as possible or your analysis runs will slow down dramatically. There especially should be no UI operations or model changes made during this call.
Another important function is CLUSERDefineInit(). It is called when a user creates a new force motor or external force or torque. The function allows the custom load application to query the user for data specific to that custom load. The data can be stored and later used in the CLUSEREvalCustomLoad() function. For example, if the custom load is for a spring, the CLUSERDefineInit() function can ask the user to provide the spring constant for this load.
CLUSERRunInit() is called before a user runs any analysis that references the custom load.
The remaining functions can help to implement control systems using the custom load. The custom load application can provide a set of derivative values is integrated at each time step.
* 
These initialization routines are called before an analysis is run, so it is not appropriate to call CLEValMeasure() or CLEvalStateVariables() from them.
CLUSERGetStateVariablesSize() is called before an analysis is run. If the custom load application provides a nonzero state variable size, Mechanism Dynamics calls CLUSERGetStateVariables() before running the analysis. Then, at each time step, CLUSERGetStateVariableDerivatives() is called to get the current derivative values.
Was this helpful?