vmm.ode
Class ODE_2D

java.lang.Object
  extended by vmm.core.Exhibit
      extended by vmm.ode.ODE_2D
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.ChangeListener, Decorateable, Parameterizable
Direct Known Subclasses:
ODE_1D, ODE1stOrder2D, ODE1stOrder2DNonAutonomous, ODE2ndOrder2D, ODE2ndOrder2DNonAutonomous

public abstract class ODE_2D
extends Exhibit

Represents an ODE exhibit that will be displayed in two dimensions.


Nested Class Summary
 class ODE_2D.ODEView
          Represents the default view for an ODEFirstOrder2D.
 
Field Summary
protected  boolean addAnimateCheckBoxToControlPanel
          If set to false in the constructor of a subclass, then the check box for turning animatino of orbit drawing will not be added to the control pandl (although the command will still be in the Action menu).
protected  boolean addLinesCheckBoxToControlPanel
          If set to false in the constructor of a subclass, then the check box for controling whether orbits are drawn as solid lines will not be added to the control pandl (although the command will still be in the Action menu).
protected  boolean addOrbitTypesToControlPanel
          If set to false in the constructor of a subclass, then the radio buttons for selecting RungeKutta/Euler/Both will not be added to the control pandl (although they will still be in the Action menu).
protected  boolean addProjectedOrbitsAction
          If set to false in the constructor of a subclass, then the command for showing projected orbits is not added to the Action menu.
protected  boolean canShowVectorField
          Tells whether it is possible to draw a vector field for the exhibit.
protected  double dtDefault
          The value of this variable is used as the initial value of dt in the Control Panel of any view of this exhbit.
protected  double[] initialDataDefault
          Contains the initial conditions that are placed in the control panel when the exhibit is first created.
protected  java.lang.String[] inputLabelNames
          The names used for the input boxes where the user can type in the initial values for an integeral curves.
