Added DEFAULT_GRAIN to grain types. When possible these should all be the same grain.
authorBill Kuker <bkuker@billkuker.com>
Wed, 15 Apr 2009 20:00:43 +0000 (20:00 +0000)
committerBill Kuker <bkuker@billkuker.com>
Wed, 15 Apr 2009 20:00:43 +0000 (20:00 +0000)
src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java
src/com/billkuker/rocketry/motorsim/grain/ExtrudedShapeGrain.java
src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java
src/com/billkuker/rocketry/motorsim/grain/RotatedShapeGrain.java

index f0d94f69b11a8c663a5e8f5861ea786926d1b3d4..78d5fbfdc4061b3babd2574201420d41164dbdc1 100644 (file)
@@ -21,9 +21,24 @@ public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Va
 \r
        private Amount<Length> oD, iD;\r
        private boolean outerSurfaceInhibited = true, innerSurfaceInhibited = false;\r
+       \r
+       public static CoredCylindricalGrain DEFAULT_GRAIN = new CoredCylindricalGrain(){\r
+               {\r
+                       try{\r
+                               setOD(Amount.valueOf(30, SI.MILLIMETER));\r
+                               setID(Amount.valueOf(10, SI.MILLIMETER));\r
+                               setLength(Amount.valueOf(70, SI.MILLIMETER));\r
+                               setInnerSurfaceInhibited(false);\r
+                               setOuterSurfaceInhibited(true);\r
+                               setForeEndInhibited(false);\r
+                               setAftEndInhibited(false);\r
+                       } catch ( Exception e ){\r
+                               throw new Error(e);\r
+                       }\r
+               }\r
+       };\r
 \r
        public CoredCylindricalGrain() {\r
-\r
                oD = Amount.valueOf(30, SI.MILLIMETER);\r
                iD = Amount.valueOf(10, SI.MILLIMETER);\r
        }\r
@@ -249,11 +264,9 @@ public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Va
        }\r
 \r
        public static void main(String args[]) throws Exception {\r
-               CoredCylindricalGrain e = new CoredCylindricalGrain();\r
+               CoredCylindricalGrain e = DEFAULT_GRAIN;\r
                new Editor(e).show();\r
                new GrainPanel(e).show();\r
        }\r
 \r
-       \r
-\r
 }\r
