Spool with a Preload

Introduction

This notebook shows how the Wolfram Language can be used to create a custom animation of a model.

Explore the available scenarios by evaluating each cell in order. Evaluation is done by selecting a cell and pressing Shift+Enter.

In order to get the full experience of this example, you need the following:

Wolfram SystemModeler; a free trial download is available at www.wolfram.com/system-modeler

The model that came in the same bundle as this notebook

For more information about Wolfram SystemModeler, visit www.wolfram.com/system-modeler.

Initialize

Define the model name:

mmodel="EducationExamples.MechanicalEngineering.SpoolWithAPreLoad";

Simulation

Simulate the model for 200 s and save it as an object:

simdata=SystemModelSimulate[mmodel, {0, 200}];

Extract the System Equations That Give the Positions Necessary for Animation

Each variable trajectory needed for animation is stored in simdata. To use the variables for animation, they are saved as objects to be manipulated and used:

OCAa=simdata["outerContactA.flange_a.s"];
OCAb=simdata["outerContactA.flange_b.s"];
OCBa=simdata["outerContactB.flange_a.s"];
OCBb=simdata["outerContactB.flange_b.s"];
OCBs=simdata["outerContactB.s_rel0"];
OCAs=simdata["outerContactA.s_rel0"];
ICAa=simdata["innerContactA.flange_a.s"];
ICAb=simdata["innerContactA.flange_b.s"];
ICBa=simdata["innerContactB.flange_a.s"];
ICBb=simdata["innerContactB.flange_b.s"];
ICBs=simdata["innerContactB.s_rel0"];
ICAs=simdata["innerContactA.s_rel0"];
Ha=simdata["housing.flange_a.s"];
Hb=simdata["housing.flange_b.s"];
force=simdata["force.f"];
pos=simdata["spool.s"];

Analysis and Animation

It is now possible to see a custom-made animation that is manipulable, as well as plots to analyze the result. Below is a force-to-position plot and animation.

Enable User-Controlled Animation Using the Manipulate Function

(*Allow the user to manipulate time and opacity*)
DynamicModule[{(*OCAa,OCAb,OCBa,OCBb,OCBs,OCAs,ICAa,ICAb,ICBa,ICBb,ICBs,ICAs,Ha,Hb,force,pos*)},
valve[t_, op_]:=Graphics3D[{
(* left contact *)
Opacity[op],
Red,
Cylinder[{{Dynamic[OCAb[t]]-Dynamic[OCAs[t][[0]]],0,0},{Dynamic[OCAb[t]],0,0}},0.01],
Cylinder[{{Dynamic[OCAb[t]],0,0},{Dynamic[ICAb[t]]-Dynamic[ICAs[t][[0]]],0,0}},0.0085],
(* right contact *)
Cylinder[{{Dynamic[OCBa[t]],0,0},{Dynamic[OCBa[t]]+Dynamic[OCBs],0,0}},0.01],
Cylinder[{{Dynamic[OCBa[t]],0,0},{Dynamic[ICBa[t]]+Dynamic[ICBs[t][[0]]],0,0}},0.0085],
(* spool *)
Opacity[1],
Yellow,
Cylinder[{{Dynamic[ICAa[t]]-0.001,0,0},{Dynamic[ICAa[t]],0,0}},0.0065],
Cylinder[{{Dynamic[ICAa[t]],0,0},{Dynamic[ICBb[t]],0,0}},0.0045],
Cylinder[{{Dynamic[ICBb[t]],0,0},{Dynamic[ICBa[t]]+0.02,0,0}},0.0065],
(* Left wall *)
 Black,
Cylinder[{{Dynamic[Ha[t]]-0.001,0,0},{Dynamic[OCAa[t]],0,0}},0.01],
(* Right wall *)
 Black,
Cylinder[{{Dynamic[Hb[t]]+0.001,0,0},{Dynamic[OCBb[t]],0,0}},0.01],
(* Housing *)
Opacity[.1],
Cylinder[{{Dynamic[Ha[t]],0,0},{Dynamic[Hb[t]],0,0}},0.01]
},
Boxed->False,
PlotRange->{{Ha[0]-0.001,Hb[0]+0.02},{-0.01,0.01},{-0.011,0.01}}
];

(*A function that will create a parametric 3D plot of a spring*)
makeSpring[{length_,diameter_,thickness_},windings_,color_:Green,specularity_:Specularity[Automatic]]:=Block[{res,windingsConstant=windings},res=GeometricTransformation[Scale[Tube[BSplineCurve[Table[{Sin[u],Cos[u],u/(windingsConstant*2 Pi)},{u,0,windingsConstant*2 Pi}],SplineDegree->3],thickness/2],{diameter/(2),diameter/(2),length},{0, 0,0}],{{0,0,1},{-1,0,0},{0,1,0}}];
{color,specularity,res}];

spring=Graphics3D[Translate[Dynamic[makeSpring[{OCBa[t]-OCAb[t], 0.0085*2+0.004, 0.03}, 8]], {Dynamic[OCAb[t]], 0, 0}], ImageSize->350];

pplot=Dynamic[Graphics[ParametricPlot[{pos[u],force[u]},{u,0,100},
AspectRatio->1,
AxesLabel->{"Position [m]","Force [N]"},
Epilog->{PointSize[Large],Red,Point[{Dynamic[pos[t]],Dynamic[force[t]]}]}, ImageSize->290]]];

(*Create interface *)
Manipulate[

Grid[{{pplot,Show[spring,valve[t, op], ViewPoint->{4,-10,10},ViewAngle->Pi/30,Axes->False,Boxed->False, PlotRange->{{Ha[0]-0.001,Hb[0]+0.02},{-0.01,0.01},{-0.011,0.01}}]}}, ItemSize->{20, 15}, Alignment->{Center, Center}, Spacings->{8}],
{{t,0.01, "Time"},0.01,200,0.1},
{{op,0.5, "Opacity"},0,1,0.01},
TrackedSymbols->{t, op},SaveDefinitions->True]
]

Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

License

All content in this bundle is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. By accessing the content or using it in any way, you accept and agree to be bound by the terms of this license. If you do not agree to these Terms of Use, you may not use this content. Wolfram Research reserves the right to change, modify, add to, or remove portions of these Terms of Use at any time without notice. Please refer back to www.wolfram.com for the latest Terms of Use.

A summary of the licensing terms can be found at:
http://creativecommons.org/licenses/by-nc-sa/3.0

The full legal code can be found at: 
http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode