2.6 Variable ManagementMechanism models often need to have many adjustable parameters that can be tweaked between runs of the model. A Mech model may have any number of user-defined variables, provided that all such variables in a model have numerical values before SolveMech is called. 2.6.1 User-Defined VariablesThis loads the Modeler2D package. Symbolic parameters can enter a kinematic model in two ways. The coordinates of a local point can be given in symbolic form or the arguments of a constraint function that specify a distance or angle can be given as a symbolic expression. The following example shows how local point specifications can be symbolic. This prevents impending spell check warnings. All local coordinates can be specified symbolically. The crankshaft-piston model can be built with several variables in the arguments to its constraint functions. The following example introduces symbols into the model to represent the frequency of the crankshaft rotation, the length of the connecting rod, and the stroke of the crankshaft. Here are the crankshaft-piston body objects, with a symbol included in the points list. This builds the constraint equations with two symbols embedded. If SolveMech is called now to seek a solution, an error message is generated because some of the symbols in the model have not yet been defined. This attempts to find a solution.
Out[19]= | |
A debugging aid. CheckSystem reports the names of any undefined symbols, as well as several other possible errors in the model. This checks the integrity of the model.
Out[20]= | |
This defines the undefined symbols, checks the model, and runs it.
Out[24]= | |
Out[25]= | |
Dependent Variables It is acceptable to use Mech dependent variables explicitly when defining local points or constraints. Highly abstract compound constraints can be specified in this manner. This is an extremely obtuse constraint. This constraint would cause the Y coordinate of a point on body 2 to be equal to the X coordinate of the origin of body 3, squared. When using dependent variables in constraints, care must be taken to ensure that the dependence of the constraint on the variables is explicit at the time that SetConstraints is run. If not, differentiation with respect to those variables cannot occur, and the constraints will not be processed correctly. Note that the names of the dependent variables used by Mech are cleared and protected when SetConstraints is run. Thus, if there happens to be a definition in place such as Y2 = 3, it is removed by SetConstraints. 2.6.2 ParametersAnother method of managing variables in a Mech model is to use the parameters functions. The parameters list is basically a list of rules stored in Mech's internal database that is applied to the mechanism model immediately before the solution phase. By using parameters, problems can be avoided such as failing to define all of the symbols in a model or accidentally defining them before SetConstraints is run and hard coding them into the model. Parameter management functions. Note that when a parameter is set with SetParameters or Parameterize, it is protected until it is unset with ClearParameters. This is to ensure that the parameter cannot be accidentally given a definition in the course of running the model. The crankshaft-piston model, which was built in Section 2.6.1, is used to demonstrate the use of parameters. The definitions of the three symbols in the model are cleared and then added to the parameters list. This adds three symbols to the parameters list.
Out[28]= | |
The crankshaft-piston model can now be built without worrying about the definitions of the parameters. SetParameters can be used at any time in the model-building process. Here the crankshaft-piston model is rebuilt with reference to the body objects previously defined. The parameters are included in the solution rules returned by SolveMech.
Out[30]= | |
Set a new value for crankfreq. Only the specified value is updated, the others are left unchanged.
Out[31]= | |
The parameters are protected.
This removes all of the parameters from the parameters list.
Out[33]= | |
|