From d986f8cf502d63b32f57189b1c9e9825ef19dc86 Mon Sep 17 00:00:00 2001 From: richardgraham Date: Wed, 5 Sep 2012 05:14:10 +0000 Subject: [PATCH] Added gravitational acceleration and propellant mass datatypes. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@1011 180e2498-e6e9-4542-8430-84ac67f01cd8 --- core/resources/l10n/messages.properties | 2 ++ .../masscalc/BasicMassCalculator.java | 27 +++++++++++++++++-- .../openrocket/masscalc/MassCalculator.java | 8 ++++++ .../sf/openrocket/motor/MotorInstance.java | 3 +++ .../sf/openrocket/motor/ThrustCurveMotor.java | 7 +++++ .../simulation/AbstractSimulationStepper.java | 6 +++-- .../simulation/BasicLandingStepper.java | 3 +++ .../openrocket/simulation/FlightDataType.java | 19 ++++++++----- .../sf/openrocket/simulation/MassData.java | 13 ++++++--- .../simulation/RK4SimulationStepper.java | 2 ++ 10 files changed, 76 insertions(+), 14 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 88f2c019..1b5da0ed 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -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 diff --git a/core/src/net/sf/openrocket/masscalc/BasicMassCalculator.java b/core/src/net/sf/openrocket/masscalc/BasicMassCalculator.java index 4b5d8276..3fd82fdf 100644 --- a/core/src/net/sf/openrocket/masscalc/BasicMassCalculator.java +++ b/core/src/net/sf/openrocket/masscalc/BasicMassCalculator.java @@ -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 getCGAnalysis(Configuration configuration, MassCalcType type) { checkCache(configuration); diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculator.java b/core/src/net/sf/openrocket/masscalc/MassCalculator.java index 003650e1..5e657f7a 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculator.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculator.java @@ -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. diff --git a/core/src/net/sf/openrocket/motor/MotorInstance.java b/core/src/net/sf/openrocket/motor/MotorInstance.java index 6b48e3a4..ab474a8e 100644 --- a/core/src/net/sf/openrocket/motor/MotorInstance.java +++ b/core/src/net/sf/openrocket/motor/MotorInstance.java @@ -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(); } diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java index 0781c7c8..e795c823 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java @@ -424,6 +424,7 @@ public class ThrustCurveMotor implements Motor, Comparable { 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 { stepCG = cg[0]; unitRotationalInertia = Inertia.filledCylinderRotational(getDiameter() / 2); unitLongitudinalInertia = Inertia.filledCylinderLongitudinal(getDiameter() / 2, getLength()); + parentMotor = ThrustCurveMotor.this; + } + + @Override + public Motor getParentMotor(){ + return parentMotor; } @Override diff --git a/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java b/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java index 85be9120..0aab853a 100644 --- a/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java +++ b/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java @@ -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; } diff --git a/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java b/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java index dc67e853..0d9c3954 100644 --- a/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java +++ b/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java @@ -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); diff --git a/core/src/net/sf/openrocket/simulation/FlightDataType.java b/core/src/net/sf/openrocket/simulation/FlightDataType.java index 3ad7d633..251d85d6 100644 --- a/core/src/net/sf/openrocket/simulation/FlightDataType.java +++ b/core/src/net/sf/openrocket/simulation/FlightDataType.java @@ -71,6 +71,9 @@ public class FlightDataType implements Comparable { //// 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 { //// 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 { 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, diff --git a/core/src/net/sf/openrocket/simulation/MassData.java b/core/src/net/sf/openrocket/simulation/MassData.java index 1d910df0..74386364 100644 --- a/core/src/net/sf/openrocket/simulation/MassData.java +++ b/core/src/net/sf/openrocket/simulation/MassData.java @@ -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 + "]"; } } diff --git a/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java b/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java index 6b7aad9d..8548ec91 100644 --- a/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java +++ b/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java @@ -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) { -- 2.30.2