index ef00d4a4484adb4381cbd51aaa72dc55119ded26..0378dcbd27cb682ae07a5442e0efb8f6d53cd163 100644 (file)
@@ -19,6 +19,21 @@ import com.billkuker.rocketry.motorsim.visual.Editor;
 import com.billkuker.rocketry.motorsim.visual.GrainPanel;\r
 \r
 public class ExtrudedShapeGrain extends MotorPart implements Grain {\r
+       \r
+       public static ExtrudedShapeGrain DEFAULT_GRAIN = new ExtrudedShapeGrain(){\r
+               {\r
+                       try{\r
+                               Shape outside = new Ellipse2D.Double(0, 0, 30, 30);\r
+                               xsection.add(outside);\r
+                               xsection.inhibit(outside);\r
+                               xsection.subtract(new Ellipse2D.Double(10,10, 10, 10));\r
+                               setLength(Amount.valueOf(70, SI.MILLIMETER));\r
+                               setEndSurfaceInhibited(false);\r
+                       } catch ( Exception e ){\r
+                               throw new Error(e);\r
+                       }\r
+               }\r
+       };\r
 \r
        BurningShape xsection = new BurningShape();\r
 \r
@@ -30,33 +45,6 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
 \r
        Amount<Length> webThickness;\r
 \r
-       {\r
-               /*\r
-                * Similar test grain Shape outside = new Ellipse2D.Double(50,50,30,30);\r
-                * plus.add(outside); minus.add(new Ellipse2D.Double(50,60,10,10));\r
-                * inhibited.add(outside); length = Amount.valueOf(70, SI.MILLIMETER); /\r
-                */\r
-\r
-               /* Big c-slot */\r
-               Shape outside = new Ellipse2D.Double(0, 0, 30, 30);\r
-               xsection.add(outside);\r
-               xsection.inhibit(outside);\r
-               //xsection.subtract(new Rectangle2D.Double(13, 13, 4, 30));\r
-               xsection.subtract(new Ellipse2D.Double(10,10, 10, 10));\r
-               length = Amount.valueOf(100, SI.MILLIMETER);\r
-               /**/\r
-\r
-               /*\r
-                * Plus sign Shape outside = new Ellipse2D.Double(0,0,200,200);\r
-                * plus.add(outside); inhibited.add(outside); minus.add(new\r
-                * Rectangle2D.Double(90,40,20,120)); minus.add(new\r
-                * Rectangle2D.Double(40,90,120,20));\r
-                */\r
-\r
-               findWebThickness();\r
-\r
-       }\r
-\r
        @Override\r
        public Amount<Area> surfaceArea(Amount<Length> regression) {\r
                Amount<Area> zero = Amount.valueOf(0, Area.UNIT);\r
@@ -105,10 +93,8 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
 \r
        @Override\r
        public Amount<Length> webThickness() {\r
-               return webThickness;\r
-       }\r
-\r
-       private void findWebThickness() {\r
+               if ( webThickness != null )\r
+                       return webThickness;\r
                java.awt.geom.Area a = getCrossSection(Amount.valueOf(0, SI.MILLIMETER));\r
                Rectangle r = a.getBounds();\r
                double max = r.getWidth() < r.getHeight() ? r.getHeight() : r\r
@@ -133,6 +119,7 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
                webThickness = Amount.valueOf(guess, SI.MILLIMETER);\r
                if (webThickness.isGreaterThan(length.divide(2)))\r
                        webThickness = length.divide(2);\r
+               return webThickness;\r
        }\r
 \r
        @Override\r
@@ -157,13 +144,6 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
                }\r
                return res;\r
        }\r
-       \r
-       public static void main(String args[]) throws Exception {\r
-               ExtrudedShapeGrain e = new ExtrudedShapeGrain();\r
-               new Editor(e).show();\r
-               new GrainPanel(e).show();\r
-       }\r
-\r
 \r
        public Amount<Length> getLength() {\r
                return length;\r
@@ -187,4 +167,11 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
                firePropertyChange("endSurfaceInhibited", old, endSurfaceInhibited);\r
        }\r
 \r
+       \r
+       public static void main(String args[]) throws Exception {\r
+               ExtrudedShapeGrain e = DEFAULT_GRAIN;\r
+               new Editor(e).show();\r
+               new GrainPanel(e).show();\r
+       }\r
+\r
 }\r
