From 65ddd1b2a22dae842fc8bad36f8fd5ff3ed523a9 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Fri, 4 Dec 2015 09:30:09 -0500 Subject: [PATCH] [Bugfix] Fixed Simulation bug - propellant mass storage fixed propellantMass bug. --- .../openrocket/masscalc/MassCalculator.java | 4 +- .../net/sf/openrocket/masscalc/MassData.java | 8 +- .../sf/openrocket/motor/MotorInstance.java | 93 ++++++++++++------- .../motor/ThrustCurveMotorInstance.java | 10 ++ .../simulation/AbstractSimulationStepper.java | 10 +- 5 files changed, 82 insertions(+), 43 deletions(-) diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculator.java b/core/src/net/sf/openrocket/masscalc/MassCalculator.java index 41757a7df..4d806f7dc 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculator.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculator.java @@ -251,12 +251,12 @@ public class MassCalculator implements Monitorable { */ public double getPropellantMass(FlightConfiguration configuration, MassCalcType calcType ){ double mass = 0; - //throw new BugException("getPropellantMass is not yet implemented.... "); // add up the masses of all motors in the rocket if ( MassCalcType.NO_MOTORS != calcType ){ for (MotorInstance curInstance : configuration.getActiveMotors()) { - mass = mass + curInstance.getCG().weight - curInstance.getMotor().getEmptyCG().weight; + mass = mass + curInstance.getPropellantMass(); + mass = curInstance.getMotor().getLaunchCG().weight - curInstance.getMotor().getEmptyCG().weight; } } return mass; diff --git a/core/src/net/sf/openrocket/masscalc/MassData.java b/core/src/net/sf/openrocket/masscalc/MassData.java index 7befe7a2b..86c8d0834 100644 --- a/core/src/net/sf/openrocket/masscalc/MassData.java +++ b/core/src/net/sf/openrocket/masscalc/MassData.java @@ -227,8 +227,14 @@ public class MassData { return I_cm.zz; } + // this is a tacked-on hack. + double m_p = Double.NaN; + public void setPropellantMass( final double _mp){ + this.m_p = _mp; + } + public double getPropellantMass(){ - return Double.NaN; + return this.m_p; } /** diff --git a/core/src/net/sf/openrocket/motor/MotorInstance.java b/core/src/net/sf/openrocket/motor/MotorInstance.java index 461b57010..b63598828 100644 --- a/core/src/net/sf/openrocket/motor/MotorInstance.java +++ b/core/src/net/sf/openrocket/motor/MotorInstance.java @@ -15,20 +15,19 @@ import net.sf.openrocket.util.StateChangeListener; * A single motor configuration. This includes the selected motor * and the ejection charge delay. */ -public class MotorInstance implements FlightConfigurableParameter { +public abstract class MotorInstance implements FlightConfigurableParameter { - protected MotorInstanceId id = null; // deferred to subclasses //protected MotorMount mount = null; //protected Motor motor = null; + + protected MotorInstanceId id = null; protected double ejectionDelay = 0.0; protected double ignitionDelay = 0.0; protected IgnitionEvent ignitionEvent = IgnitionEvent.NEVER; protected Coordinate position = Coordinate.ZERO; protected double ignitionTime = 0.0; - // comparison threshold - //private static final double EPSILON = 0.01; protected int modID = 0; private final List listeners = new ArrayList(); @@ -39,6 +38,46 @@ public class MotorInstance implements FlightConfigurableParameter public boolean equals( Object other ){ return (this==other); } + + @Override + public Motor getMotor() { + throw new UnsupportedOperationException("Retrieve a motor from an immutable no-motors instance"); + } + + @Override + public MotorMount getMount() { + throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance"); + } + + @Override + public double getThrust() { + throw new UnsupportedOperationException("Trying to get thrust from an empty motor instance."); + } + + @Override + public Coordinate getCM() { + throw new UnsupportedOperationException("Trying to get Center-of-Mass from an empty motor instance."); + } + + @Override + public double getPropellantMass(){ + throw new UnsupportedOperationException("Trying to get mass from an empty motor instance."); + } + + @Override + public double getLongitudinalInertia() { + throw new UnsupportedOperationException("Trying to get inertia from an empty motor instance."); + } + + @Override + public double getRotationalInertia() { + throw new UnsupportedOperationException("Trying to get inertia from an empty motor instance."); + } + + @Override + public void step(double time, double acceleration, AtmosphericConditions cond) { + throw new UnsupportedOperationException("Cannot step an abstract base class"); + } }; protected MotorInstance() { @@ -61,25 +100,15 @@ public class MotorInstance implements FlightConfigurableParameter return this.ejectionDelay; } - public void setMotor(Motor motor) { - throw new UnsupportedOperationException("Retrieve a motor from an immutable no-motors instance"); - } - - public Motor getMotor() { - throw new UnsupportedOperationException("Retrieve a motor from an immutable no-motors instance"); - } + public void setMotor(Motor motor){} + + public abstract Motor getMotor(); - public void setEjectionDelay(double delay) { - throw new UnsupportedOperationException("Trying to modify immutable no-motors configuration"); - }; + public void setEjectionDelay(double delay) {} - public MotorMount getMount() { - throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance"); - } + public abstract MotorMount getMount(); - public void setMount(final MotorMount _mount) { - throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance"); - } + public void setMount(final MotorMount _mount){} public Coordinate getOffset(){ return this.position; @@ -126,9 +155,7 @@ public class MotorInstance implements FlightConfigurableParameter * @param acceleration the average acceleration during the step. * @param cond the average atmospheric conditions during the step. */ - public void step(double time, double acceleration, AtmosphericConditions cond) { - // no-op - } + public abstract void step(double time, double acceleration, AtmosphericConditions cond); /** @@ -142,32 +169,30 @@ public class MotorInstance implements FlightConfigurableParameter /** * Return the average thrust during the last step. */ - public double getThrust() { - return Double.NaN; - } + public abstract double getThrust(); /** * Return the average CG location during the last step. */ - public Coordinate getCG() { - return Coordinate.NaN; + public Coordinate getCG() { + return this.getCM(); } + public abstract Coordinate getCM(); + + public abstract double getPropellantMass(); + /** * Return the average longitudinal moment of inertia during the last step. * This is the actual inertia, not the unit inertia! */ - public double getLongitudinalInertia() { - return Double.NaN; - } + public abstract double getLongitudinalInertia(); /** * Return the average rotational moment of inertia during the last step. * This is the actual inertia, not the unit inertia! */ - public double getRotationalInertia() { - return Double.NaN; - } + public abstract double getRotationalInertia(); /** * Return whether this motor still produces thrust. If this method returns false diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotorInstance.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotorInstance.java index dec45e925..84a97dc78 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotorInstance.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotorInstance.java @@ -65,6 +65,16 @@ public class ThrustCurveMotorInstance extends MotorInstance { return stepCG; } + @Override + public Coordinate getCM() { + return stepCG; + } + + @Override + public double getPropellantMass(){ + return (motor.getLaunchCG().weight - motor.getEmptyCG().weight); + } + @Override public Coordinate getOffset( ){ if( null == mount ){ diff --git a/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java b/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java index 4e07509f6..856d8919a 100644 --- a/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java +++ b/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java @@ -129,9 +129,10 @@ public abstract class AbstractSimulationStepper implements SimulationStepper { cg = calc.getCG(status.getConfiguration(), MassCalcType.LAUNCH_MASS); longitudinalInertia = calc.getLongitudinalInertia(status.getConfiguration(), MassCalcType.LAUNCH_MASS); rotationalInertia = calc.getRotationalInertia(status.getConfiguration(), MassCalcType.LAUNCH_MASS); - propellantMass = calc.getPropellantMass(status.getConfiguration(), MassCalcType.LAUNCH_MASS); - mass = new MassData(cg, longitudinalInertia, rotationalInertia, propellantMass); - + mass = new MassData(cg, rotationalInertia, longitudinalInertia); + propellantMass = calc.getPropellantMass(status.getConfiguration(), MassCalcType.LAUNCH_MASS); + mass.setPropellantMass( propellantMass ); + // Call post-listener mass = SimulationListenerHelper.firePostMassCalculation(status, mass); @@ -144,9 +145,6 @@ public abstract class AbstractSimulationStepper implements SimulationStepper { } - - - /** * Calculate the average thrust produced by the motors in the current configuration, allowing * listeners to override. The average is taken between status.time and