Mechanics Oop

download Mechanics Oop

of 20

Transcript of Mechanics Oop

  • 7/29/2019 Mechanics Oop

    1/20

    DRAFT: J anuary 31, 2000

    An Object-Oriented Approach to Basic Mechanics

    David M. AuslanderMechanical Engineering

    University of California at [email protected]

    AbstractAn approach is suggested for a methodology associated with basic mechanics that greatlyenlarges the scope of problems accessible to students and professionals. A numerical approachbased on Newtonian point-mass mechanics and pseudo-rigid bodies brings problems such asthree-dimensional dynamics and constrained motions into the arena of basic mechanics. Becausesolutions of almost any problems of interest require computation, integrated study of physics,math, and computation is essential. An object-oriented computational approach is extremelyuseful since all models can be expressed with the same set of basic elements.

    IntroductionBasic mechanics is defined as the material associated with the mechanics of rigid bodies that ispresented to students in the last two years of high school through the first three years of college.Some of the material is presented in physics courses and some of it in engineering courses. Basicmechanics is important for engineers because it:

    Forms the basis for the study of advanced mechanics, Forms the basis for a number of engineering application areas, Establishes the pattern by which engineers approach problems involving

    mechanics.

    The last of these points is important in engineering practice because easy problems aregenerally defined as those that can be solved using material generally classified as basicmechanics. The purpose of this paper is to reexamine basic so as to increase the scope of problems considered easy.

    The starting point for this reexamination is the following two questions:1. What is the purpose of the basic mechanics curriculum?2. What is the appropriate role of computation in formulation of the curriculum?

    While these questions themselves are subjects for considerable debate, answers to them are

    proposed as a means of guiding this study. Different answers would, of course, lead to differentapproaches to basic mechanics -- indeed, even the same answers could lead to differentapproaches.

    The proposed responses are:1. The purpose of the basic mechanics curriculum is to equip engineers with tools

    enabling them to solve the broadest possible class of problems.

  • 7/29/2019 Mechanics Oop

    2/20

    DRAFT: J anuary 31, 2000

    2

    2. Computation is central to the professional activities of engineers. Integration of computing methodology with the engineering science curriculum is highlydesirable.

    The first answer, the purpose of the basic mechanics curriculum, is very pragmatic. The reasons

    behind the choice are both professional and historical. Professionally, engineers use physics andrelated engineering science subject areas to allow them to predict the behavior of actual orpotential products for the purpose of improving the performance of those products. Thus, thebroader the range of problems they can solve, the more effective they will be at that aspect of their engineering work.

    The present mechanics curriculum shows signs of the same pragmatic approach. Its antecedentsgo so far back that, at this point, it is hard to separate pragmatism from fundamental material.A reasonable case can be made, however, that most of the current basic mechanics curriculumconsists of a set of techniques that allow solutions to be obtained for certain special cases in theabsence of a computer. In pre-computer times, therefore, a student would be as well equipped as

    possible to solve problems in mechanics.While integration of computation with the curriculum sounds good on the surface, it brings upthe following controversial issue: Is it reasonable to design a curriculum that depends almostentirely on computation to obtain solutions? This question will certainly be answered in thenegative by a substantial number of engineering educators. However, this paper is based on anaffirmative response. The rationale is that very few problems of modern practical engineeringimportance can be solved without a computer. Computer-based solution techniques can be

    justified if they broaden the scope of problems that can be solved.

    The approach to mechanics proposed here starts with the assertion that there are two fundamentaltopics to be covered: 1) kinematics, and 2) Newtonian mechanics. Kinematics establishes theconcepts of position, velocity and acceleration in the common three-dimensional space.Newtonian mechanics describes the connections among inertial, point-mass bodies, forces andkinematics. All material beyond this represents techniques that allow these fundamentalprinciples to be used to solve problems of practical importance.

    The method chosen, for its generality, is to treat all mechanical bodies as pseudo-rigid. That is,mechanical bodies are modeled as collections of point-masses connected by springs (and,possibly, dampers) that are very stiff, but not infinitely stiff. The stiffness must be high enoughto maintain the mechanical integrity of the body to some desired tolerance. Bodies modeled thisway can be connected to other bodies or to constraints to solve mechanical system problems.Problems formulated in this manner can be solved as initial-condition ordinary differentialequations (ODEs). Each mass contributes six states to the system equation (that is, six first-orderODEs -- for position and velocity in x, y, and z). While the use of pseudo-rigid bodies as amodeling technique is not new, it is proposed here as a unifying methodology for basic levelmechanics.

    Point-mass modeling can be used to solve a huge variety of problems in rigid body mechanics,including three-dimensional dynamics, constrained motions, rotational motions, etc., all within

  • 7/29/2019 Mechanics Oop

    3/20

    DRAFT: J anuary 31, 2000

    3

    the context of solving sets of first-order, nonlinear ODEs. The solution is only practical usingcomputer methods because of the large number of equations generated even by relatively simplesystems. However, the scope of problems that can be solved covers many areas currentlyconsidered advanced. The trade-off for this generality is the need to understand and carefullyapply error analysis to the results. Because of the stiff springs, the ODEs are mathematically

    relatively stiff so choice of solution method and error control can be quite important. A secondlayer of error is introduced because of the pseudo-rigid model (i.e., how stiff is stiff enough?)

    Because point-mass models of rigid bodies are all constructed from a small set of primitiveelements, masses, springs, dampers, an object-oriented approach to computationalimplementation is natural. The object-oriented approach is efficient because models are builtfrom pre-defined elements and those elements can be extended to account for situations notanticipated at the time the original software base was created. The extensions themselves use thesame syntax as the original model elements so, if well designed, are also reusable and appear tosubsequent users as no different than the original library of modeling elements.

    Because the method of constructing computational models is well defined, it is as effective forthe development of automated or semi-automated modeling software as it is for direct modelconstruction in the base language. At the lowest level, classes are defined for masses and forconnectors. Connectors include both springs and dampers. Modelers, however, interact with amore abstract class representing rigid bodies. Each of these elements contains a collection of masses and connectors. The rigid body abstraction is important because it allows for underlyingmodels to be changed without changing the application code.

    Motivation The notion that a reexamination of the basic mechanics curriculum was warranted came fromexperience with a freshman seminar titled Animating Physics. The purpose of this seminar was

    to offer an attractive experience that would parallel and integrate material from math, physics,and computation courses. The theme of the course was the production of physically realisticanimations, that is, animations in which the motions of the objects obeyed the laws of physics(http://euler.Berkeley.EDU/~dma/res.html , then follow links to ME39E, Animating Physics).

    The prerequisite was high school physics (calculus was not required).

    Figure 1 shows a typical student projectfrom this class. This is the opening graphicthat was animated. The animations wereall two-dimensional, done completely inMatlab. A graphics-animation package

    was supplied that allowed students toconcentrate on the basic pictorialdescription of their problem (circles,rectangles, shapes made of multiple lines)and the computation via simulation of successive positions, shapes, colors, etc.(see the above-mentioned web site for

    copies of the sample software). Students were responsible for all of the programming involving

    Figure 1. Student Project: Newton's Cradle

    http://euler.berkeley.edu/~dma/res.htmlhttp://euler.berkeley.edu/~dma/res.htmlhttp://euler.berkeley.edu/~dma/res.html
  • 7/29/2019 Mechanics Oop

    4/20

    DRAFT: J anuary 31, 2000

    4

    the physics of their specific problems. The programming was done using Matlabs standardprocedural language.

    The course was successful as a seminar in several ways: It did interest students. Animation was a theme that people could identify with

    and understood immediately. Students dealt with integration of math, physics, and computing in a natural way.It was very clear that such integration was necessary to produce an animation.

    It explored the role of extended projects in engineering science instruction.Students picked problems with significant complexity and were not afraid of nonlinearities or system configuration changes.

    Despite the successes of this seminar, several disturbing factors emerged. Two were particularlyinfluential in motivating a complete reexamination of the physics curriculum:

    Students were notably unprepared for dealing with a numerical approach toproblem solving.

    There were a number of interesting problems for which they had no usefulformulation tools, particularly problems involving simple constrained motions.

    The numerical approach to problem solving in physics was clearly alien to these students. Theyseemed to feel that all solutions should be expressible as closed-form expressions for position.

    They also had no experience with anything but the special case problems (constant velocity,constant acceleration, etc.) for which formulaic results are available.

    Since students selected their own projects, a large variety of physical situations were represented.Some of these used physical configurations for which none of the solution methods available tostudents at this level were applicable. A good example of a problem of this sort is the double

    pendulum. The single pendulum is discussed in all basic physics classes, but the solution used isnot generalizable to a double pendulum.

    A Numerical/Computational Approach The work in the Animating Physics seminar strongly suggested a numerical approach tomechanics. However, an examination of the current curriculum is not encouraging. Because asubstantial part of the curriculum is devoted to special cases for which analytical solutions can beobtained, it does not seem that a numerical approach would add much. Adding numerics to theexisting curriculum might allow for introduction of some nonlinearity, but would not expand onthe scope of problems that could be solved. An alternative is needed!

    The current curriculum can be viewed in three parts: kinematics, Newtonian point-massmechanics, and special cases of problems that can be solved without a computer. If a suitablemethodology can be found, an attractive approach would be to keep the first two topics becausethey represent fundamental physical phenomena and eliminate the special cases. Such anapproach is discussed below.

  • 7/29/2019 Mechanics Oop

    5/20

    DRAFT: J anuary 31, 2000

    5

    KinematicsBasic kinematics describes motion in the normal Euclidian three-dimensional space.Decomposition of the motion into orthogonal components is a key element. Most of the actualnumerics in solving mechanics problems is in the kinematics. All problems are viewedincrementally, with acceleration or velocity given and position (and velocity, if necessary)calculated by accumulation. Finite accumulation is used rather than the integral or differentialequation formulation to allow introduction of this material before calculus. This order shouldactually help the calculus courses because it would add motivation and relevance to the calculusmaterial.

    The basic Euler formulation for numerical solution of differential equations is used to introduceincremental kinematics,

    ttatvttv +=+ )()()( Eq (1)ttvtxttx +=+ )()()( Eq (2)

    This form makes intuitive sense and is easy to explain and implement. It can be used either forevaluation of integrals or for differential equations. It can be applied to orthogonal componentsor to motion along a path.

    Understanding the use of this formulation is the key to the numerical approach. Newtonianmechanics will be used to calculate accelerations for a system of bodies. These kinematicrelations are then used to calculate the actual velocities and positions.

    An example of this approach is the problem of motion along a prescribed path. This problem,and several variants of it, is used as a theme problem for the sections that follow. It is typical of problems that students can work on using the approach described here. It uses thenumerical/computational approach to generalize well beyond the types of problems that can besolved using the current curriculum. However, the programming involved requires studentintensity that is beyond that of the current curriculum also.

    In this case, the problem is stated in terms of velocity. That is, the velocity and the nature of thepath are specified. The objective is to calculate the position of the object as a function of time.Only the second of the Euler forms, for position, is needed for this problem. The general methodof solution is to compute how far the object will move along the path for the current timeincrement, then use a search algorithm to find the point on the path the given distance from thecurrent point. The search is a one-dimensional search with the angle from the current point as thesearch variable. As an assignment, this problem has a number of interesting aspects. In additionto exploring the kinematics of a velocity-specified problem, there is the issue of how to do asearch ( i.e. , solve a general one-dimensional nonlinear equation).

    A number of simple problems can be given initially, such as straight lines and circles. Theseproblems are also solvable analytically, if desired. Figure 2 shows the result for a circle. The Xand Y positions versus time show the familiar sinusoidal shapes and the swept angle increasesproportionally with time.

  • 7/29/2019 Mechanics Oop

    6/20

    DRAFT: J anuary 31, 2000

    6

    Unlike the analytical result for a problem of this sort, the numerical solution is fullygeneralizable. For example, the velocity along the path may not be a constant, Figure 3.

    On the other hand, the path might not be circular, Figure 4. In this case, though the velocityalong the path is also constant, the X and Y positions of the object versus are not even vaguelysinusoidal, nor does the swept angle vary linearly with time.

    0 5 100

    0.5

    1

    1.5

    2

    time

    x

    0 5 101.5

    2

    2.5

    3

    time

    y

    0 5 100

    200

    400

    600

    800

    time

    a n g

    l e ( d e g

    )

    0.5 1 1.51.5

    2

    2.5

    x

    y

    Figure 2 Following a Circular Path with Specified Velocity

    0 5 100

    0.5

    1

    1.5

    2

    time

    x

    0 5 101

    1.5

    2

    2.5

    3

    time

    y

    0 5 100

    200

    400

    600

    800

    time

    a n g

    l e ( d e g

    )

    0.5 1 1.51.5

    2

    2.5

    x

    y

    Figure 3 Motion on a Circular Path: Varying Velocity

  • 7/29/2019 Mechanics Oop

    7/20

    DRAFT: J anuary 31, 2000

    7

    The program that created these results was written in Matlab. The portion of the program wherethe primary material of the problem is located is quite small (and consists mostly of copyingoutput values and comments),

    for t = 0:DeltaT:TFinal% Copy output valuesi = i + 1;tt(i) = t;yy(i,1) = x;yy(i,2) = y;yy(i,3) = ang;% Compute the current velocityvelcur = vel + velvar * sin(velfreq * t);% Compute distance to move based on velocityd = velcur * DeltaT;% Find point on path at this distance - uncomment whichever is%in use (make sure to change Fxy accordingly!)%[x,y,ang] = FindPoint(circ,x,y,d,ang);[x,y,ang] = FindPoint(ellipse,x,y,d,ang);

    end

    As a student project, much of the interesting work is buried in the FindPoint() function. This iswhere the search takes place. Some studies of error control would be a crucial part of any workwith the program. At a geometric level, chordal steps approximate the motion on the path. Thusthe distance traveled is in error. That error can be explored by varying DeltaT and comparingcomputed travel distance (the computation of travel distance isnt shown in the code above, butis a simple addition). The search algorithm is another rich source of exploration (a simple variantof a one-dimensional simplex search is used in this program).

    0 5 10-1

    0

    1

    2

    3

    time

    x

    0 5 101.5

    2

    2.5

    3

    time

    y

    0 5 100

    100

    200

    300

    400

    time

    a n g

    l e ( d e g

    )

    0 1 2

    1

    1.5

    2

    2.5

    3

    x

    y

    Figure 4 Motion on an Elliptical Path with Specified Velocity

  • 7/29/2019 Mechanics Oop

    8/20

    DRAFT: J anuary 31, 2000

    8

    Construction of the entire program would be a significant project for students somewhere in thefirst quarter of a unit on mechanics. This is typical of the pedagogical question relating to use of extended projects in the engineering science curriculum, is the time a student would need toconstruct this program worthwhile? While a full answer to this question is well beyond thescope of this paper, some relevant points can be made: in order to complete such a project a

    student would have to integrate knowledge from several subject areas and he or she would havean experimental vehicle to carry out a variety of experiments in kinematics. The program couldalso be reused in subsequent units. For example, it would only take changes in a few lines of thecode to convert the problem from a velocity specification to an acceleration specification.

    Point-Mass MechanicsNewtons laws provide the means of relating forces and masses to kinematics. For constant massproblems they give a direct connection to acceleration. For numeric purposes, it is much better toalways posit the relationship in terms of momentum. Then problems with varying mass can alsobe solved, although students will almost always take the F=ma shortcut because there arerelatively few varying mass problems (maybe the y2k computer bug could have some influence

    here!). Newtons laws also define an inertial reference frame that establishes some of the limitsof validity of the Newtonian approach.

    By adopting a numeric approach, a wide variety of point-mass problems can be solved. Thecircular motion kinematics example can be modified to produce a problem of constrained motionof a point-mass object. The problem consists of a vehicle moving on a track of specified shapedriven by a force that is always in the direction of motion. The vehicle is modeled as a pointmass. As before, the numerical approach allows for any shape of track to be used. Theconstraining force can also be computed.

    Most of the kinematics sample program remains the same. The core code is modified to calculate

    acceleration on the basis of the force applied to the vehicle. The constraining force isapproximated from the change in velocity in the direction orthogonal to the motion. The coreMatlab code is:

    for t = 0:DeltaT:TFinal% Copy output valuesi = i + 1;tt(i) = t;yy(i,1) = x;yy(i,2) = y;yy(i,3) = Fconstraint;% Acceleration along the pathif t < TimeOff, f = force; else f = 0; endaccel = f / mass;% Compute the current velocityvel = vel + accel * DeltaT;% Compute distance to move based on velocityd = vel * DeltaT;% Find point on path at this distance - uncomment whichever is%in use (make sure to change Fxy accordingly!)%[x,y,ang] = FindPoint(circ,x,y,d,ang);[x,y,ang] = FindPoint(ellipse,x,y,d,ang);

  • 7/29/2019 Mechanics Oop

    9/20

    DRAFT: J anuary 31, 2000

    9

    % Compute constraining forcedAng = ang - AngPrev;AngPrev = ang;Fconstraint = vel * sin(dAng) / DeltaT; % Change in othogonal velocity

    end

    The problem is set up with the vehicle initially at rest. The force is applied for a specified time,and then the vehicle is left to coast (with no friction). The results are shown in Figure 5 forcircular motion. The lower left graph shows the constraining force. It builds with time as thevehicle speed increases, and then becomes constant as the vehicle coasts at constant velocityalong the path.

    For elliptical motion, Figure 6, the same two changes are made as in the kinematics example. The constraining force is dramatically different than in the circular motion case.

    0 5 100

    0.5

    1

    1.5

    2

    time

    x

    0 5 101.5

    2

    2.5

    time

    y

    0 5 100

    100

    200

    300

    400

    500

    time

    F c o n s t r a

    i n t

    0.5 1 1.5

    1.6

    1.8

    2

    2.2

    2.4

    x

    y

    Figure 5 Point-Mass Vehicle on a Circular Track

  • 7/29/2019 Mechanics Oop

    10/20

    DRAFT: J anuary 31, 2000

    10

    There are always interesting error analysis issues with numerically produced results. In this case,the tolerance specified in the search for the correct point on the path shows up in the calculationof the constraining force. Since that calculation, in effect, differentiates the vehicle-headingangle, small errors in computation of the angle can be magnified. Using smaller step sizes for theintegration will magnify that effect further, giving a good example showing that smaller is notalways better in step size.

    In these cases, although not very much has changed in the code, a full differential equation isbeing solved. To the student, however, it appears in a very natural way as an extension of thekinematics material.

    Pseudo-Rigid ElementsWhile the above solutions display considerable generality in terms of the way that the vehicle isdriven, the shape of the track, etc., the formulation of how the constraint is applied and how theconstraint forces are calculated is largely ad hoc . A much more consistent formulation can bebased on the use of pseudo-rigid elements. In this case, a spring is attached between the massrepresenting the vehicle and a point that can move along the specified path ( Figure 7, not to

    scale!) In order to compute the spring force, the moveable point is first positioned along the pathsuch that the distance between that point and the vehicle mass point is minimized. The springforce calculation then proceeds. If the spring constant is made very high, but not infinite, it willact as a constraining element that guarantees that the moving mass is always within a reasonabletolerance of the constraining path (the rest length of the spring is set to zero).

    0 5 10-1

    0

    1

    2

    3

    time

    x

    0 5 101.5

    2

    2.5

    time

    y

    0 5 100

    500

    1000

    1500

    time

    F c o n s t r a

    i n t

    0 0.5 1 1.5 2

    1

    1.5

    2

    2.5

    3

    x

    y

    Figure 6 Point-Mass Vehicle on an Elliptical Track

  • 7/29/2019 Mechanics Oop

    11/20

    DRAFT: J anuary 31, 2000

    11

    Whereas the earlier solution was an ad hoc one-dimensional solution based on motion along thepath, this is a general solution of a two-dimensional problem. No special solution techniques areneeded to solve the problem. The force on the mass from the spring is computed according to thenormal rules for computing such forces. The constraining force is just the force in the spring. No

    special computation is required to determine the constraining force. The shape of the path isunique to the particular problem being solved, and a method must be provided to find the pointon the path nearest to the current position of the moving mass. These are general techniques,however, and are useful in a wide variety of other problems. The solution is easily generalized tothree dimensions, for example. The description of the path and the solution of the }nearestpoint problem become more difficult, but nothing really changes.

    The primary Matlab code for this problem is below. It still uses the Euler solution method,however, this case might be a good stepping-off point for examination of other ODE solversbecause of the stiffness of the resulting equations.

    for t = 0:DeltaT:TFinal% Copy output valuesi = i + 1;tt(i) = t;yy(i,1) = x;yy(i,2) = y;yy(i,3) = Fconstraint; %sqrt(vel * vel.');% Spring force%xp = NearestPointCircle(circ,x,y); % Find the point on the circle

    % nearest to (x,y) -- This is an example of how to save computing time% by taking advantage of special cases.

    xp = NearestPoint(PathIndex,path,x,y,xydir(ang),tol);

    L = [x y] - xp;Ls = sqrt(L * L.');ang = Fslope(PathIndex,path,xp(1),xp(2),ang);if Ls == rs, Fsp = [0 0]; Fs = 0;else

    Fs = ks * abs(Ls - rs);Fsp = (L / Ls) * Fs;

    end

    Point-Massobject

    Spring

    Path

    Moving referencepoint

    Figure 7 Pseudo-Rigid Constraint to a Path

  • 7/29/2019 Mechanics Oop

    12/20

    DRAFT: J anuary 31, 2000

    12

    Fconstraint = Fs;% Force on massif t < TimeOff

    f = force * [cos(ang) sin(ang)];else f = [0 0];end

    % Compute the current velocityMom= Mom+ (f - Fsp) * DeltaT; % Update momentum

    %disp([ang*180/pi atan2(vel(2),vel(1))*180/pi f Fsp Ls*ks]);vel = Mom/ mass; % Convert to velocity% Compute distance to move based on velocityxnew = [x y] + vel * DeltaT;x = xnew(1);y = xnew(2);

    end

    Note that in this case the mechanics computation is based on momentum rather than acceleration,as was the case for the previous example.

    The solution for the elliptical path is shown in Figure 8. The obvious price paid for the increasedgenerality of the solution method is in computing time. As a note on generality, the method usedfor this problem easily solves the double pendulum problem. There are also several differenterror control issues raised in this case. An interesting question, probably raised by an errorcontrol issue, is left as an exercise for the reader: why are the peak values of constraining forcehigher in Figure 8 than they are in Figure 6? A more important question: are those peak values tobe believed?

    0 5 10-1

    0

    1

    2

    3

    time

    x

    0 5 101

    1.5

    2

    2.5

    3

    time

    y

    0 5 100

    500

    1000

    1500

    time

    F c o n s t r a

    i n t

    0 1 2

    1

    1.5

    2

    2.5

    3

    x

    y

    Figure 8 Elliptical Track: Pseudo-Rigid Constraint

  • 7/29/2019 Mechanics Oop

    13/20

    DRAFT: J anuary 31, 2000

    13

    Rigid BodiesOne step takes the methodology in the previous section, which applies to the solution of problems of the motion of constrained point-masses, to the much broader domain of rigid bodydynamics. A rigid body can be thought of as a set of point masses connected by rigid, masslessrods. In the spirit of the previous problem, those rods represent constraints on the distance fromeach point-mass to its neighbors. If, for computational purposes, those constraints were replacedby pseudo-rigid, massless springs, it would appear that problems in rigid body dynamics couldbe solved by the same computing methodology that was used to solve the point-mass on a pathproblem. This is exactly the case.

    Thus, having arrived at this point, the fundamentals of mechanics are complete! As anillustration, consider a solution to a problem in basic gyroscopic motion. Figure 9 shows aschematic of a simple top. When placed as shown, it will fall over if it is not spinning. If it isspinning rapidly enough, it will balance. This is a problem in three-dimensional dynamics, whichis not accessible to students who have studied basic mechanics but that could be solved by suchstudents (or practicing engineers) using the point-mass approach.

    Figure 10 is a point-mass representation of the top. The disk is modeled as a set of three pointmasses with pseudo-rigid connections. The rod balancing the disk is modeled by three morepseudo-rigid connections that constrain each of the masses to be a fixed distance from a fixedpivot point.

    Figure 9 A " Top"

  • 7/29/2019 Mechanics Oop

    14/20

    DRAFT: J anuary 31, 2000

    14

    Figure 11 shows the simulated behavior of the top. A small transverse initial velocity is

    introduced as a disturbance. The upper graph gives the X and Y locations of the center of thedisk and the lower graph has the X location of one of the masses, all as a function of time. Thecenter point motion shows the precession of the top while the outer edge X location shows thespinning motion.

    It is important to note that the solution to the top problem involved nothing more than thekinematics and Newtonian point-mass mechanics already introduced. This is a problem includingboth three-dimensional dynamics and constrained motion.

    In addition to the questions of error analysis noted previously, a couple of new issues are raisedwith this problem. One of these is the representation of a rigid body. The top is described as adisk on a massless supporting rod. The disk is represented by three point-masses. How is this

    justified? There are two approaches to rigid body representation. One is to position an arbitrary

    Figure 10 Point-Mass Representationof a Top

    0 1 2 3 4 5 6 7 8-0.4

    -0.2

    0

    0.2

    0.4

    Center X & Y

    0 1 2 3 4 5 6 7 8-1

    -0.5

    0

    0.5

    1

    Edge X

    Figure 11 Simulated Motion of Top

  • 7/29/2019 Mechanics Oop

    15/20

    DRAFT: J anuary 31, 2000

    15

    number of point masses in approximately the locations of the actual mass. The approximation isdeemed to be adequate when the result does not change significantly with the addition of moremasses. Appealing to rigid body theory however, it can be shown (XXXX ) that it takes at mostfour masses to represent a rigid body. As long as the principal moments of inertia match thepseudo-rigid body representation retains all of the dynamic properties of the original object. For

    degenerate objects, such as a disk, fewer masses are needed. This is a good example of how theintroduction of appropriate theory can make the numerical representation much more efficient.

    A second issue in complex systems, particularly with three-dimensional motion, is thedescription of the resulting behavior. The problem was sidestepped in this case by usingCartesian coordinates of different places on the object. Some kind of rotational angle system isneeded in most cases, however. Unfortunately, except for direction cosines, all of the anglesystems contain singularities. Direction cosines do not have any singularities but, with ninevalues, are not very convenient! Angular representations are not necessary for the basic systemsimulation but can be important, for example, if there is a force that follows the orientation of anobject (typical in propulsion, jet engines, rockets, etc.). Angles, however, are often very

    important in behavioral visualization. A number of angle systems are in common use roll-pitch-yaw, azimuth-elevation-range, Euler angles, etc. It seems likely that a choice must beavailable for visualization but a single standard may be important for simulation.

    Computing ConsiderationsIt only takes a few examples to realize that constructing models from scratch using point-massmethodology can get very tedious indeed! The number of components goes up very rapidly andeach mass contributes six state equations. Keeping track of all of the correct directions and signconventions can be a major headache. Object-oriented computing should keep this problem incheck by burying those details into the class structure from which specific models can beconstructed. The fact that regardless of the nature of the bodies used in the modeling, the

    underlying computation always sees nothing but a cloud of masses, springs and dampers makesobject-oriented computing very attractive.

    In fact, while the path-following examples were constructed from scratch using Matlab, the topgyroscopic example was built using a semi-object-oriented Matlab infrastructure. The codemakes heavy use of Matlab version 5s data structures, but does not use its class structure.Defining the disk uses the following code sequence:

    DiskMass = 0.75; % Total mass of diskDiskDiameter = 2; % Diameter of the uniformdisk (point masses will

    % be located so as to match the moment of inertia to that% of the uniformdisk

    c0 = [0 0 0]; % Coordinates of the initial center position[Masses,Springs,Disk1] = CreateUniformDisk(...DiskMass,DiskDiameter,c0,Masses,Springs);

    The variables Masses and Springs are the lists of masses and springs. The call toCreateUniformDisk() adds appropriate elements to those lists to create a model for the specifieddisk.

  • 7/29/2019 Mechanics Oop

    16/20

    DRAFT: J anuary 31, 2000

    16

    The disk is then constrained to a fixed point to create the top by adding pseudo-rigid springs asconnections:

    kspr = 1;cnflag = 1; % These are dummy constraint springsGroundPt = [0 0 -2]; % A point on the z axisfor i = 1:3 % Constraints to all three masses

    [Springs,ifix] = AddFixedEndSpring(Masses,Springs,i,...GroundPt,kspr,cnflag);

    end

    The basic calculation in the right-hand side function used for the ODE solver calculates all of thespring forces and uses those to compute the derivatives of the momentum terms,

    MM = InsertStateVector(MM,x); % Update Mass information

    % Compute the spring forces in all of the springsSS = SpringForce(SS,MM);

    InitFlag = 1;MM = SumSpringForces(MM,SS,InitFlag); % Sumspring forces (2nd argument% zeros the forces before summation, 0 would add to the% existing values)% Additional forces can be added after this has been done

    InitFlag = 0; % For any additional forces, sumwith previous entriesMM = GravityForces(MM,MiscPar.Gravity,InitFlag);

    What is important to note here is that the calculation is completely general. It is independent of the details of the application because all applications are just collections of masses and springs(the variables MM and SS are the same as the Masses and Springs used above). Unless there issome unique calculation such as a control or other input of some sort, the same right-hand sidefunction can be used with many applications.

    Before pursuing this Matlab approach too far, however, it became obvious that it wouldnt worksatisfactorily. The major problem was computing time. Because Matlab is interpreted, it is to beexpected that its compute times will be long but not as long as was observed for the samplesused (including the gyro-top). The probable problem is associated with the use of data structures(MM and SS are data structures). Because Matlab has neither pointers nor references, every timea data structure is passed into a function, modified, and passed back, the entire data structuremust be copied into fresh memory several times. This is very time consuming and generates alarge amount of memory thrashing. For this reason, the Matlab code was not completed and isnot available for distribution.

    To get a more computationally efficient environment, a C++version was created. It followedmuch of the structure of the Matlab version, but used a full class-based approach and addedanother object layer. As before, objects were defined for masses and springs and lists werecreated to manage them. In addition, a class was defined for a body. This was absent in theMatlab version. As can be seen from the code above, keeping track of bodies is up to theprogrammer. The advantage to defining a class for bodies is that many general-purposeoperations can be defined that pertain to bodies. The general design is that in most cases the

  • 7/29/2019 Mechanics Oop

    17/20

    DRAFT: J anuary 31, 2000

    17

    programmer putting together a model of a physical system will deal only with body elementsand will not have to manipulate the internal masses or springs at all.

    The C++ approach succeeded in increasing the computation speed considerably (100-fold ormore). The downside to this switch is the loss of all of Matlabs mathematical and graphical

    facilities. Unless quality distributable libraries for C++can be located these facilities must bereplaced locally. The sample below uses locally produced libraries for the ODE solver, matrixfunctions, etc.

    The example of a single pendulum shows quickly how the C++ software works. The maindifference from the Matlab software shown above is that all references are to bodies ratherthan to masses and springs. To set up the pendulum problem a body consisting of a single massis created for the bob and a second body is created for the pivot point,

    CPointMass *PendulumBob1 = new CPointMass(MassList,BodyList,SurfaceList,MassBob1,p1,v1,"Bob1");

    CFixedPoint *Pivot = new CFixedPoint(MassList,BodyList,SurfaceList,

    pivot,"Pivot Point");

    The SurfaceList allows for the definition of surfaces associated with the bodies (something thatcould not be done with the mass-spring orientation). This can be important for collisions, bodiesthat slide or roll, etc. The surface facility is not yet highly developed.

    The pendulum bob is constrained to the pivot point by,

    double bc[3] = {0.0,0.0,0.0}; // Location of bob mass in body coordinatesPendulumBob1->ConnectToConstraint(MassList,ConnectionList,Pivot,bc,kspr1,kdmp1);

    Computation is even more compact than in the previous case. The generic right-hand sidefunction for the ODE solver is:

    void CSystemODE::GetRHS(double t,double *x,double *rhs){// This is the real versionCopyFromStateVector(x,Masses); // Copy current state

    // information to the mass informationComputeConnectionForces(Connections); // Compute the

    // internal forces due to springs and dampersSumMassForce(Masses); // Zero forces on each mass and

    // add in all forces fromconnecting elementsAddGravityForce(Masses,Gravity);

    ComputeRHS(rhs,Masses,nStates);}

    Most of the other code needed to set up a solution sets parameter values, determines output forwriting to a file, establishes the connection to the ODE solver, etc.

  • 7/29/2019 Mechanics Oop

    18/20

    DRAFT: J anuary 31, 2000

    18

    A difference between this example and the traditional pendulum example is that this one worksin three dimensions. An interesting problem is finding the correct initial velocity so that thependulum moves in a circle at constant height.

    Figure 12 shows a nearly correct solution. The top graphs show the x and y motions as a functionof time; the lower left graph shows the z motion and the lower right shows the projection of thependulum motion onto the XY plane. The z motion is limited to about +/- 0.01. The buzz in thez-motion graph is the oscillation due to the compliance of the spring constraining the pendulumto the pivot. That can be reduced at the expense of increased computing time by increasing thestiffness of that spring.

    An incorrect solution is shown in Figure 13.

    0 5 10 15-2

    -1

    0

    1

    2

    time

    x

    0 5 10 15-2

    -1

    0

    1

    2

    time

    y

    0 5 10 15-1.84

    -1.82

    -1.8

    time

    z

    -1 -0.5 0 0.5 1

    -1

    -0.5

    0

    0.5

    1

    x

    y

    Figure 12 Single Pendulum: Motion in a Horizontal Plane

  • 7/29/2019 Mechanics Oop

    19/20

    DRAFT: J anuary 31, 2000

    19

    This problem is interesting because it introduces the beginnings of gyroscopic motion using onlya single point-mass and a constraint. Once the pendulum is set in motion revolving around the z-axis it is very stable in that motion. The faster it revolves, the more stable it is. It also shows thata more general approach to a standard textbook problem leads to interesting and complicatedproblems arising from a relatively simple physical system.

    As a student exercise it could be a good vehicle for relating simulation to problem solution andanalytic techniques. The solution above was found by trial-and-error. However, a faster route tothe solution would be to look at the constraining force on the pendulum and realize that thesolution is reached when the z-component of the constraining force exactly equals the gravityforce. This force is easily obtained from the simulation. Because the motion is circular, therequired velocity can also be computed directly from the acceleration needed to keep thependulum in pure horizontal motion.

    ConclusionsAs shown by the examples, the point-mass approach to mechanics can be used for problems thatare far beyond the scope of current curricular material. Further, an object-oriented computationalapproach seems essential for all but the simplest problems. Otherwise the internal bookkeepingcomplexity could quickly overwhelm any attempts at rational software design.

    These observations support the initial hypothesis that a base-zero re-examination of themechanics curriculum is warranted. The material seems ideally suited to an integrated approach,including computation, modeling, and mathematics with the physics. Modeling seems anespecially important addition here. Modeling explores the connection between the computationalphysics and the real-world systems the physics purports to represent. The ability to handle morerealistic systems means that the modeling has a broader purview in which it can be applied. Inany case, though, good attention to modeling in an academic context is very difficult. One areaof mathematics that is clearly emphasized in this work is trigonometry. Beyond that, subjects likeinterpolation, curve-fitting, matrix manipulation, solution of linear and nonlinear equations, ODE

    0 5 10 15-2

    -1

    0

    1

    2

    time

    x

    0 5 10 15-1

    -0.5

    0

    0.5

    1

    time

    y

    0 5 10 15-2.1

    -2

    -1.9

    -1.8

    -1.7

    time

    z

    -1 -0.5 0 0.5 1

    -0.5

    0

    0.5

    x

    y

    Figure 13 Single Pendulum: "Incorrect" Initial Velocity

  • 7/29/2019 Mechanics Oop

    20/20

    DRAFT: J anuary 31, 2000

    solvers, and others all play a role. How much is exposed and how much is hidden of thesesubjects is a curricular decision.

    The computational component brings up other issues. While some early preliminary work can bedone in a friendly environment such as Matlab, the need for efficient computing pushes the

    work very quickly to a compiler environment such as C++. Learning C++ (or an equivalent)would absorb a substantial amount of time at the late high school-early college level. Suchlanguages are not usually the vehicles for personal computing, as is used here for the solutionof problems in physics. On the other hand, one objection to C++or the like, the turnaround timefor compile-link-execute, is no longer a problem. Modern compilers, with incrementalcompilation, can handle a small change in source code and start a new computation in a fewseconds. Thus, using the main() routine of a C++program as a working space for manipulating asimulation is entirely practical.

    Students took very well to animation, so its use as a visualization tool for solutions could be anexcellent way to tie many aspects of the experience together.