\r
import org.jscience.physics.amount.Amount;\r
\r
+import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;\r
+\r
import com.billkuker.rocketry.motorsim.Grain;\r
import com.billkuker.rocketry.motorsim.MotorPart;\r
+import com.billkuker.rocketry.motorsim.visual.Editor;\r
+import com.billkuker.rocketry.motorsim.visual.GrainPanel;\r
\r
\r
-public class CoredCylindricalGrain extends MotorPart implements Grain, MotorPart.Validating {\r
+public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Validating {\r
\r
- private Amount<Length> length, oD, iD;\r
- private boolean outerSurfaceInhibited = true, innerSurfaceInhibited = false, endSurfaceInhibited = false;\r
+ private Amount<Length> oD, iD;\r
+ private boolean outerSurfaceInhibited = true, innerSurfaceInhibited = false;\r
\r
public CoredCylindricalGrain() {\r
- length = Amount.valueOf(100, SI.MILLIMETER);\r
+\r
oD = Amount.valueOf(30, SI.MILLIMETER);\r
iD = Amount.valueOf(10, SI.MILLIMETER);\r
}\r
\r
- \r
+ @Deprecated\r
public void inhibit(boolean in, boolean out, boolean end){\r
outerSurfaceInhibited = out;\r
innerSurfaceInhibited = in;\r
- endSurfaceInhibited = end;\r
}\r
\r
@Override\r
Amount<Length> zero = Amount.valueOf(0, SI.MILLIMETER);\r
\r
//Calculated regressed length\r
- Amount<Length> cLength = length;\r
- if ( !endSurfaceInhibited ){\r
- cLength = cLength.minus(regression.times(2));\r
- }\r
+ Amount<Length> cLength = regressedLength(regression);\r
\r
//Calculate regressed iD\r
Amount<Length> cID = iD;\r
\r
Amount<Area> ends = (cOD.divide(2).pow(2).times(Math.PI)).minus(cID.divide(2).pow(2).times(Math.PI)).times(2).to(SI.SQUARE_METRE);\r
\r
- Amount<Area> total = inner.times(innerSurfaceInhibited?0:1).plus(outer.times(outerSurfaceInhibited?0:1)).plus(ends.times(endSurfaceInhibited?0:1));\r
+ Amount<Area> total = inner.times(innerSurfaceInhibited?0:1).plus(outer.times(outerSurfaceInhibited?0:1)).plus(ends.times(numberOfBurningEnds()));\r
\r
return total;\r
}\r
Amount<Length> zero = Amount.valueOf(0, SI.MILLIMETER);\r
\r
//Calculated regressed length\r
- Amount<Length> cLength = length;\r
- if ( !endSurfaceInhibited ){\r
- cLength = cLength.minus(regression.times(2));\r
- }\r
+ Amount<Length> cLength = regressedLength(regression);\r
\r
//Calculate regressed iD\r
Amount<Length> cID = iD;\r
return end.times(cLength).to(SI.CUBIC_METRE);\r
}\r
\r
- public void setLength(Amount<Length> length) throws PropertyVetoException {\r
- fireVetoableChange("length", this.length, length);\r
- Amount<Length> old = this.length;\r
- this.length = length;\r
- firePropertyChange("length", old, length);\r
- }\r
-\r
public void setOD(Amount<Length> od) throws PropertyVetoException {\r
fireVetoableChange("od", this.oD, od);\r
Amount<Length> old = this.oD;\r
throw new ValidationException(this, "Invalid iD");\r
if ( oD.equals(Amount.ZERO) )\r
throw new ValidationException(this, "Invalid oD");\r
- if ( length.equals(Amount.ZERO) )\r
+ if ( getLength().equals(Amount.ZERO) )\r
throw new ValidationException(this, "Invalid Length");\r
if ( iD.isGreaterThan(oD) )\r
throw new ValidationException(this, "iD > oD");\r
\r
- if ( innerSurfaceInhibited && outerSurfaceInhibited && endSurfaceInhibited )\r
+ if ( innerSurfaceInhibited && outerSurfaceInhibited )\r
throw new ValidationException(this, "No exposed grain surface");\r
\r
}\r
\r
@Override\r
public Amount<Length> webThickness() {\r
- if ( innerSurfaceInhibited && outerSurfaceInhibited && endSurfaceInhibited ){\r
- return oD;\r
+ if ( innerSurfaceInhibited && outerSurfaceInhibited ){\r
+ return oD; //TODO gotta move this to the end\r
}\r
\r
Amount<Length> radial = null;\r
\r
Amount<Length> axial = null;\r
\r
- if ( !endSurfaceInhibited )\r
- axial = length.divide(2);\r
+ if ( numberOfBurningEnds() != 0 )\r
+ axial = getLength().divide(numberOfBurningEnds());\r
\r
if ( axial == null )\r
return radial;\r
return axial;\r
}\r
\r
- public Amount<Length> getLength() {\r
- return length;\r
- }\r
-\r
public Amount<Length> getOD() {\r
return oD;\r
}\r
double rmm = regression.doubleValue(SI.MILLIMETER);\r
double oDmm = oD.doubleValue(SI.MILLIMETER);\r
double iDmm = iD.doubleValue(SI.MILLIMETER);\r
- double lmm = length.doubleValue(SI.MILLIMETER);\r
+ double lmm = regressedLength(regression).doubleValue(SI.MILLIMETER);\r
+ double length = getLength().doubleValue(SI.MILLIMETER);\r
\r
if ( !outerSurfaceInhibited )\r
oDmm -= 2.0 * rmm;\r
if ( !innerSurfaceInhibited )\r
iDmm += 2.0 * rmm;\r
- if ( !endSurfaceInhibited )\r
- lmm -= 2.0 * rmm;\r
\r
java.awt.geom.Area a = new java.awt.geom.Area();\r
- a.add( new java.awt.geom.Area(new Rectangle2D.Double(-oDmm/2,-lmm/2,oDmm, lmm)));\r
- a.subtract( new java.awt.geom.Area(new Rectangle2D.Double(-iDmm/2,-lmm/2,iDmm, lmm)));\r
+ \r
+ double top = -lmm/2;\r
+ if ( isForeEndInhibited() && !isAftEndInhibited() )\r
+ top = -length/2;\r
+ else if ( isAftEndInhibited() && !isForeEndInhibited() )\r
+ top = length-lmm;\r
+ \r
+ a.add( new java.awt.geom.Area(new Rectangle2D.Double(-oDmm/2,top,oDmm, lmm)));\r
+ a.subtract( new java.awt.geom.Area(new Rectangle2D.Double(-iDmm/2,-length/2,iDmm, length)));\r
\r
return a;\r
}\r
firePropertyChange("innerSurfaceInhibited", old, innerSurfaceInhibited);\r
}\r
\r
-\r
- public boolean isEndSurfaceInhibited() {\r
- return endSurfaceInhibited;\r
+ public static void main(String args[]) throws Exception {\r
+ CoredCylindricalGrain e = new CoredCylindricalGrain();\r
+ new Editor(e).show();\r
+ new GrainPanel(e).show();\r
}\r
\r
-\r
- public void setEndSurfaceInhibited(boolean endSurfaceInhibited) throws PropertyVetoException {\r
- fireVetoableChange("endSurfaceInhibited", this.endSurfaceInhibited, endSurfaceInhibited);\r
- boolean old = this.endSurfaceInhibited;\r
- this.endSurfaceInhibited = endSurfaceInhibited;\r
- firePropertyChange("endSurfaceInhibited", old, endSurfaceInhibited);\r
- }\r
\r
\r
}\r
--- /dev/null
+package com.billkuker.rocketry.motorsim.grain;\r
+\r
+import java.beans.PropertyVetoException;\r
+\r
+import javax.measure.quantity.Length;\r
+import javax.measure.unit.SI;\r
+\r
+import org.jscience.physics.amount.Amount;\r
+\r
+import com.billkuker.rocketry.motorsim.Grain;\r
+import com.billkuker.rocketry.motorsim.MotorPart;\r
+\r
+public abstract class ExtrudedGrain extends MotorPart implements Grain {\r
+ private boolean foreEndInhibited = false;\r
+ private boolean aftEndInhibited = false;\r
+ private Amount<Length> length = Amount.valueOf(100, SI.MILLIMETER);\r
+ \r
+ protected int numberOfBurningEnds(){\r
+ return (foreEndInhibited?0:1) + (aftEndInhibited?0:1);\r
+ }\r
+ \r
+ protected Amount<Length> regressedLength(Amount<Length> regression){\r
+ return length.minus(regression.times(numberOfBurningEnds()));\r
+ }\r
+\r
+ public boolean isForeEndInhibited() {\r
+ return foreEndInhibited;\r
+ }\r
+\r
+ public void setForeEndInhibited(boolean foreEndInhibited)throws PropertyVetoException {\r
+ fireVetoableChange("foreEndInhibited", this.foreEndInhibited, foreEndInhibited);\r
+ boolean old = this.foreEndInhibited;\r
+ this.foreEndInhibited = foreEndInhibited;\r
+ firePropertyChange("foreEndInhibited", old, foreEndInhibited);\r
+ }\r
+\r
+ public boolean isAftEndInhibited() {\r
+ return aftEndInhibited;\r
+ }\r
+\r
+ public void setAftEndInhibited(boolean aftEndInhibited) throws PropertyVetoException {\r
+ fireVetoableChange("aftEndInhibited", this.aftEndInhibited, aftEndInhibited);\r
+ boolean old = this.aftEndInhibited;\r
+ this.aftEndInhibited = aftEndInhibited;\r
+ firePropertyChange("aftEndInhibited", old, aftEndInhibited);\r
+ }\r
+\r
+ public Amount<Length> getLength() {\r
+ return length;\r
+ }\r
+\r
+ public void setLength(Amount<Length> length) throws PropertyVetoException {\r
+ fireVetoableChange("length", this.length, length);\r
+ Amount<Length> old = this.length;\r
+ this.length = length;\r
+ firePropertyChange("length", old, length);\r
+ }\r
+}\r
import org.jscience.physics.amount.Amount;\r
\r
import com.billkuker.rocketry.motorsim.Grain;\r
+import com.billkuker.rocketry.motorsim.visual.Editor;\r
+import com.billkuker.rocketry.motorsim.visual.GrainPanel;\r
\r
public class RodAndTubeGrain extends CompoundGrain {\r
CoredCylindricalGrain rod, tube;\r
rod.setID(Amount.valueOf(0, SI.MILLIMETER));\r
rod.setOD(Amount.valueOf(10, SI.MILLIMETER));\r
rod.setOuterSurfaceInhibited(false);\r
- rod.setEndSurfaceInhibited(true);\r
+ rod.setForeEndInhibited(true);\r
+ rod.setAftEndInhibited(true);\r
\r
tube = new CoredCylindricalGrain();\r
tube.setInnerSurfaceInhibited(false);\r
tube.setID(Amount.valueOf(20, SI.MILLIMETER));\r
tube.setOD(Amount.valueOf(30, SI.MILLIMETER));\r
- tube.setOuterSurfaceInhibited(true);\r
- tube.setEndSurfaceInhibited(true);\r
+ tube.setForeEndInhibited(true);\r
+ tube.setAftEndInhibited(true);\r
} catch ( PropertyVetoException v ){\r
v.printStackTrace();\r
//I know these values are OK\r
tube.setOD(od);\r
}\r
\r
- public boolean isEndSurfaceInhibited() {\r
- return rod.isEndSurfaceInhibited();\r
- }\r
-\r
- public void setEndSurfaceInhibited(boolean endSurfaceInhibited)\r
- throws PropertyVetoException {\r
- rod.setEndSurfaceInhibited(endSurfaceInhibited);\r
- tube.setEndSurfaceInhibited(endSurfaceInhibited);\r
- }\r
-\r
public Amount<Length> getLength() {\r
return rod.getLength();\r
}\r
tube.setLength(length);\r
}\r
\r
+ public boolean isAftEndInhibited() {\r
+ return rod.isAftEndInhibited();\r
+ }\r
+\r
+ public boolean isForeEndInhibited() {\r
+ return rod.isForeEndInhibited();\r
+ }\r
+\r
+ public void setAftEndInhibited(boolean aftEndInhibited)\r
+ throws PropertyVetoException {\r
+ rod.setAftEndInhibited(aftEndInhibited);\r
+ tube.setAftEndInhibited(aftEndInhibited);\r
+ }\r
+\r
+ public void setForeEndInhibited(boolean foreEndInhibited)\r
+ throws PropertyVetoException {\r
+ rod.setForeEndInhibited(foreEndInhibited);\r
+ tube.setForeEndInhibited(foreEndInhibited);\r
+ }\r
+\r
+\r
+ public static void main(String args[]) throws Exception {\r
+ Grain g = new RodAndTubeGrain();\r
+ new Editor(g).show();\r
+ new GrainPanel(g).show();\r
+ }\r
}\r