Merge pull request #1573 from JoePfeiffer/optimize-drag

Multiply component drag by number of instances
This commit is contained in:
SiboVG 2022-08-10 21:04:54 +02:00 committed by GitHub
commit e3c7ccc035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
import net.sf.openrocket.aerodynamics.barrowman.FinSetCalc; import net.sf.openrocket.aerodynamics.barrowman.FinSetCalc;
import net.sf.openrocket.aerodynamics.barrowman.RocketComponentCalc; import net.sf.openrocket.aerodynamics.barrowman.RocketComponentCalc;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.ComponentAssembly;
import net.sf.openrocket.rocketcomponent.ExternalComponent; import net.sf.openrocket.rocketcomponent.ExternalComponent;
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish; import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
@ -370,8 +371,9 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) { for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) {
final RocketComponent c = entry.getKey(); final RocketComponent c = entry.getKey();
if (!c.isAerodynamic()) if (!c.isAerodynamic()) {
continue; continue;
}
// Handle Overriden CD for Whole Rocket // Handle Overriden CD for Whole Rocket
if(c.isCDOverridden()) { if(c.isCDOverridden()) {
@ -407,34 +409,29 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
} }
// iterate across component instances double componentFrictionCD = calcMap.get(c).calculateFrictionCD(conditions, componentCf, warningSet);
double componentFrictionCDTotal = 0; // Total friction drag of the component
final ArrayList<InstanceContext> contextList = entry.getValue();
for(InstanceContext context: contextList ) {
double componentFrictionCD = calcMap.get(c).calculateFrictionCD(conditions, componentCf, warningSet);
if (c instanceof SymmetricComponent) { int instanceCount = entry.getValue().size();
SymmetricComponent s = (SymmetricComponent) c; if (c instanceof SymmetricComponent) {
bodyFrictionCD += componentFrictionCD; SymmetricComponent s = (SymmetricComponent) c;
final double componentMinX = context.getLocation().x; bodyFrictionCD += instanceCount * componentFrictionCD;
minX = Math.min(minX, componentMinX);
final double componentMaxX = componentMinX + c.getLength(); final double componentMinX = c.getAxialOffset(AxialMethod.ABSOLUTE);
maxX = Math.max(maxX, componentMaxX); minX = Math.min(minX, componentMinX);
final double componentMaxR = Math.max(s.getForeRadius(), s.getAftRadius()); final double componentMaxX = componentMinX + c.getLength();
maxR = Math.max(maxR, componentMaxR); maxX = Math.max(maxX, componentMaxX);
} else { final double componentMaxR = Math.max(s.getForeRadius(), s.getAftRadius());
otherFrictionCD += componentFrictionCD; maxR = Math.max(maxR, componentMaxR);
}
componentFrictionCDTotal += componentFrictionCD; } else {
otherFrictionCD += instanceCount * componentFrictionCD;
} }
if (map != null) { if (map != null) {
map.get(c).setFrictionCD(componentFrictionCDTotal); map.get(c).setFrictionCD(componentFrictionCD);
} }
} }
@ -594,8 +591,7 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
private double calculatePressureCD(FlightConfiguration configuration, FlightConditions conditions, private double calculatePressureCD(FlightConfiguration configuration, FlightConditions conditions,
Map<RocketComponent, AerodynamicForces> forceMap, WarningSet warningSet) { Map<RocketComponent, AerodynamicForces> forceMap, WarningSet warningSet) {
double stagnation, base, total; double total, stagnation, base;
if (calcMap == null) if (calcMap == null)
buildCalcMap(configuration); buildCalcMap(configuration);
@ -607,45 +603,46 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) { for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) {
final RocketComponent c = entry.getKey(); final RocketComponent c = entry.getKey();
if (!c.isAerodynamic()) if (!c.isAerodynamic()) {
continue; continue;
// iterate across component instances
double pressureCDTotal = 0; // Total pressure drag for this component
final ArrayList<InstanceContext> contextList = entry.getValue();
for(InstanceContext context: contextList ) {
// Pressure drag
double pressureCD = calcMap.get(c).calculatePressureCD(conditions, stagnation, base,
warningSet);
pressureCDTotal += pressureCD;
// Total pressure drag of the rocket
total += pressureCD;
if(c.isCDOverridden())
continue;
// Stagnation drag
if (c instanceof SymmetricComponent) {
SymmetricComponent s = (SymmetricComponent) c;
double radius = 0;
final SymmetricComponent prevComponent = s.getPreviousSymmetricComponent();
if (prevComponent != null && configuration.isComponentActive(prevComponent))
radius = prevComponent.getAftRadius();
if (radius < s.getForeRadius()) {
double area = Math.PI * (pow2(s.getForeRadius()) - pow2(radius));
pressureCD = stagnation * area / conditions.getRefArea();
pressureCDTotal += pressureCD;
total += pressureCD;
}
}
} }
if(c.isCDOverridden()) {
continue;
}
int instanceCount = entry.getValue().size();
// Pressure drag of this component
double cd = calcMap.get(c).calculatePressureCD(conditions, stagnation, base,
warningSet);
if (forceMap != null) { if (forceMap != null) {
forceMap.get(c).setPressureCD(pressureCDTotal); forceMap.get(c).setPressureCD(cd);
}
total += cd * instanceCount;
// Stagnation drag caused by difference in radius between this component
// and previous component (increasing radii. Decreasing radii handled in
// base drag calculation
if (c instanceof SymmetricComponent) {
SymmetricComponent s = (SymmetricComponent) c;
double radius = 0;
final SymmetricComponent prevComponent = s.getPreviousSymmetricComponent();
if (prevComponent != null && configuration.isComponentActive(prevComponent))
radius = prevComponent.getAftRadius();
if (radius < s.getForeRadius()) {
double area = Math.PI * (pow2(s.getForeRadius()) - pow2(radius));
cd = stagnation * area / conditions.getRefArea();
total += instanceCount * cd;
if (forceMap != null) {
forceMap.get(c).setPressureCD(forceMap.get(c).getPressureCD() + cd);
}
}
} }
} }
@ -677,47 +674,46 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) { for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) {
final RocketComponent c = entry.getKey(); final RocketComponent c = entry.getKey();
if (!(c instanceof SymmetricComponent)) if (!(c instanceof SymmetricComponent)) {
continue; continue;
}
SymmetricComponent s = (SymmetricComponent) c; SymmetricComponent s = (SymmetricComponent) c;
// iterate across component instances int instanceCount = entry.getValue().size();
final ArrayList<InstanceContext> contextList = entry.getValue();
for(InstanceContext context: contextList ) {
if(c.isCDOverridden()) {
total += c.getOverrideCD();
continue;
}
// if aft radius of previous component is greater than my forward radius, set if(c.isCDOverridden()) {
// its aft CD total += instanceCount * c.getOverrideCD();
double radius = 0; continue;
final SymmetricComponent prevComponent = s.getPreviousSymmetricComponent(); }
if (prevComponent != null && configuration.isComponentActive(prevComponent)) {
radius = prevComponent.getAftRadius();
}
if (radius > s.getForeRadius()) { // if aft radius of previous component is greater than my forward radius, set
double area = Math.PI * (pow2(radius) - pow2(s.getForeRadius())); // its aft CD
double baseCD = base * area / conditions.getRefArea(); double radius = 0;
total += baseCD; final SymmetricComponent prevComponent = s.getPreviousSymmetricComponent();
if ((map != null) && (prevComponent != null)) { if (prevComponent != null && configuration.isComponentActive(prevComponent)) {
map.get(prevComponent).setBaseCD(baseCD); radius = prevComponent.getAftRadius();
} }
}
// if I'm the last component, set my base CD if (radius > s.getForeRadius()) {
// note: the iterator *should* serve up the next component.... buuuut .... double area = Math.PI * (pow2(radius) - pow2(s.getForeRadius()));
// this code has is tested, and there's no compelling reason to change. double cd = base * area / conditions.getRefArea();
final SymmetricComponent n = s.getNextSymmetricComponent(); total += instanceCount * cd;
if ((n == null) || !configuration.isStageActive(n.getStageNumber())) { if ((map != null) && (prevComponent != null)) {
double area = Math.PI * pow2(s.getAftRadius()); map.get(prevComponent).setBaseCD(cd);
double baseCD = base * area / conditions.getRefArea(); }
total += baseCD; }
if (map != null) {
map.get(s).setBaseCD(baseCD); // if I'm the last component, set my base CD
} // note: the iterator *should* serve up the next component.... buuuut ....
// this code has is tested, and there's no compelling reason to change.
final SymmetricComponent n = s.getNextSymmetricComponent();
if ((n == null) || !configuration.isStageActive(n.getStageNumber())) {
double area = Math.PI * pow2(s.getAftRadius());
double cd = base * area / conditions.getRefArea();
total += instanceCount * cd;
if (map != null) {
map.get(s).setBaseCD(cd);
} }
} }
} }
@ -889,8 +885,9 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
calcMap = new HashMap<>(); calcMap = new HashMap<>();
for (RocketComponent comp: configuration.getAllComponents()) { for (RocketComponent comp: configuration.getAllComponents()) {
if (!comp.isAerodynamic()) if (!comp.isAerodynamic()) {
continue; continue;
}
RocketComponentCalc calcObj = (RocketComponentCalc) Reflection.construct(BARROWMAN_PACKAGE, comp, BARROWMAN_SUFFIX, comp); RocketComponentCalc calcObj = (RocketComponentCalc) Reflection.construct(BARROWMAN_PACKAGE, comp, BARROWMAN_SUFFIX, comp);