12.3 Compiling ExpressionsMost MechanicalSystems functions that use an iterative Newton-Rhapson solver or numerical integration accept the Compiled option. Setting Compiled -> True can result in a substantial reduction in run time, at the expense of some increase in the time required to build the model. However, Mathematica's ability to compile expressions is not universal. There are some types of algebraic expressions that cannot be compiled. If an algebraic expression within a Mech model contains such a form, it cannot be compiled. The spatial slider-crank model is rebuilt with the Compiled option to demonstrate the speed increase that is realized by compiling the model. This rebuilds the constraints in compiled form. The BuildMech option forces an immediate build of the velocity equations, which prevents the time required to build them from being included in the timing. This generates the complete location and velocity solution at 21 points in about half the time that was required without the Compiled option.
Out[18]= | |
|