index bf35bb8e17741891d19a33b8f5a9b03d7d114647..e9228ba333c2cf83e485128b7db2970fdfd00223 100644 (file)
@@ -14,27 +14,33 @@ import com.billkuker.rocketry.motorsim.visual.GrainPanel;
 public class RodAndTubeGrain extends CompoundGrain {\r
        CoredCylindricalGrain rod, tube;\r
        \r
+       public static RodAndTubeGrain DEFAULT_GRAIN = new RodAndTubeGrain(){\r
+               {\r
+                       try{\r
+                               setOd(Amount.valueOf(30, SI.MILLIMETER));\r
+                               setTubeID(Amount.valueOf(20, SI.MILLIMETER));\r
+                               setRodDiameter(Amount.valueOf(10, SI.MILLIMETER));\r
+                               setForeEndInhibited(true);\r
+                               setAftEndInhibited(true);\r
+                       } catch ( Exception e ){\r
+                               throw new Error(e);\r
+                       }\r
+               }\r
+       };\r
+       \r
        public RodAndTubeGrain() {\r
                try{\r
                        rod = new CoredCylindricalGrain();\r
-                       rod.setInnerSurfaceInhibited(true);\r
                        rod.setID(Amount.valueOf(0, SI.MILLIMETER));\r
-                       rod.setOD(Amount.valueOf(10, SI.MILLIMETER));\r
+                       rod.setInnerSurfaceInhibited(true);\r
                        rod.setOuterSurfaceInhibited(false);\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.setForeEndInhibited(true);\r
-                       tube.setAftEndInhibited(true);\r
                } catch ( PropertyVetoException v ){\r
                        v.printStackTrace();\r
                        //I know these values are OK\r
                }\r
-               \r
                add(rod);\r
                add(tube);\r
        }\r
@@ -94,7 +100,7 @@ public class RodAndTubeGrain extends CompoundGrain {
 \r
 \r
        public static void main(String args[]) throws Exception {\r
-               Grain g = new RodAndTubeGrain();\r
+               Grain g = DEFAULT_GRAIN;\r
                new Editor(g).show();\r
                new GrainPanel(g).show();\r
        }\r
index 45187f6e12d1e14986e4d10b33dab675800c38e5..30b78f2f9d326572508f568e088b523cc2fc9fbb 100644 (file)
@@ -23,6 +23,21 @@ public class RotatedShapeGrain implements Grain {
        \r
        private static Logger log = Logger.getLogger(RotatedShapeGrain.class);\r
        \r
+       public static RotatedShapeGrain DEFAULT_GRAIN = new RotatedShapeGrain(){\r
+               {\r
+                       try{\r
+                               Shape outside = new Rectangle2D.Double(0,0,15,70);\r
+                               shape.add( outside );\r
+                               shape.inhibit( outside );\r
+                               shape.subtract( new Rectangle2D.Double(0,0,5,70));\r
+                               shape.subtract(new Rectangle2D.Double(0, -10, 15, 10));\r
+                               shape.subtract(new Rectangle2D.Double(0, 70, 15, 10));\r
+                       } catch ( Exception e ){\r
+                               throw new Error(e);\r
+                       }\r
+               }\r
+       };\r
+       \r
        public enum Quality {\r
                High()\r
                        {{\r
@@ -50,15 +65,6 @@ public class RotatedShapeGrain implements Grain {
        \r
        Amount<Length> web = null;\r
        \r
-       {\r
-               Shape outside = new Rectangle2D.Double(0,0,15,100);\r
-               shape.add( outside );\r
-               shape.inhibit( outside );\r
-               shape.subtract( new Rectangle2D.Double(0,0,5,100));\r
-               shape.subtract(new Rectangle2D.Double(0, -10, 15, 10));\r
-               shape.subtract(new Rectangle2D.Double(0, 100, 15, 10));\r
-       }\r
-\r
        @Override\r
        public Area getCrossSection(Amount<Length> regression) {\r
                Area ret = new Area();\r
@@ -147,14 +153,7 @@ public class RotatedShapeGrain implements Grain {
                return web;\r
 \r
        }\r
-       \r
 \r
-       public static void main(String args[]) throws Exception {\r
-               RotatedShapeGrain e = new RotatedShapeGrain();\r
-               new Editor(e).show();\r
-               new GrainPanel(e).show();\r
-       }\r
-       \r
        private Shape square(java.awt.geom.Area a) {\r
                PathIterator i = a.getPathIterator(new AffineTransform(), quality.squareFlatteningError);\r
                GeneralPath cur = new GeneralPath();\r
@@ -249,5 +248,12 @@ public class RotatedShapeGrain implements Grain {
                return len;\r
        }\r
 \r
+       \r
 \r
+       public static void main(String args[]) throws Exception {\r
+               RotatedShapeGrain e = DEFAULT_GRAIN;\r
+               new Editor(e).show();\r
+               new GrainPanel(e).show();\r
+       }\r
+       \r
 }\r