circuitsimulator
Class Circuit

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--edu.davidson.tools.SApplet
                                |
                                +--circuitsimulator.Circuit
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable, edu.davidson.tools.SStepable

public class Circuit
extends edu.davidson.tools.SApplet
implements edu.davidson.tools.SStepable, java.lang.Runnable

Main applet to use in exercises, displays the circuit build by a script.

See Also:
Serialized Form

Inner classes inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
 double dt
          time step width in the calculation of the V and I functions.
 double fps
          frames (clock steps) per second
 java.lang.String imagedir
           
 int noc
          number of calculations (dt time steps) in one clock step
 int numberofdt
          Number of time steps.
 double realt
          Real time for the circuit when the clock is running
 
Fields inherited from class edu.davidson.tools.SApplet
autoRefresh, clock, dataConnections, dataListeners, dataSources, debugLevel, lock, oneShotMsg, staticDebugLevel
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Circuit()
          The constructor.
 
Method Summary
 int addObject(java.lang.String name, java.lang.String list)
          The element objects (wire, resistor, capacitor, inductor, source, general) can be added at the wanted coordinates:
 java.net.URL base()
           
 void calculateCircuit()
          Calculates all Voltage and Current parameters that are defined after a parse action for a whole time interval.
 boolean changePolarity(int id)
          Changes the polarity of an element
 boolean couple(int id1, int id2)
          Couples two elements together
 java.lang.String get(int id)
          Gets the property list of an element
 double[] getCurrent(int id)
          Read the Current curve of an object for the whole time interval.
 double getDCLevel(int id)
          Calculates the mean Voltage level for a whole time interval.
 double getIAmplitude(int id)
          Read the amplitude of the Current curve for the whole time interval.
 int getID(int r, int c, java.lang.String to)
          Get the ID of an element to row "R", column "C", direction "to" horizontal ("h") or vertical ("h")
 double getIMaxT(int id)
          Read the time of the maximum Current value of an object for a whole time interval
 double getIMinT(int id)
          Read the time of the minimum Current value of an object for a whole time interval
 double getIrms(int id)
          Read the RMS value of the Current curve for the whole time interval.
 double[] getPar(int par)
           
 java.lang.String getScript()
           
 double[] gett()
           
 double getVAmplitude(int id)
          Read the amplitude of the Voltage curve for the whole time interval.
 double getVMaxT(int id)
          Read the time of the maximum Voltage value of an object for a whole time interval
 double getVMinT(int id)
          Read the time of the minimum Voltage value of an object for a whole time interval
 double[] getVoltage(int id)
          Read the Voltage curve of an object for the whole time interval.
 double[] getVoltage(int br, int bc, int er, int ec)
          Read the Voltage curve between two points of the circuit for the whole time interval.
 double getVrms(int id)
          Read the RMS value of the Voltage curve for the whole time interval.
 void init()
           
 void parse()
          Interprets the whole circuit and translates this into a set of equations.
 boolean removeObject(int id)
           
 void reset()
           
 void resetTiming()
           
 void run()
           
 boolean set(int id, java.lang.String s)
          Sets properties of an element
 void setDT(double dt)
           
 boolean setFont(int id, java.lang.String family, int style, int size)
          Change the font style of an element
 boolean setFormat(int id, java.lang.String fstr)
          Change the numeric format of an element.
 void setFPS(double fps)
           
 void setGrid(int r, int c)
          Set the size of the circuit grid.
 void setGrid(java.lang.String list)
          Set the size of the circuit grid.
 boolean setImage(int id, java.lang.String gifname)
          Changes the element's default image.
 boolean setImageVisible(int id, boolean status)
          Changes the visibility of the element's default image
 void setIntergrid(int ig)
           
 boolean setLabel(int id, java.lang.String l)
          Changes the label of an element
 boolean setMaxCurrentValue(int id, java.lang.String s)
          Sets the value for the highest possible current for the component
 void setNOC(int noc)
           
 void setNumberOfDT(int numberofdt)
           
 boolean setRCTo(int id, int r, int c, java.lang.String to)
          Move an element to row "R", column "C", direction "to" horizontal ("h") or vertical ("h")
 void setShowCurrent(int sc)
          Enable/disable the display of current arrows.
 boolean setValue(int id, java.lang.String s)
          Sets the value of a passive element (resistor, capacitor, inductor)
 boolean setValueVisible(int id, boolean status)
          Changes the visibility of an element's value or function
 void start()
          Start is called by the browser whenever the html page is entered.
 void step(double dt, double time)
          The step method that will be called at every clock step.
 void stop()
           
 
