package lorenz_v01; //import java.io.*; //import java.math.* ; import java.awt.* ; //import java.awt.event.* ; //import java.applet.* ; class LorenzWheelCup extends Object { LorenzWheel myWheel ; int cupNum ; double gallonsInCup ; //gallons double holeOutFlowGallons ; //gallons double spoutFlowGallons ; //gallons double spoutFlowGallonsAccepted ; //gallons double aboveCupFlowGallons ; //gallons double aboveCupFlowGallonsAccepted ; //gallons int cupHeight ; int cupWidth ; double cupDegree ; // degrees relative to the 12:00 position on the wheel Point cupLocation ; public LorenzWheelCup(LorenzWheel aWheel, int aCupNum ) { //System.out.println("I: "+Thread.currentThread()+" LorenzWheelCup.LorenzWheelCup() called. cupNum="+aCupNum); myWheel = aWheel ; cupNum = aCupNum ; gallonsInCup = 0.0d ; cupDegree = myWheel.initialOffsetDegrees + 360.0d*(double)cupNum/(double)myWheel.numberOfCups ; cupLocation = new Point(); setCupLocation(); setCupDisplayParameters(); } // public int addCup(aNumCups int) { // add aNUmCups to cupNum and boundry check it. // aNumCups = aNumCups % myWheel.numberOfCups ; // return ( (myWheel.numberOfCups + cupNum + aNumCups) % myWheel.numberOfCups ; // } synchronized public void setCupDisplayParameters() { // initializes the cups for diaplay //System.out.println("I: "+Thread.currentThread()+" LorenzWheelCup.setCupDisplayParameters() called. cupNum="+cupNum); cupHeight = myWheel.diameter/6 ; cupWidth = (int) ( (double)myWheel.diameter / 2.0d * (double)(Math.sin(2.0d*Math.PI*myWheel.cupTopOpeningDegrees/360.0d))); } synchronized public void setCupLocation() { // initializes the cups for diaplay //System.out.println("I: "+Thread.currentThread()+" LorenzWheelCup.setCupLocation() called. cupNum="+cupNum); cupLocation.x = (myWheel.diameter/2+myWheel.drawBorder) +(int)(Math.sin(2.0d*Math.PI*cupDegree/360.0d)/2.0d*(double)myWheel.diameter); cupLocation.y = (myWheel.diameter/2+myWheel.drawBorder) -(int)(Math.cos(2.0d*Math.PI*cupDegree/360.0d)/2.0d*(double)myWheel.diameter); } public Point getCupLocation() { return (cupLocation) ; } public double getCupDegree() { return cupDegree ; // return the current degree position relative to the top center of the wheel } public double getMass() { return gallonsInCup*myWheel.waterDensity ; // return the mass of wwater in the cup } public double getPctFull() { return gallonsInCup/myWheel.gallonsInCupMax*100.0d ; } synchronized public void drawCup(Graphics g) { //System.out.println("I: "+Thread.currentThread()+" LorenzWheelCup.drawCup() called. cupNum="+cupNum+" cupLocation="+cupLocation+" cupWidth="+cupWidth+" cupHeight="+cupHeight+"="); if ( cupNum == 0 ) { g.setColor(Color.green); } else if ( cupNum == myWheel.numberOfCups/2 ) { g.setColor(Color.red); } else { g.setColor(Color.blue); } g.drawRect((cupLocation.x-cupWidth/2),cupLocation.y,cupWidth,cupHeight); int fillHeight = (int)((double)cupHeight*gallonsInCup/myWheel.gallonsInCupMax); g.fillRect((cupLocation.x-cupWidth/2),cupLocation.y+cupHeight-fillHeight,cupWidth,fillHeight); g.setColor(Color.black); g.fillOval((cupLocation.x)-2,cupLocation.y-2,4,4); if ( gallonsInCup > 0.0d ) { // draw water flowing out of it... int dummy = myWheel.drawWaterImage(g, cupLocation.x-3, cupLocation.y+cupHeight, myWheel.saveSpoutCycle) ; } } synchronized public void moveCupDegree(double amount) { //System.out.println("I: "+Thread.currentThread()+" LorenzWheelCup.moveCupDegree() called. "); cupDegree = cupDegree+amount ; if (cupDegree > 360.0d) { cupDegree = cupDegree - 360.0d ; } if (cupDegree < 0.0d) { cupDegree = cupDegree + 360.0d ; } if ( cupDegree < 0.0d || cupDegree > 360.0d ) { cupDegree = cupDegree-amount ; // set it to the old degree //System.out.println("E: Cup.MovecupDegree: cupDegree is not btw 0 and 360 :"+cupDegree); } setCupLocation(); } synchronized public boolean catchesStream(Point aLocation) { //System.out.println("I: "+Thread.currentThread()+" LorenzWheelCup.catchesStream() called. "); if (cupLocation.y > aLocation.y // remember y axis is upside down! && cupLocation.x-cupWidth/2 <= aLocation.x && cupLocation.x+cupWidth/2 >= aLocation.x ) { return true ; } else { return false ; } } synchronized public void zeroStepCounters() { //spoutFlowGallons = 0.0d; //spoutFlowGallonsAccepted = 0.0d; aboveCupFlowGallons = 0.0d; aboveCupFlowGallonsAccepted = 0.0d; holeOutFlowGallons = 0.0d; } synchronized public void addSpoutFlow(int milliSecs) { // check for new water in from spout if (cupDegree < myWheel.cupTopOpeningDegrees/2.0d || (360.0d-cupDegree) < myWheel.cupTopOpeningDegrees/2.0d ) { spoutFlowGallons = myWheel.spoutFlowGallons ;// ms/(ms/s)*(g/hr)/(s/hr) double spillage = getOverflowAmount(spoutFlowGallons); spoutFlowGallonsAccepted = spoutFlowGallons - spillage ; // put any amount not placed in the cup into the total as spillage myWheel.currentStepTotalOutFlowGallons += spillage ; } else { spoutFlowGallons = 0.0d; spoutFlowGallonsAccepted = 0.0d; } } synchronized public void removeHoleFlowAmount(int milliSecs) { if ( gallonsInCup <= 0.0d ) { // Check that we don't let more out than is actually there! holeOutFlowGallons = 0.0d ; gallonsInCup = 0.0d ; } else { // Always let water out of the hole (assume for now that it does not go into the cup below it. holeOutFlowGallons = (double)milliSecs/1000.0d * myWheel.cupHoleOutFlowRate/3600.0d;//ms/(ms/s)*(g/hr)/(s/hr) if (gallonsInCup < holeOutFlowGallons ) { // Check that we don't let more out than is actually there! holeOutFlowGallons = gallonsInCup ; } // Cycle through the cups (if fillsBelow) [ I just need to check 3 cups!] int someCupBelow ; int numCupsToCheck = (int)(Math.abs(180.0d - cupDegree)/180.0d*(int)myWheel.numberOfCups/2.0d) ; double amountDispersed = 0; someCupBelow = cupNum ; for ( int i=0 ; i < numCupsToCheck ; i++ ) { if (cupDegree <= 180) {someCupBelow += 1 ; } else {someCupBelow -= 1 ; } if (someCupBelow >= myWheel.numberOfCups) { someCupBelow = 0 ; } else if (someCupBelow < 0 ) { someCupBelow = myWheel.numberOfCups -1; } // Add the outflow to some other cup? Otherwise it goes into the total outflow from the wheel double spillage ; //System.out.println("D: debug"+someCupBelow); if ( myWheel.fillsBelow && myWheel.wheelCups[someCupBelow].catchesStream(cupLocation) ) { spillage = myWheel.wheelCups[someCupBelow].getOverflowAmount(holeOutFlowGallons) ; myWheel.wheelCups[someCupBelow].aboveCupFlowGallons =holeOutFlowGallons ; myWheel.wheelCups[someCupBelow].aboveCupFlowGallonsAccepted=holeOutFlowGallons - spillage ; myWheel.currentStepTotalOutFlowGallons += spillage ; amountDispersed = holeOutFlowGallons ; } } myWheel.currentStepTotalOutFlowGallons += holeOutFlowGallons - amountDispersed ; } } synchronized public void settleGallonsBalance( ) { gallonsInCup = gallonsInCup + spoutFlowGallonsAccepted + aboveCupFlowGallonsAccepted - holeOutFlowGallons ; if (gallonsInCup < 0.0d ) {gallonsInCup = 0.0d ; } if (gallonsInCup > myWheel.gallonsInCupMax ) { myWheel.currentStepTotalOutFlowGallons += gallonsInCup - myWheel.gallonsInCupMax ; // spillage gallonsInCup = myWheel.gallonsInCupMax ; } } synchronized public double getOverflowAmount( double nGallons ) { //System.out.println("I: "+Thread.currentThread()+" LorenzWheelCup.addWater() called. "); double newGallonsInCup = (gallonsInCup + nGallons ) ; if (newGallonsInCup > myWheel.gallonsInCupMax ) {return (newGallonsInCup - myWheel.gallonsInCupMax) ; } else {return (0.0d); } } }