protected  boolean isAutonomous
          Tells whether the ODE is autonomous (i.e.
static int ORBIT_TYPE_BOTH
           
static int ORBIT_TYPE_EULER
           
static int ORBIT_TYPE_RUNGE_KUTTA
           
protected  double timeSpanDefault
          The value of this variable is used as the initial value of Time Span in the Control Panel of any view of this exhbit.
 
Fields inherited from class vmm.core.Exhibit
decorations, exhibitNeedsRedraw, isMorphing, morphingView, parameters, previousTransform
 
Constructor Summary
protected ODE_2D(boolean canShowVectorField, boolean isAutonomous, java.lang.String... inputLabelName)
          Constructor sets the default background to be black, and sets the value of the final "isAutonomous" property and the lables to be used for the input boxes for initial conditions.
 
Method Summary
protected  void doDraw(java.awt.Graphics2D g, View view, Transform transform)
          Draws a direction field, but only for an exhbit in which the canShowVectorField property is true and then only if the exhibit is being displayed in an ODEView whose showDirectionField property is turned on (or in the unlikely event that it is being displayed in some other type of View).
protected  java.awt.geom.Point2D extractPointFromData(double[] pointData)
          Extract from the data for a point on the integral curve the actual point that is to be displayed on the screen.
 TimerAnimation getCreateAnimation(View view)
          For an ODE view, returns the animation that redraws the current orbit, if there is one, or draws the default orbit as defined by initialDataDefault, if the value of that variable is non-null.
 View getDefaultView()
          Returns a view of type ODE_2D.ODEView.
protected  MouseTask makeDefaultMouseTask(ODE_2D.ODEView view)
          Should construct and return a mouse task appropriate for this exhibit, to be used in the specified view.
protected abstract  void nextEulerPoint(double[] pointData, double dt)
          Computes the next point on an integral curve, using Euler's method.
protected abstract  void nextRungeKuttaPoint(double[] pointData, double dt)
          Computes the next point on an integral curve, using the Runge-Kutta method.
protected  double vectorField_x(double x, double y, double t)
          Returns the x-component of the vector field at point (x,y) and time t.
protected  double vectorField_y(double x, double y, double t)
          Returns the x-component of the vector field at point (x,y) and time t.
 
Methods inherited from class vmm.core.Exhibit
addChangeListener, addDecoration, addExtraXML, addParameter, addView, clearDecorations, computeDrawData, computeDrawDataHook, doDrawHook, fireExhibitChangeEvent, forceRedraw, getActionsForView, getAdditionalAnimationsForView, getAlternativeViews, getBuildAnimation, getDecorations, getDefaultBackground, getDefaultForeground, getDefaultTransform, getDefaultWindow, getFramesForMorphing, getMorphingAnimation, getName, getParameterByName, getParameters, getSettingsCommandsForView, getTitle, getUseFilmstripForMorphing, getViews, parameterChanged, readExtraXML, removeChangeListener, removeDecoration, removeParameter, removeView, render, setDefaultBackground, setDefaultForeground, setDefaultWindow, setDefaultWindow, setFramesForMorphing, setName, setUseFilmstripForMorphing, stateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORBIT_TYPE_RUNGE_KUTTA

public static final int ORBIT_TYPE_RUNGE_KUTTA
See Also:
Constant Field Values

ORBIT_TYPE_BOTH

public static final int ORBIT_TYPE_BOTH
See Also:
Constant Field Values

ORBIT_TYPE_EULER

public static final int ORBIT_TYPE_EULER
See Also:
Constant Field Values

isAutonomous

protected final boolean isAutonomous
Tells whether the ODE is autonomous (i.e. independent of time). This final variable is set by the constructor ODE_2D(boolean, boolean, String[]), with the actual value coming from the constructor of each subclass. Autonomous and non-autonomous vector fields have different behaviors.


canShowVectorField

protected final boolean canShowVectorField
Tells whether it is possible to draw a vector field for the exhibit. This is set in the contructor ODE_2D(boolean, boolean, String[]), with the actual value coming from the contructor of each subclass. If the value is false, then the methods vectorField_x(double, double, double) and vectorField_y(double, double, double) are never called. If the value is true, then these methods must be overridden to return the correct values. For an autonomous ODE, the display of the vector field is under control of the user. For a non-autonomous ODE, the vector field is shown only when an integral curve is being constructed. (Actually, a direction field rather than a vector field is drawn.)


inputLabelNames

protected final java.lang.String[] inputLabelNames
The names used for the input boxes where the user can type in the initial values for an integeral curves. This array is set from the String parameters to the constructor ODE_2D(boolean, boolean, String[]). There must be exactly as many strings as there are data items in the pointData array that is passed to nextEulerPoint(double[], double), nextRungeKuttaPoint(double[], double) and extractPointFromData(double[]).


addOrbitTypesToControlPanel

protected boolean addOrbitTypesToControlPanel
If set to false in the constructor of a subclass, then the radio buttons for selecting RungeKutta/Euler/Both will not be added to the control pandl (although they will still be in the Action menu).


addAnimateCheckBoxToControlPanel

protected boolean addAnimateCheckBoxToControlPanel
If set to false in the constructor of a subclass, then the check box for turning animatino of orbit drawing will not be added to the control pandl (although the command will still be in the Action menu).


addLinesCheckBoxToControlPanel

protected boolean addLinesCheckBoxToControlPanel
If set to false in the constructor of a subclass, then the check box for controling whether orbits are drawn as solid lines will not be added to the control pandl (although the command will still be in the Action menu).


addProjectedOrbitsAction

protected boolean addProjectedOrbitsAction
If set to false in the constructor of a subclass, then the command for showing projected orbits is not added to the Action menu.


dtDefault

protected double dtDefault
The value of this variable is used as the initial value of dt in the Control Panel of any view of this exhbit. The default is 0.05, but it can be reset in the constructor of a subclass.


timeSpanDefault

protected double timeSpanDefault
The value of this variable is used as the initial value of Time Span in the Control Panel of any view of this exhbit. The default is 10.0, but it can be reset in the constructor of a subclass.


initialDataDefault

protected double[] initialDataDefault
Contains the initial conditions that are placed in the control panel when the exhibit is first created. The value in this class is null, which means that the initial condition input boxed in the control panel will be empty when it first appears. Subclasses can set a different value. The value should be an array of doubles, where the first several items have the same meaning as the parameter in such methods as nextEulerPoint(double[], double) and extractPointFromData(double[]). In addition there can be up to two additional items. The first additional item, if present and greater than zero, specifies a dt for the initial orbit. The second additional item, if present and greater than zero, specifies a timeSpan for the initial orbit. If these values are not present or are less than or equal to zero, then the default dt/TimeSpan of the exhbit is used.

Constructor Detail

ODE_2D

protected ODE_2D(boolean canShowVectorField,
                 boolean isAutonomous,
                 java.lang.String... inputLabelName)
Constructor sets the default background to be black, and sets the value of the final "isAutonomous" property and the lables to be used for the input boxes for initial conditions. For a non-autonomous ODE, the first lable should be the label for the initial time input, generally just "t".

Method Detail

nextEulerPoint

protected abstract void nextEulerPoint(double[] pointData,
                                       double dt)
Computes the next point on an integral curve, using Euler's method. The pointData parameter array contains the data for the current point. This data should be replaced with the data for the next point. The size of the array and the meaning of the data that it contains will vary from one subclass to another. However, for non-autonomous ODEs, the time should always be the first parameter in the array. The second parameter, dt, gives the time step from the current point to the next point.


nextRungeKuttaPoint

protected abstract void nextRungeKuttaPoint(double[] pointData,
                                            double dt)
Computes the next point on an integral curve, using the Runge-Kutta method. The pointData parameter array contains the data for the current point. This data should be replaced with the data for the next point. The size of the array and the meaning of the data that it contains will vary from one subclass to another. But for the non-autonmous case, the time should always be the first value in the array. The second parameter, dt, gives the time step from the current point to the next point.


extractPointFromData

protected java.awt.geom.Point2D extractPointFromData(double[] pointData)
Extract from the data for a point on the integral curve the actual point that is to be displayed on the screen. The default implementation in this class takes the point from the first two components of the array for an autonomous ODE and from the second and third components for a non-autonomous ODE, allowing the first spot for the current time. Note that for non-autonomous ODEs, the time must be in the first spot in the array.


vectorField_x

protected double vectorField_x(double x,
                               double y,
                               double t)
Returns the x-component of the vector field at point (x,y) and time t. For autonomous ODEs, the result should be independent of t. The default implementation here simply returns 0. An exhibit that sets the canShowVectorField propery to true should override this method to compute the correct value.


vectorField_y

protected double vectorField_y(double x,
                               double y,
                               double t)
Returns the x-component of the vector field at point (x,y) and time t. For autonomous ODEs, the result should be independent of t. The default implementation here simply returns 0. An exhibit that sets the canShowVectorField propery to true should override this method to compute the correct value.


makeDefaultMouseTask

protected MouseTask makeDefaultMouseTask(ODE_2D.ODEView view)
Should construct and return a mouse task appropriate for this exhibit, to be used in the specified view. The default return value is a standard BasicMouseTask2D; subclasses can redefine this to add the ability to input the initial conditions with the mouse.


getCreateAnimation

public TimerAnimation getCreateAnimation(View view)
For an ODE view, returns the animation that redraws the current orbit, if there is one, or draws the default orbit as defined by initialDataDefault, if the value of that variable is non-null. Otherwise, the return value is null.

Overrides:
getCreateAnimation in class Exhibit
Parameters:
view - A View that is displaying this Exhibit. The animation, if any, that is returned by this method will be installed in the View's display. If the view is null, than a creation animation that can run independently of a view could be returned.
Returns:
A creation animation for the given View of this Exhibit. The return value can be null to indicate that no creation animation is to be run.

doDraw

protected void doDraw(java.awt.Graphics2D g,
                      View view,
                      Transform transform)
Draws a direction field, but only for an exhbit in which the canShowVectorField property is true and then only if the exhibit is being displayed in an ODEView whose showDirectionField property is turned on (or in the unlikely event that it is being displayed in some other type of View).

Overrides:
doDraw in class Exhibit
Parameters:
g - The graphics context where the Exhibit is being drawn. It has already been cleared to the background color (assuming that drawing is being done in the usual way, as defined in the top-level View class).
view - The View that is drawing the Exhibit; this object contains other information that might be of use, such as the Display, if any, associated with the View.
transform - Contains information about the rectangular area in the xy-plane that is being drawn and about the rectangle of pixels in the graphics context where it is drawn. Note that at least for the top-level View class, transform.getX() and transform.getY() can be assumed to be zero.
See Also:
ODE_2D.ODEView.setShowDirectionField(boolean)

getDefaultView

public View getDefaultView()
Returns a view of type ODE_2D.ODEView.

Overrides:
getDefaultView in class Exhibit