Methods inherited from class edu.davidson.tools.SApplet
addDataListener, addDataSource, cleanupDataConnections, clearAllData, clearData, cyclingClock, deleteDataConnection, deleteDataConnections, destroy, forward, getClockID, getClockTime, getDataConnectionFromDL, getDataConnectionFromDS, getDataFromDS, getDataListener, getDataListener, getDataSource, getDataSource, getDebugLevel, getID, getRunningID, getSourceData, getSourceVariables, isAutoRefresh, isClockRunning, makeDataConnection, pause, pausingClock, removeDataListener, removeDataSource, reverse, setAutoRefresh, setClockContinous, setClockCycle, setClockOneShot, setClockTime, setConnectionBlock, setConnectionListener, setConnectionSmoothing, setConnectionSource, setConnectionStride, setDebugLevel, setDefault, setDt, setExternalClock, setRunningID, setRunningID, setTimeContinuous, setTimeCycle, setTimeOneShot, startClock, stepClock, stepTime, stepTimeBack, stepTimeForward, stopClock, stoppingClock, updateDataConnection, updateDataConnections
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numberofdt

public int numberofdt

Number of time steps.

The whole time interval is determined by numberofdt times dt.

dt

public double dt
time step width in the calculation of the V and I functions.

noc

public int noc
number of calculations (dt time steps) in one clock step

fps

public double fps
frames (clock steps) per second

realt

public double realt
Real time for the circuit when the clock is running

imagedir

public java.lang.String imagedir
Constructor Detail

Circuit

public Circuit()

The constructor. DO NO SCRIPT!

Register the applet as a clock listener so that we can step the solution in time.

Method Detail

start

public void start()

Start is called by the browser whenever the html page is entered. DO NOT SCRIPT.

Since start runs after to that ALL html elements have been loaded, it is a good place to do initialization. This version of start is used for testing only since we can't script fron the JDK.

Overrides:
start in class java.applet.Applet

run

public void run()
Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Overrides:
stop in class java.applet.Applet

reset

public void reset()
Overrides:
reset in class edu.davidson.tools.SApplet

init

public void init()
Overrides:
init in class java.applet.Applet

setGrid

public void setGrid(int r,
                    int c)
Set the size of the circuit grid. The vertical size is defined by the number of rows and the horizontal size by the number of columns.
Parameters:
r - number of rows
c - number of columns

setGrid

public void setGrid(java.lang.String list)
Set the size of the circuit grid. The vertical size is defined by the number of rows and the horizontal size by the number of columns.
Parameters:
list - String : "rows=***,cols=***"

calculateCircuit

public void calculateCircuit()
Calculates all Voltage and Current parameters that are defined after a parse action for a whole time interval.

step

public void step(double dt,
                 double time)
The step method that will be called at every clock step. DO NOT SCRIPT.
Specified by:
step in interface edu.davidson.tools.SStepable

setIntergrid

public void setIntergrid(int ig)

base

public java.net.URL base()

parse

public void parse()
Interprets the whole circuit and translates this into a set of equations. Use this method when the circuit is (re)built or when new elements are added !

setDT

public void setDT(double dt)

setNOC

public void setNOC(int noc)

setNumberOfDT

public void setNumberOfDT(int numberofdt)

setFPS

public void setFPS(double fps)
Overrides:
setFPS in class edu.davidson.tools.SApplet

resetTiming

public void resetTiming()

setShowCurrent

public void setShowCurrent(int sc)
Enable/disable the display of current arrows. The arrows indicate the chosen current directions in a parsed circuit
Parameters:
sc - 0 disables the display, all other values enable the display

gett

public double[] gett()
Returns:
time array

getScript

public java.lang.String getScript()
Returns:
String representing the element list

getPar

public double[] getPar(int par)

getID

public int getID(int r,
                 int c,
                 java.lang.String to)
Get the ID of an element to row "R", column "C", direction "to" horizontal ("h") or vertical ("h")
Parameters:
r - row
c - column
to - direction

getVoltage

public double[] getVoltage(int br,
                           int bc,
                           int er,
                           int ec)
Read the Voltage curve between two points of the circuit for the whole time interval.
Parameters:
br - row for the negative probe point
bc - column for the negative probe point
er - row for the positive probe point
ec - column for the positive probe point

