Pull CD calculation out of BasicLandingStepper sim step

Aligh BasicLandingStepper and BasicTumbleStepper sim steps
This commit is contained in:
JoePfeiffer 2023-04-21 16:18:49 -06:00
parent 77d4bc890f
commit dfd7e04db5
2 changed files with 24 additions and 20 deletions

View File

@ -17,15 +17,30 @@ public class BasicLandingStepper extends AbstractSimulationStepper {
private static final double RECOVERY_TIME_STEP = 0.5; private static final double RECOVERY_TIME_STEP = 0.5;
private double cd;
@Override @Override
public SimulationStatus initialize(SimulationStatus status) { public SimulationStatus initialize(SimulationStatus status) {
this.cd = computeCD(status);
return 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 @Override
public void step(SimulationStatus status, double maxTimeStep) throws SimulationException { public void step(SimulationStatus status, double maxTimeStep) throws SimulationException {
double totalCD = 0;
double refArea = status.getConfiguration().getReferenceArea();
// Get the atmospheric conditions // Get the atmospheric conditions
AtmosphericConditions atmosphere = modelAtmosphericConditions(status); AtmosphericConditions atmosphere = modelAtmosphericConditions(status);
@ -34,19 +49,12 @@ public class BasicLandingStepper extends AbstractSimulationStepper {
Coordinate windSpeed = modelWindVelocity(status); Coordinate windSpeed = modelWindVelocity(status);
Coordinate airSpeed = status.getRocketVelocity().add(windSpeed); 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 // Compute drag force
double mach = airSpeed.length() / atmosphere.getMachSpeed();
double dynP = (0.5 * atmosphere.getDensity() * airSpeed.length2()); 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 rocketMass = calculateStructureMass(status).getMass();
double motorMass = calculateMotorMass(status).getMass(); double motorMass = calculateMotorMass(status).getMass();

View File

@ -34,7 +34,7 @@ public class BasicTumbleStepper extends AbstractSimulationStepper {
@Override @Override
public SimulationStatus initialize(SimulationStatus status) { public SimulationStatus initialize(SimulationStatus status) {
this.cd = computeTumbleCD(status); this.cd = computeCD(status);
return status; return status;
} }
@ -42,7 +42,7 @@ public class BasicTumbleStepper extends AbstractSimulationStepper {
return cd; return cd;
} }
private double computeTumbleCD(SimulationStatus status) { private double computeCD(SimulationStatus status) {
// Computed based on Sampo's experimentation as documented in the pdf. // 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 windSpeed = modelWindVelocity(status);
Coordinate airSpeed = status.getRocketVelocity().add(windSpeed); Coordinate airSpeed = status.getRocketVelocity().add(windSpeed);
// Get total CD
double mach = airSpeed.length() / atmosphere.getMachSpeed();
double tumbleCD = getCD();
// Compute drag force // Compute drag force
double mach = airSpeed.length() / atmosphere.getMachSpeed();
double dynP = (0.5 * atmosphere.getDensity() * airSpeed.length2()); 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... // n.b. this is constant, and could be calculated once at the beginning of this simulation branch...
double rocketMass = calculateStructureMass(status).getMass(); double rocketMass = calculateStructureMass(status).getMass();