[refactor][cleanup] refactored optimization.parameters.StabilityParameter -- shortened function, and removed deprecated function call

This commit is contained in:
Daniel_M_Williams 2020-08-23 21:29:32 -04:00
parent 7c72f3a231
commit 728964531b

View File

@ -44,57 +44,47 @@ public class StabilityParameter implements OptimizableParameter {
@Override @Override
public double computeValue(Simulation simulation) throws OptimizationException { public double computeValue(Simulation simulation) throws OptimizationException {
Coordinate cp, cg;
double cpx, cgx;
double stability;
log.debug("Calculating stability of simulation, absolute=" + absolute); log.debug("Calculating stability of simulation, absolute=" + absolute);
/* /*
* These are instantiated each time because this class must be thread-safe. * These are instantiated each time because this class must be thread-safe.
* Caching would in any case be inefficient since the rocket changes all the time. * Caching would in any case be inefficient since the rocket changes all the time.
*/ */
AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator(); final AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();
final FlightConfiguration configuration = simulation.getActiveConfiguration();
FlightConfiguration configuration = simulation.getRocket().getSelectedConfiguration(); final FlightConditions conditions = new FlightConditions(configuration);
FlightConditions conditions = new FlightConditions(configuration);
conditions.setMach(Application.getPreferences().getDefaultMach()); conditions.setMach(Application.getPreferences().getDefaultMach());
conditions.setAOA(0); conditions.setAOA(0);
conditions.setRollRate(0); conditions.setRollRate(0);
cp = aerodynamicCalculator.getWorstCP(configuration, conditions, null); final Coordinate cp = aerodynamicCalculator.getWorstCP(configuration, conditions, null);
// worst case CM is also // the launch CM is the worst case CM
cg = MassCalculator.calculateLaunch(configuration).getCM(); final Coordinate cg = MassCalculator.calculateLaunch(configuration).getCM();
double cpx = Double.NaN;
if (cp.weight > 0.000001) if (cp.weight > 0.000001)
cpx = cp.x; cpx = cp.x;
else
cpx = Double.NaN; double cgx = Double.NaN;
if (cg.weight > 0.000001) if (cg.weight > 0.000001)
cgx = cg.x; cgx = cg.x;
else
cgx = Double.NaN;
// Calculate the reference (absolute or relative) // Calculate the reference (absolute or relative)
stability = cpx - cgx; final double stability_absolute = cpx - cgx;
if (!absolute) { if (absolute) {
return stability_absolute;
} else {
double diameter = 0; double diameter = 0;
for (RocketComponent c : configuration.getActiveComponents()) { for (RocketComponent c : configuration.getActiveInstances().keySet()) {
if (c instanceof SymmetricComponent) { if (c instanceof SymmetricComponent) {
double d1 = ((SymmetricComponent) c).getForeRadius() * 2; final double d1 = ((SymmetricComponent) c).getForeRadius() * 2;
double d2 = ((SymmetricComponent) c).getAftRadius() * 2; final double d2 = ((SymmetricComponent) c).getAftRadius() * 2;
diameter = MathUtil.max(diameter, d1, d2); diameter = MathUtil.max(diameter, d1, d2);
} }
} }
stability = stability / diameter; return stability_absolute / diameter;
} }
log.debug("Resulting stability is " + stability + ", absolute=" + absolute);
return stability;
} }
@Override @Override