[refactor][cleanup] refactored optimization.parameters.StabilityParameter -- shortened function, and removed deprecated function call
This commit is contained in:
parent
7c72f3a231
commit
728964531b
@ -44,57 +44,47 @@ public class StabilityParameter implements OptimizableParameter {
|
||||
|
||||
@Override
|
||||
public double computeValue(Simulation simulation) throws OptimizationException {
|
||||
Coordinate cp, cg;
|
||||
double cpx, cgx;
|
||||
double stability;
|
||||
|
||||
log.debug("Calculating stability of simulation, absolute=" + absolute);
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();
|
||||
|
||||
FlightConfiguration configuration = simulation.getRocket().getSelectedConfiguration();
|
||||
FlightConditions conditions = new FlightConditions(configuration);
|
||||
final AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();
|
||||
final FlightConfiguration configuration = simulation.getActiveConfiguration();
|
||||
final FlightConditions conditions = new FlightConditions(configuration);
|
||||
conditions.setMach(Application.getPreferences().getDefaultMach());
|
||||
conditions.setAOA(0);
|
||||
conditions.setRollRate(0);
|
||||
|
||||
cp = aerodynamicCalculator.getWorstCP(configuration, conditions, null);
|
||||
// worst case CM is also
|
||||
cg = MassCalculator.calculateLaunch(configuration).getCM();
|
||||
final Coordinate cp = aerodynamicCalculator.getWorstCP(configuration, conditions, null);
|
||||
// the launch CM is the worst case CM
|
||||
final Coordinate cg = MassCalculator.calculateLaunch(configuration).getCM();
|
||||
|
||||
double cpx = Double.NaN;
|
||||
if (cp.weight > 0.000001)
|
||||
cpx = cp.x;
|
||||
else
|
||||
cpx = Double.NaN;
|
||||
|
||||
double cgx = Double.NaN;
|
||||
if (cg.weight > 0.000001)
|
||||
cgx = cg.x;
|
||||
else
|
||||
cgx = Double.NaN;
|
||||
|
||||
|
||||
// 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;
|
||||
for (RocketComponent c : configuration.getActiveComponents()) {
|
||||
for (RocketComponent c : configuration.getActiveInstances().keySet()) {
|
||||
if (c instanceof SymmetricComponent) {
|
||||
double d1 = ((SymmetricComponent) c).getForeRadius() * 2;
|
||||
double d2 = ((SymmetricComponent) c).getAftRadius() * 2;
|
||||
final double d1 = ((SymmetricComponent) c).getForeRadius() * 2;
|
||||
final double d2 = ((SymmetricComponent) c).getAftRadius() * 2;
|
||||
diameter = MathUtil.max(diameter, d1, d2);
|
||||
}
|
||||
}
|
||||
stability = stability / diameter;
|
||||
return stability_absolute / diameter;
|
||||
}
|
||||
|
||||
log.debug("Resulting stability is " + stability + ", absolute=" + absolute);
|
||||
|
||||
return stability;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user