From dfd7e04db502f1e50db35792fd69bb0d576c657c Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Fri, 21 Apr 2023 16:18:49 -0600 Subject: [PATCH] Pull CD calculation out of BasicLandingStepper sim step Aligh BasicLandingStepper and BasicTumbleStepper sim steps --- .../simulation/BasicLandingStepper.java | 32 ++++++++++++------- .../simulation/BasicTumbleStepper.java | 12 +++---- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java b/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java index de7db0bab..bdd92d8dd 100644 --- a/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java +++ b/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java @@ -16,16 +16,31 @@ public class BasicLandingStepper extends AbstractSimulationStepper { private static final Logger log = LoggerFactory.getLogger(BasicLandingStepper.class); private static final double RECOVERY_TIME_STEP = 0.5; + + private double cd; @Override public SimulationStatus initialize(SimulationStatus status) { + this.cd = computeCD(status); return status; } + + private double getCD() { + return cd; + } + + private double computeCD(SimulationStatus status) { + // Accumulate CD for all recovery devices + cd = 0; + final InstanceMap imap = status.getConfiguration().getActiveInstances(); + for (RecoveryDevice c : status.getDeployedRecoveryDevices()) { + cd += imap.count(c) * c.getCD() * c.getArea() / status.getConfiguration().getReferenceArea(); + } + return cd; + } @Override public void step(SimulationStatus status, double maxTimeStep) throws SimulationException { - double totalCD = 0; - double refArea = status.getConfiguration().getReferenceArea(); // Get the atmospheric conditions AtmosphericConditions atmosphere = modelAtmosphericConditions(status); @@ -34,19 +49,12 @@ public class BasicLandingStepper extends AbstractSimulationStepper { Coordinate windSpeed = modelWindVelocity(status); Coordinate airSpeed = status.getRocketVelocity().add(windSpeed); - // Get total CD - double mach = airSpeed.length() / atmosphere.getMachSpeed(); - - final InstanceMap imap = status.getConfiguration().getActiveInstances(); - for (RecoveryDevice c : status.getDeployedRecoveryDevices()) { - totalCD += imap.count(c) * c.getCD(mach) * c.getArea() / refArea; - } - // Compute drag force + double mach = airSpeed.length() / atmosphere.getMachSpeed(); double dynP = (0.5 * atmosphere.getDensity() * airSpeed.length2()); - double dragForce = totalCD * dynP * refArea; + double dragForce = getCD() * dynP * status.getConfiguration().getReferenceArea(); - // Calculate mass data + // n.b. this is constant, and could be calculated once at the beginning of this simulation branch... double rocketMass = calculateStructureMass(status).getMass(); double motorMass = calculateMotorMass(status).getMass(); diff --git a/core/src/net/sf/openrocket/simulation/BasicTumbleStepper.java b/core/src/net/sf/openrocket/simulation/BasicTumbleStepper.java index eae5a2f72..c22c327dc 100644 --- a/core/src/net/sf/openrocket/simulation/BasicTumbleStepper.java +++ b/core/src/net/sf/openrocket/simulation/BasicTumbleStepper.java @@ -34,7 +34,7 @@ public class BasicTumbleStepper extends AbstractSimulationStepper { @Override public SimulationStatus initialize(SimulationStatus status) { - this.cd = computeTumbleCD(status); + this.cd = computeCD(status); return status; } @@ -42,7 +42,7 @@ public class BasicTumbleStepper extends AbstractSimulationStepper { return cd; } - private double computeTumbleCD(SimulationStatus status) { + private double computeCD(SimulationStatus status) { // Computed based on Sampo's experimentation as documented in the pdf. @@ -93,14 +93,10 @@ public class BasicTumbleStepper extends AbstractSimulationStepper { Coordinate windSpeed = modelWindVelocity(status); Coordinate airSpeed = status.getRocketVelocity().add(windSpeed); - // Get total CD - double mach = airSpeed.length() / atmosphere.getMachSpeed(); - - double tumbleCD = getCD(); - // Compute drag force + double mach = airSpeed.length() / atmosphere.getMachSpeed(); double dynP = (0.5 * atmosphere.getDensity() * airSpeed.length2()); - double dragForce = status.getConfiguration().getReferenceArea() * tumbleCD * dynP; + double dragForce = status.getConfiguration().getReferenceArea() * getCD() * dynP; // n.b. this is constant, and could be calculated once at the beginning of this simulation branch... double rocketMass = calculateStructureMass(status).getMass();