getVoltage

public double[] getVoltage(int id)
Read the Voltage curve of an object for the whole time interval.
Parameters:
id - the object identifier

getCurrent

public double[] getCurrent(int id)
Read the Current curve of an object for the whole time interval.
Parameters:
id - the object identifier

getVAmplitude

public double getVAmplitude(int id)
Read the amplitude of the Voltage curve for the whole time interval.
Parameters:
id - the object identifier

getIAmplitude

public double getIAmplitude(int id)
Read the amplitude of the Current curve for the whole time interval.
Parameters:
id - the object identifier

getVMaxT

public double getVMaxT(int id)
Read the time of the maximum Voltage value of an object for a whole time interval
Parameters:
id - the object identifier

getVMinT

public double getVMinT(int id)
Read the time of the minimum Voltage value of an object for a whole time interval
Parameters:
id - the object identifier

getVrms

public double getVrms(int id)
Read the RMS value of the Voltage curve for the whole time interval.
Parameters:
id - the object identifier

getIMaxT

public double getIMaxT(int id)
Read the time of the maximum Current value of an object for a whole time interval
Parameters:
id - the object identifier

getIMinT

public double getIMinT(int id)
Read the time of the minimum Current value of an object for a whole time interval
Parameters:
id - the object identifier

getIrms

public double getIrms(int id)
Read the RMS value of the Current curve for the whole time interval.
Parameters:
id - the object identifier

getDCLevel

public double getDCLevel(int id)
Calculates the mean Voltage level for a whole time interval.
Parameters:
id - the object identifier

addObject

public int addObject(java.lang.String name,
                     java.lang.String list)

The element objects (wire, resistor, capacitor, inductor, source, general) can be added at the wanted coordinates:

The 'source' has additional parameters:

Other objects have following parameters:

A probe is set as in following example:
addObject("probe","row=1,col=0,row2=3,col2=4");

Examples:

Parameters:
name - the object to be added
list - a list of settable parameters
Returns:
object identifier: the hashCode() or -1 if 'Out of Bounds'

couple

public boolean couple(int id1,
                      int id2)
Couples two elements together
Parameters:
id - the object identifier
s - the property list

set

public boolean set(int id,
                   java.lang.String s)
Sets properties of an element
Parameters:
id - the object identifier
s - the property list

get

public java.lang.String get(int id)
Gets the property list of an element
Parameters:
id - the object identifier

setValue

public boolean setValue(int id,
                        java.lang.String s)
Sets the value of a passive element (resistor, capacitor, inductor)
Parameters:
id - the object identifier
v - the new value

setMaxCurrentValue

public boolean setMaxCurrentValue(int id,
                                  java.lang.String s)
Sets the value for the highest possible current for the component
Parameters:
id - the object identifier
v - the new value

changePolarity

public boolean changePolarity(int id)
Changes the polarity of an element
Parameters:
id - the object identifier

setLabel

public boolean setLabel(int id,
                        java.lang.String l)
Changes the label of an element
Parameters:
id - the object identifier
l - the new label

setValueVisible

public boolean setValueVisible(int id,
                               boolean status)
Changes the visibility of an element's value or function
Parameters:
id - the object identifier
status - the value is visible if status = true

setImageVisible

public boolean setImageVisible(int id,
                               boolean status)
Changes the visibility of the element's default image
Parameters:
id - the object identifier
status - the default image is visible if status = true

setImage

public boolean setImage(int id,
                        java.lang.String gifname)
Changes the element's default image. If gifname is empty then the default image is not visible.
Parameters:
id - the object identifier
gifname - the name of the image new gif file

setFormat

public boolean setFormat(int id,
                         java.lang.String fstr)
Change the numeric format of an element. Use the C-style printf formatting (e.g. "%6.2g")
Parameters:
id - the object identifier
fstr - the format string

setFont

public boolean setFont(int id,
                       java.lang.String family,
                       int style,
                       int size)
Change the font style of an element
Parameters:
id - the object identifier
family - The font family: Helvetica, Times.
style - The style: 0=plain, 1=bold.
size - The size of the font.

setRCTo

public boolean setRCTo(int id,
                       int r,
                       int c,
                       java.lang.String to)
Move an element to row "R", column "C", direction "to" horizontal ("h") or vertical ("h")
Parameters:
id - the object identifier
r - row
c - column
to - direction

removeObject

public boolean removeObject(int id)