Added gravitational acceleration and propellant mass datatypes.
authorrichardgraham <richardgraham@180e2498-e6e9-4542-8430-84ac67f01cd8>
Wed, 5 Sep 2012 05:14:10 +0000 (05:14 +0000)
committerrichardgraham <richardgraham@180e2498-e6e9-4542-8430-84ac67f01cd8>
Wed, 5 Sep 2012 05:14:10 +0000 (05:14 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@1011 180e2498-e6e9-4542-8430-84ac67f01cd8

core/resources/l10n/messages.properties
core/src/net/sf/openrocket/masscalc/BasicMassCalculator.java
core/src/net/sf/openrocket/masscalc/MassCalculator.java
core/src/net/sf/openrocket/motor/MotorInstance.java
core/src/net/sf/openrocket/motor/ThrustCurveMotor.java
core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java
core/src/net/sf/openrocket/simulation/BasicLandingStepper.java
core/src/net/sf/openrocket/simulation/FlightDataType.java
core/src/net/sf/openrocket/simulation/MassData.java
core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java

index 88f2c0197c40e2adb39b0352eccf3efb45ab061b..1b5da0edba944a488b7b3c50fae1d2345613553a 100644 (file)
@@ -1367,6 +1367,7 @@ FlightDataType.TYPE_ROLL_RATE = Roll rate
 FlightDataType.TYPE_PITCH_RATE = Pitch rate
 FlightDataType.TYPE_YAW_RATE = Yaw rate
 FlightDataType.TYPE_MASS = Mass
+FlightDataType.TYPE_PROPELLANT_MASS = Propellant mass
 FlightDataType.TYPE_LONGITUDINAL_INERTIA = Longitudinal moment of inertia
 FlightDataType.TYPE_ROTATIONAL_INERTIA = Rotational moment of inertia
 FlightDataType.TYPE_CP_LOCATION = CP location
@@ -1403,6 +1404,7 @@ FlightDataType.TYPE_COMPUTATION_TIME = Computation time
 FlightDataType.TYPE_LATITUDE = Latitude
 FlightDataType.TYPE_LONGITUDE = Longitude
 FlightDataType.TYPE_CORIOLIS_ACCELERATION = Coriolis acceleration
+FlightDataType.TYPE_GRAVITY = Gravitational acceleration
 
 ! PlotConfiguration
 PlotConfiguration.Verticalmotion = Vertical motion vs. time
index 4b5d8276f2f74ca4219c0ad9c0aaf901f8eef5fc..3fd82fdf3d18a61d488900efd6fa4339404fba46 100644 (file)
@@ -2,8 +2,10 @@ package net.sf.openrocket.masscalc;
 
 import static net.sf.openrocket.util.MathUtil.pow2;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import net.sf.openrocket.motor.Motor;
@@ -38,6 +40,7 @@ public class BasicMassCalculator extends AbstractMassCalculator {
         * Return the CG of the rocket with the specified motor status (no motors,
         * ignition, burnout).
         */
+       @Override
        public Coordinate getCG(Configuration configuration, MassCalcType type) {
                checkCache(configuration);
                calculateStageCache(configuration);
@@ -80,6 +83,7 @@ public class BasicMassCalculator extends AbstractMassCalculator {
        /**
         * Return the CG of the rocket with the provided motor configuration.
         */
+       @Override
        public Coordinate getCG(Configuration configuration, MotorInstanceConfiguration motors) {
                checkCache(configuration);
                calculateStageCache(configuration);
@@ -103,7 +107,6 @@ public class BasicMassCalculator extends AbstractMassCalculator {
                return totalCG;
        }
        
-       
        /**
         * Return the longitudinal inertia of the rocket with the specified motor instance
         * configuration.
@@ -111,6 +114,7 @@ public class BasicMassCalculator extends AbstractMassCalculator {
         * @param configuration         the current motor instance configuration
         * @return                                      the longitudinal inertia of the rocket
         */
+       @Override
        public double getLongitudinalInertia(Configuration configuration, MotorInstanceConfiguration motors) {
                checkCache(configuration);
                calculateStageCache(configuration);
@@ -154,6 +158,7 @@ public class BasicMassCalculator extends AbstractMassCalculator {
         * @param configuration         the current motor instance configuration
         * @return                                      the rotational inertia of the rocket
         */
+       @Override
        public double getRotationalInertia(Configuration configuration, MotorInstanceConfiguration motors) {
                checkCache(configuration);
                calculateStageCache(configuration);
@@ -190,8 +195,26 @@ public class BasicMassCalculator extends AbstractMassCalculator {
                return totalInertia;
        }
        
+       /**
+        * Return the total mass of the motors
+        * 
+        * @param configuration         the current motor instance configuration
+        * @return                                      the total mass of all motors
+        */
+       @Override
+       public double getPropellantMass(Configuration configuration, MotorInstanceConfiguration motors){
+               double mass = 0;
+                               
+               // add up the masses of all motors in the rocket
+               if (motors != null) {
+                       for (MotorId id : motors.getMotorIDs()) {
+                               MotorInstance motor = motors.getMotorInstance(id);                                      
+                               mass = mass + motor.getCG().weight - motor.getParentMotor().getEmptyCG().weight;
+                       }
+               }
+               return mass;
+       }
        
-
        @Override
        public Map<RocketComponent, Coordinate> getCGAnalysis(Configuration configuration, MassCalcType type) {
                checkCache(configuration);
index 003650e11603ae6bbc5ae8b88ce82785dfa61557..5e657f7ab6006909aa342aa0fd63981c08c1ef74 100644 (file)
@@ -70,6 +70,14 @@ public interface MassCalculator extends Monitorable {
         */
        public double getRotationalInertia(Configuration configuration, MotorInstanceConfiguration motors);
        
+       /**
+        * Return the total mass of the motors
+        * 
+        * @param motors                        the motor configuration
+        * @param configuration         the current motor instance configuration
+        * @return                                      the total mass of all motors
+        */
+       public double getPropellantMass(Configuration configuration, MotorInstanceConfiguration motors);        
        
        /**
         * Compute an analysis of the per-component CG's of the provided configuration.
index 6b48e3a4b4c3286ec7288914f412b9e0dab4d1e1..ab474a8e946973b6832de70101bcc9d2d6187437 100644 (file)
@@ -56,5 +56,8 @@ public interface MotorInstance extends Cloneable, Monitorable {
         * identical to this instance and can be used independently from this one.
         */
        public MotorInstance clone();
+
+
+       public Motor getParentMotor();
        
 }
index 0781c7c88ed5cbf499cc18d58eda15355b408ced..e795c82308f9197fb241dd01a6fdd290e40a1594 100644 (file)
@@ -424,6 +424,7 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                
                private final double unitRotationalInertia;
                private final double unitLongitudinalInertia;
+               private final Motor parentMotor;
                
                private int modID = 0;
                
@@ -437,6 +438,12 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                        stepCG = cg[0];
                        unitRotationalInertia = Inertia.filledCylinderRotational(getDiameter() / 2);
                        unitLongitudinalInertia = Inertia.filledCylinderLongitudinal(getDiameter() / 2, getLength());
+                       parentMotor = ThrustCurveMotor.this;
+               }
+               
+               @Override
+               public Motor getParentMotor(){
+                       return parentMotor;
                }
                
                @Override
index 85be91201282613b629491f40c9f82eb53e1ca3d..0aab853ac46fa485088747145a25d485eaf4cc83 100644 (file)
@@ -115,7 +115,7 @@ public abstract class AbstractSimulationStepper implements SimulationStepper {
        protected MassData calculateMassData(SimulationStatus status) throws SimulationException {
                MassData mass;
                Coordinate cg;
-               double longitudinalInertia, rotationalInertia;
+               double longitudinalInertia, rotationalInertia, propellantMass;
                
                // Call pre-listener
                mass = SimulationListenerHelper.firePreMassCalculation(status);
@@ -127,7 +127,8 @@ public abstract class AbstractSimulationStepper implements SimulationStepper {
                cg = calc.getCG(status.getConfiguration(), status.getMotorConfiguration());
                longitudinalInertia = calc.getLongitudinalInertia(status.getConfiguration(), status.getMotorConfiguration());
                rotationalInertia = calc.getRotationalInertia(status.getConfiguration(), status.getMotorConfiguration());
-               mass = new MassData(cg, longitudinalInertia, rotationalInertia);
+               propellantMass = calc.getPropellantMass(status.getConfiguration(), status.getMotorConfiguration());
+               mass = new MassData(cg, longitudinalInertia, rotationalInertia, propellantMass);
                
                // Call post-listener
                mass = SimulationListenerHelper.firePostMassCalculation(status, mass);
@@ -135,6 +136,7 @@ public abstract class AbstractSimulationStepper implements SimulationStepper {
                checkNaN(mass.getCG());
                checkNaN(mass.getLongitudinalInertia());
                checkNaN(mass.getRotationalInertia());
+               checkNaN(mass.getPropellantMass());
                
                return mass;
        }
index dc67e85375c60cdc8c2e15d1937f433c8db999ec..0d9c3954b5bff15ee04f4dcbbe4a8f9d74f628ff 100644 (file)
@@ -109,6 +109,8 @@ public class BasicLandingStepper extends AbstractSimulationStepper {
 
                data.setValue(FlightDataType.TYPE_LATITUDE, status.getRocketWorldPosition().getLatitudeRad());
                data.setValue(FlightDataType.TYPE_LONGITUDE, status.getRocketWorldPosition().getLongitudeRad());
+               data.setValue(FlightDataType.TYPE_GRAVITY, gravity);
+               
                if (status.getSimulationConditions().getGeodeticComputation() != GeodeticComputationStrategy.FLAT) {
                        data.setValue(FlightDataType.TYPE_CORIOLIS_ACCELERATION, coriolisAcceleration.length());
                }
@@ -121,6 +123,7 @@ public class BasicLandingStepper extends AbstractSimulationStepper {
                data.setValue(FlightDataType.TYPE_MACH_NUMBER, mach);
                
                data.setValue(FlightDataType.TYPE_MASS, mass);
+               data.setValue(FlightDataType.TYPE_PROPELLANT_MASS, 0.0); // Is this a reasonable assumption? Probably.
                
                data.setValue(FlightDataType.TYPE_THRUST_FORCE, 0);
                data.setValue(FlightDataType.TYPE_DRAG_FORCE, dragForce);
index 3ad7d633e7711eeb461c86ffdf98602ab331dcbd..251d85d6c9b2b6e47a5fc8b82905660f55d5b13e 100644 (file)
@@ -71,6 +71,9 @@ public class FlightDataType implements Comparable<FlightDataType> {
        //// Longitude
        public static final FlightDataType TYPE_LONGITUDE = newType(trans.get("FlightDataType.TYPE_LONGITUDE"), "\u03bb", UnitGroup.UNITS_ANGLE, 37);
        
+       //// Gravity
+       public static final FlightDataType TYPE_GRAVITY = newType(trans.get("FlightDataType.TYPE_GRAVITY"), "g", UnitGroup.UNITS_ACCELERATION, 38);
+       
        //// Angular motion
        //// Angle of attack
        public static final FlightDataType TYPE_AOA = newType(trans.get("FlightDataType.TYPE_AOA"), "\u03b1", UnitGroup.UNITS_ANGLE, 40);
@@ -85,16 +88,18 @@ public class FlightDataType implements Comparable<FlightDataType> {
        //// Stability information
        //// Mass
        public static final FlightDataType TYPE_MASS = newType(trans.get("FlightDataType.TYPE_MASS"), "m", UnitGroup.UNITS_MASS, 50);
+       //// Propellant mass
+       public static final FlightDataType TYPE_PROPELLANT_MASS = newType(trans.get("FlightDataType.TYPE_PROPELLANT_MASS"), "mp", UnitGroup.UNITS_MASS, 51);
        //// Longitudinal moment of inertia
-       public static final FlightDataType TYPE_LONGITUDINAL_INERTIA = newType(trans.get("FlightDataType.TYPE_LONGITUDINAL_INERTIA"), "Il", UnitGroup.UNITS_INERTIA, 51);
+       public static final FlightDataType TYPE_LONGITUDINAL_INERTIA = newType(trans.get("FlightDataType.TYPE_LONGITUDINAL_INERTIA"), "Il", UnitGroup.UNITS_INERTIA, 52);
        //// Rotational moment of inertia
-       public static final FlightDataType TYPE_ROTATIONAL_INERTIA = newType(trans.get("FlightDataType.TYPE_ROTATIONAL_INERTIA"), "Ir", UnitGroup.UNITS_INERTIA, 52);
+       public static final FlightDataType TYPE_ROTATIONAL_INERTIA = newType(trans.get("FlightDataType.TYPE_ROTATIONAL_INERTIA"), "Ir", UnitGroup.UNITS_INERTIA, 53);
        //// CP location
-       public static final FlightDataType TYPE_CP_LOCATION = newType(trans.get("FlightDataType.TYPE_CP_LOCATION"), "Cp", UnitGroup.UNITS_LENGTH, 53);
+       public static final FlightDataType TYPE_CP_LOCATION = newType(trans.get("FlightDataType.TYPE_CP_LOCATION"), "Cp", UnitGroup.UNITS_LENGTH, 54);
        //// CG location
-       public static final FlightDataType TYPE_CG_LOCATION = newType(trans.get("FlightDataType.TYPE_CG_LOCATION"), "Cg", UnitGroup.UNITS_LENGTH, 54);
+       public static final FlightDataType TYPE_CG_LOCATION = newType(trans.get("FlightDataType.TYPE_CG_LOCATION"), "Cg", UnitGroup.UNITS_LENGTH, 55);
        //// Stability margin calibers
-       public static final FlightDataType TYPE_STABILITY = newType(trans.get("FlightDataType.TYPE_STABILITY"), "S", UnitGroup.UNITS_COEFFICIENT, 55);
+       public static final FlightDataType TYPE_STABILITY = newType(trans.get("FlightDataType.TYPE_STABILITY"), "S", UnitGroup.UNITS_COEFFICIENT, 56);
        
        
        //// Characteristic numbers
@@ -194,12 +199,14 @@ public class FlightDataType implements Comparable<FlightDataType> {
                TYPE_VELOCITY_XY, 
                TYPE_ACCELERATION_XY, 
                TYPE_LATITUDE, 
-               TYPE_LONGITUDE, 
+               TYPE_LONGITUDE,
+               TYPE_GRAVITY,
                TYPE_AOA,
                TYPE_ROLL_RATE,
                TYPE_PITCH_RATE,
                TYPE_YAW_RATE,
                TYPE_MASS,
+               TYPE_PROPELLANT_MASS,
                TYPE_LONGITUDINAL_INERTIA,
                TYPE_ROTATIONAL_INERTIA,
                TYPE_CP_LOCATION,
index 1d910df0a751f0a0e1edfe84f8647002c4697115..74386364d3ffc07369dc7f0bd7493afae5c9cff4 100644 (file)
@@ -13,15 +13,17 @@ public class MassData {
        private final Coordinate cg;
        private final double longitudinalInertia;
        private final double rotationalInertia;
+       private final double propellantMass;
        
        
-       public MassData(Coordinate cg, double longitudinalInertia, double rotationalInertia) {
+       public MassData(Coordinate cg, double longitudinalInertia, double rotationalInertia, double propellantMass) {
                if (cg == null) {
                        throw new IllegalArgumentException("cg is null");
                }
                this.cg = cg;
                this.longitudinalInertia = longitudinalInertia;
                this.rotationalInertia = rotationalInertia;
+               this.propellantMass = propellantMass;
        }
 
        
@@ -39,6 +41,9 @@ public class MassData {
                return rotationalInertia;
        }
 
+       public double getPropellantMass() {
+               return propellantMass;
+       }
        
        
        @Override
@@ -50,20 +55,20 @@ public class MassData {
                
                MassData other = (MassData) obj;
                return (this.cg.equals(other.cg) && MathUtil.equals(this.longitudinalInertia, other.longitudinalInertia) &&
-                               MathUtil.equals(this.rotationalInertia, other.rotationalInertia));
+                               MathUtil.equals(this.rotationalInertia, other.rotationalInertia)) && MathUtil.equals(this.propellantMass, other.propellantMass) ;
        }
 
        
        @Override
        public int hashCode() {
-               return (int) (cg.hashCode() ^ Double.doubleToLongBits(longitudinalInertia) ^ Double.doubleToLongBits(rotationalInertia));
+               return (int) (cg.hashCode() ^ Double.doubleToLongBits(longitudinalInertia) ^ Double.doubleToLongBits(rotationalInertia) ^ Double.doubleToLongBits(propellantMass) );
        }
 
 
        @Override
        public String toString() {
                return "MassData [cg=" + cg + ", longitudinalInertia=" + longitudinalInertia
-                               + ", rotationalInertia=" + rotationalInertia + "]";
+                               + ", rotationalInertia=" + rotationalInertia + ", propellantMass="+propellantMass + "]";
        }
        
 }
index 6b7aad9d8312adcb7170f5556ab46ce5d9577357..8548ec91ef5feb6f34e31dfce524a59108f1592f 100644 (file)
@@ -605,12 +605,14 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
                }
                if (store.massData != null) {
                        data.setValue(FlightDataType.TYPE_MASS, store.massData.getCG().weight);
+                       data.setValue(FlightDataType.TYPE_PROPELLANT_MASS, store.massData.getPropellantMass());
                        data.setValue(FlightDataType.TYPE_LONGITUDINAL_INERTIA, store.massData.getLongitudinalInertia());
                        data.setValue(FlightDataType.TYPE_ROTATIONAL_INERTIA, store.massData.getRotationalInertia());
                }
                
                data.setValue(FlightDataType.TYPE_THRUST_FORCE, store.thrustForce);
                data.setValue(FlightDataType.TYPE_DRAG_FORCE, store.dragForce);
+               data.setValue(FlightDataType.TYPE_GRAVITY, store.gravity);
                
                if (status.isLaunchRodCleared() && store.forces != null) {
                        if (store.massData != null && store.flightConditions != null) {