From e76417b62e058d5f7a4e513db5e6e97236c72582 Mon Sep 17 00:00:00 2001 From: Bill Kuker Date: Mon, 13 Apr 2009 01:52:23 +0000 Subject: [PATCH] Added extrudedGrain superclass --- .../motorsim/grain/CoredCylindricalGrain.java | 80 ++++++++----------- .../motorsim/grain/ExtrudedGrain.java | 58 ++++++++++++++ .../motorsim/grain/RodAndTubeGrain.java | 45 ++++++++--- 3 files changed, 123 insertions(+), 60 deletions(-) create mode 100644 src/com/billkuker/rocketry/motorsim/grain/ExtrudedGrain.java diff --git a/src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java b/src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java index 9ba8f97..e7fdbf4 100644 --- a/src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java +++ b/src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java @@ -12,26 +12,29 @@ import javax.measure.unit.SI; import org.jscience.physics.amount.Amount; +import sun.reflect.ReflectionFactory.GetReflectionFactoryAction; + import com.billkuker.rocketry.motorsim.Grain; import com.billkuker.rocketry.motorsim.MotorPart; +import com.billkuker.rocketry.motorsim.visual.Editor; +import com.billkuker.rocketry.motorsim.visual.GrainPanel; -public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart.Validating { +public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Validating { - private Amount length, oD, iD; - private boolean outerSurfaceInhibited = true, innerSurfaceInhibited = false, endSurfaceInhibited = false; + private Amount oD, iD; + private boolean outerSurfaceInhibited = true, innerSurfaceInhibited = false; public CoredCylindricalGrain() { - length = Amount.valueOf(100, SI.MILLIMETER); + oD = Amount.valueOf(30, SI.MILLIMETER); iD = Amount.valueOf(10, SI.MILLIMETER); } - + @Deprecated public void inhibit(boolean in, boolean out, boolean end){ outerSurfaceInhibited = out; innerSurfaceInhibited = in; - endSurfaceInhibited = end; } @Override @@ -39,10 +42,7 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart Amount zero = Amount.valueOf(0, SI.MILLIMETER); //Calculated regressed length - Amount cLength = length; - if ( !endSurfaceInhibited ){ - cLength = cLength.minus(regression.times(2)); - } + Amount cLength = regressedLength(regression); //Calculate regressed iD Amount cID = iD; @@ -69,7 +69,7 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart Amount ends = (cOD.divide(2).pow(2).times(Math.PI)).minus(cID.divide(2).pow(2).times(Math.PI)).times(2).to(SI.SQUARE_METRE); - Amount total = inner.times(innerSurfaceInhibited?0:1).plus(outer.times(outerSurfaceInhibited?0:1)).plus(ends.times(endSurfaceInhibited?0:1)); + Amount total = inner.times(innerSurfaceInhibited?0:1).plus(outer.times(outerSurfaceInhibited?0:1)).plus(ends.times(numberOfBurningEnds())); return total; } @@ -79,10 +79,7 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart Amount zero = Amount.valueOf(0, SI.MILLIMETER); //Calculated regressed length - Amount cLength = length; - if ( !endSurfaceInhibited ){ - cLength = cLength.minus(regression.times(2)); - } + Amount cLength = regressedLength(regression); //Calculate regressed iD Amount cID = iD; @@ -109,13 +106,6 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart return end.times(cLength).to(SI.CUBIC_METRE); } - public void setLength(Amount length) throws PropertyVetoException { - fireVetoableChange("length", this.length, length); - Amount old = this.length; - this.length = length; - firePropertyChange("length", old, length); - } - public void setOD(Amount od) throws PropertyVetoException { fireVetoableChange("od", this.oD, od); Amount old = this.oD; @@ -135,20 +125,20 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart throw new ValidationException(this, "Invalid iD"); if ( oD.equals(Amount.ZERO) ) throw new ValidationException(this, "Invalid oD"); - if ( length.equals(Amount.ZERO) ) + if ( getLength().equals(Amount.ZERO) ) throw new ValidationException(this, "Invalid Length"); if ( iD.isGreaterThan(oD) ) throw new ValidationException(this, "iD > oD"); - if ( innerSurfaceInhibited && outerSurfaceInhibited && endSurfaceInhibited ) + if ( innerSurfaceInhibited && outerSurfaceInhibited ) throw new ValidationException(this, "No exposed grain surface"); } @Override public Amount webThickness() { - if ( innerSurfaceInhibited && outerSurfaceInhibited && endSurfaceInhibited ){ - return oD; + if ( innerSurfaceInhibited && outerSurfaceInhibited ){ + return oD; //TODO gotta move this to the end } Amount radial = null; @@ -159,8 +149,8 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart Amount axial = null; - if ( !endSurfaceInhibited ) - axial = length.divide(2); + if ( numberOfBurningEnds() != 0 ) + axial = getLength().divide(numberOfBurningEnds()); if ( axial == null ) return radial; @@ -171,10 +161,6 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart return axial; } - public Amount getLength() { - return length; - } - public Amount getOD() { return oD; } @@ -206,18 +192,24 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart double rmm = regression.doubleValue(SI.MILLIMETER); double oDmm = oD.doubleValue(SI.MILLIMETER); double iDmm = iD.doubleValue(SI.MILLIMETER); - double lmm = length.doubleValue(SI.MILLIMETER); + double lmm = regressedLength(regression).doubleValue(SI.MILLIMETER); + double length = getLength().doubleValue(SI.MILLIMETER); if ( !outerSurfaceInhibited ) oDmm -= 2.0 * rmm; if ( !innerSurfaceInhibited ) iDmm += 2.0 * rmm; - if ( !endSurfaceInhibited ) - lmm -= 2.0 * rmm; java.awt.geom.Area a = new java.awt.geom.Area(); - a.add( new java.awt.geom.Area(new Rectangle2D.Double(-oDmm/2,-lmm/2,oDmm, lmm))); - a.subtract( new java.awt.geom.Area(new Rectangle2D.Double(-iDmm/2,-lmm/2,iDmm, lmm))); + + double top = -lmm/2; + if ( isForeEndInhibited() && !isAftEndInhibited() ) + top = -length/2; + else if ( isAftEndInhibited() && !isForeEndInhibited() ) + top = length-lmm; + + a.add( new java.awt.geom.Area(new Rectangle2D.Double(-oDmm/2,top,oDmm, lmm))); + a.subtract( new java.awt.geom.Area(new Rectangle2D.Double(-iDmm/2,-length/2,iDmm, length))); return a; } @@ -248,18 +240,12 @@ public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart firePropertyChange("innerSurfaceInhibited", old, innerSurfaceInhibited); } - - public boolean isEndSurfaceInhibited() { - return endSurfaceInhibited; + public static void main(String args[]) throws Exception { + CoredCylindricalGrain e = new CoredCylindricalGrain(); + new Editor(e).show(); + new GrainPanel(e).show(); } - - public void setEndSurfaceInhibited(boolean endSurfaceInhibited) throws PropertyVetoException { - fireVetoableChange("endSurfaceInhibited", this.endSurfaceInhibited, endSurfaceInhibited); - boolean old = this.endSurfaceInhibited; - this.endSurfaceInhibited = endSurfaceInhibited; - firePropertyChange("endSurfaceInhibited", old, endSurfaceInhibited); - } } diff --git a/src/com/billkuker/rocketry/motorsim/grain/ExtrudedGrain.java b/src/com/billkuker/rocketry/motorsim/grain/ExtrudedGrain.java new file mode 100644 index 0000000..81b0563 --- /dev/null +++ b/src/com/billkuker/rocketry/motorsim/grain/ExtrudedGrain.java @@ -0,0 +1,58 @@ +package com.billkuker.rocketry.motorsim.grain; + +import java.beans.PropertyVetoException; + +import javax.measure.quantity.Length; +import javax.measure.unit.SI; + +import org.jscience.physics.amount.Amount; + +import com.billkuker.rocketry.motorsim.Grain; +import com.billkuker.rocketry.motorsim.MotorPart; + +public abstract class ExtrudedGrain extends MotorPart implements Grain { + private boolean foreEndInhibited = false; + private boolean aftEndInhibited = false; + private Amount length = Amount.valueOf(100, SI.MILLIMETER); + + protected int numberOfBurningEnds(){ + return (foreEndInhibited?0:1) + (aftEndInhibited?0:1); + } + + protected Amount regressedLength(Amount regression){ + return length.minus(regression.times(numberOfBurningEnds())); + } + + public boolean isForeEndInhibited() { + return foreEndInhibited; + } + + public void setForeEndInhibited(boolean foreEndInhibited)throws PropertyVetoException { + fireVetoableChange("foreEndInhibited", this.foreEndInhibited, foreEndInhibited); + boolean old = this.foreEndInhibited; + this.foreEndInhibited = foreEndInhibited; + firePropertyChange("foreEndInhibited", old, foreEndInhibited); + } + + public boolean isAftEndInhibited() { + return aftEndInhibited; + } + + public void setAftEndInhibited(boolean aftEndInhibited) throws PropertyVetoException { + fireVetoableChange("aftEndInhibited", this.aftEndInhibited, aftEndInhibited); + boolean old = this.aftEndInhibited; + this.aftEndInhibited = aftEndInhibited; + firePropertyChange("aftEndInhibited", old, aftEndInhibited); + } + + public Amount getLength() { + return length; + } + + public void setLength(Amount length) throws PropertyVetoException { + fireVetoableChange("length", this.length, length); + Amount old = this.length; + this.length = length; + firePropertyChange("length", old, length); + } +} diff --git a/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java b/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java index 2ae00f4..bf35bb8 100644 --- a/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java +++ b/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java @@ -8,6 +8,8 @@ import javax.measure.unit.SI; import org.jscience.physics.amount.Amount; import com.billkuker.rocketry.motorsim.Grain; +import com.billkuker.rocketry.motorsim.visual.Editor; +import com.billkuker.rocketry.motorsim.visual.GrainPanel; public class RodAndTubeGrain extends CompoundGrain { CoredCylindricalGrain rod, tube; @@ -19,14 +21,15 @@ public class RodAndTubeGrain extends CompoundGrain { rod.setID(Amount.valueOf(0, SI.MILLIMETER)); rod.setOD(Amount.valueOf(10, SI.MILLIMETER)); rod.setOuterSurfaceInhibited(false); - rod.setEndSurfaceInhibited(true); + rod.setForeEndInhibited(true); + rod.setAftEndInhibited(true); tube = new CoredCylindricalGrain(); tube.setInnerSurfaceInhibited(false); tube.setID(Amount.valueOf(20, SI.MILLIMETER)); tube.setOD(Amount.valueOf(30, SI.MILLIMETER)); - tube.setOuterSurfaceInhibited(true); - tube.setEndSurfaceInhibited(true); + tube.setForeEndInhibited(true); + tube.setAftEndInhibited(true); } catch ( PropertyVetoException v ){ v.printStackTrace(); //I know these values are OK @@ -60,16 +63,6 @@ public class RodAndTubeGrain extends CompoundGrain { tube.setOD(od); } - public boolean isEndSurfaceInhibited() { - return rod.isEndSurfaceInhibited(); - } - - public void setEndSurfaceInhibited(boolean endSurfaceInhibited) - throws PropertyVetoException { - rod.setEndSurfaceInhibited(endSurfaceInhibited); - tube.setEndSurfaceInhibited(endSurfaceInhibited); - } - public Amount getLength() { return rod.getLength(); } @@ -79,4 +72,30 @@ public class RodAndTubeGrain extends CompoundGrain { tube.setLength(length); } + public boolean isAftEndInhibited() { + return rod.isAftEndInhibited(); + } + + public boolean isForeEndInhibited() { + return rod.isForeEndInhibited(); + } + + public void setAftEndInhibited(boolean aftEndInhibited) + throws PropertyVetoException { + rod.setAftEndInhibited(aftEndInhibited); + tube.setAftEndInhibited(aftEndInhibited); + } + + public void setForeEndInhibited(boolean foreEndInhibited) + throws PropertyVetoException { + rod.setForeEndInhibited(foreEndInhibited); + tube.setForeEndInhibited(foreEndInhibited); + } + + + public static void main(String args[]) throws Exception { + Grain g = new RodAndTubeGrain(); + new Editor(g).show(); + new GrainPanel(g).show(); + } } -- 2.47.2