Previous section-----Next section

2.4 Building the Model

Constraint objects are processed into a kinematic model with the SetConstraints function. The system of equations generated by SetConstraints is not returned to the user; it is stored in several variables in Mech's private context. Thus only one mechanism model can be current in Mech at any given time. Several means of accessing and modifying the model are provided by Mech; these are discussed in the following section.

2.4.1 SetConstraints

SetConstraints is Mech's core model building function. SetConstraints takes constraint objects that represent the physical interactions in the mechanism model and processes them into a system of kinematic equations.

The core model-building function.

SetConstraints accepts options that determine how certain parts of the mathematical model are built.

An option for SetConstraints.

2.4.2 Constraints

The actual constraint expressions that are generated by SetConstraints can be extracted with Constraints. Constraints can be very useful for debugging a model because it is often possible to read the constraint expressions directly and relate them to the function of the model.

Constraints function.

This loads the Modeler2D package.

Consider the 2D crankshaft-piston model of Section 1.2. This model is built with various settings for the options for SetConstraints to show their affect on the resulting equations.

Here is the crankshaft-piston model rebuilt.

The first constraint cs[1] is a two degree of freedom constraint that constrains the origin of the crankshaft to lie at the global origin.

Here is the expression generated by the Revolute2 constraint.

Obviously, when these two expressions are driven to zero, the desired result is achieved, the coordinates of the local origin of the crankshaft {X2, Y2} are zero.
The third constraint cs[3] is a two degree of freedom constraint that allows the piston to translate along a vertical axis, but constrains its rotation and its translation in the X direction.

Here is the expression generated by the Translate2 constraint.

The first expression, 10 Sin[CapitalTheta3], constrains the rotation of the piston; this expression can be equal to zero if CapitalTheta3 is any integer multiple of Pi. The reason that the solution CapitalTheta3 -> 0 is found is because the default initial guess is CapitalTheta3 -> 0. If a different initial guess were used, such as CapitalTheta3 -> 3, the model would converge to CapitalTheta3 -> N[Pi] instead.
The second expression in the list constrains the X coordinate of the piston to be zero. Notice that at any value of CapitalTheta3 that satisfies the first expression, the second expression reduces to  or  , either of which will drive X3 to zero.

2.4.3 Initial Guesses

SetGuess serves both as an option for several Mech functions, and as a function for temporarily setting a model's initial guesses.

Various methods of setting initial guesses.

A SolveMech utility.

To advance the position for the model in large steps, it is sometimes necessary to specify a better initial guess than the current one. For example, to turn the crankshaft 3/4 of a turn at once, it might be necessary to set a new initial guess for CapitalTheta2 and Y3, the angular coordinate of the crankshaft and the height of the piston, respectively.

This runs the model at its initial position.

This sets new guesses for CapitalTheta2 and Y3.

This runs the model at 3/4 turn of the crank.

If SetConstraints were to be run at this time with the default options, the initial guesses would remain at their current values,  and  . The SetGuess option resets the guesses to their defaults.

The SetGuess option resets the initial guesses.

This shows the current guesses.

2.4.4 $MechProcessFunction

$MechProcessFunction is a function that is applied to all of the mechanism equations that are generated by SetConstraints as they are created. The default setting, $MechProcessFunction = Chop, can reduce the size of the constraint expressions substantially if any of the constraints involve the local origins of bodies in the model which have local coordinates of  or  . Setting $MechProcessFunction = Identity disables this action.

Set $MechProcessFunction equal to Identity to disable chopping.

In[21]:=

Here the model is built without chopping the constraints.

Here is the Revolute2 constraint.

Obviously, the run time of the model is increased by increasing the size of the constraint expressions. However, if the model contains very small physical dimensions, it may not be acceptable to apply Chop to the constraints.

2.4.5 SetSymbols

The default symbols that appear in the solution rules returned by SolveMech can be changed with the SetSymbols function.

A model set-up function.

Default settings.

Because SetSymbols changes the behavior of all Mech functions that return symbolic expressions, SetSymbols must be run before building any other part of the mechanism model with SetBodies or SetConstraints. SetSymbols has the effect of executing ClearMech[].
The CapitalOmegax, CapitalOmegay, and CapitalOmegaz symbols are used by Modeler3D to represent angular velocities used in 3D velocity analysis, which is discussed in Chapter 4. The CapitalLambda symbol is a Lagrange multiplier used in static and dynamic analysis, which is discussed in Chapter 7. The d symbol is used in 2D and 3D velocity analysis to symbolically represent differentiation.
If the current model is rebuilt with a new setting for SymbolBasis, the solution rules returned by SolveMech are changed accordingly.

This causes new symbols to be used in all subsequent models.

The model is rebuilt with SetConstraints.

This runs the model at crankangle = 0.5.

This returns MechanicalSystems to its initial state.