diff --git a/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java b/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java index 880db8151..e0c0aab8d 100644 --- a/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java +++ b/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java @@ -571,11 +571,9 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator { * @return */ private double calculateBaseDrag(FlightConfiguration configuration, FlightConditions conditions, - Map map, WarningSet warnings) { + Map map, WarningSet warnings) { double base, total; - double radius = 0; - RocketComponent prevComponent = null; if (calcMap == null) buildCalcMap(configuration); @@ -583,36 +581,51 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator { base = calculateBaseCD(conditions.getMach()); total = 0; - for (RocketComponent c : configuration.getActiveComponents()) { + final InstanceMap imap = configuration.getActiveInstances(); + for(Map.Entry> entry: imap.entrySet() ) { + final RocketComponent c = entry.getKey(); + if (!(c instanceof SymmetricComponent)) continue; SymmetricComponent s = (SymmetricComponent) c; - - if(c.isCDOverridden()) { - total += c.getOverrideCD(); - continue; - } - if (radius > s.getForeRadius()) { - double area = Math.PI * (pow2(radius) - pow2(s.getForeRadius())); - double cd = base * area / conditions.getRefArea(); - total += cd; - if (map != null) { - map.get(prevComponent).setBaseCD(cd); + // iterate across component instances + final ArrayList 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 + // its aft CD + double radius = 0; + final SymmetricComponent prevComponent = s.getPreviousSymmetricComponent(); + if (prevComponent != null) { + radius = prevComponent.getAftRadius(); + } + + if (radius > s.getForeRadius()) { + double area = Math.PI * (pow2(radius) - pow2(s.getForeRadius())); + double cd = base * area / conditions.getRefArea(); + total += cd; + if ((map != null) && (prevComponent != null)) { + map.get(prevComponent).setBaseCD(cd); + } + } + + // if I'm the last componenet, set my base CD + // note I can't depend on the iterator serving up components in order, + // so I can't just do this after the last iteration. + if (s.getNextSymmetricComponent() == null) { + double area = Math.PI * pow2(s.getAftRadius()); + double cd = base * area / conditions.getRefArea(); + total += cd; + if (map != null) { + map.get(s).setBaseCD(cd); + } } - } - - radius = s.getAftRadius(); - prevComponent = c; - } - - if (radius > 0) { - double area = Math.PI * pow2(radius); - double cd = base * area / conditions.getRefArea(); - total += cd; - if (map != null) { - map.get(prevComponent).setBaseCD(cd); } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java index 35957c459..64958596e 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.List; import net.sf.openrocket.preset.ComponentPreset; +import net.sf.openrocket.rocketcomponent.PodSet; import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -561,34 +562,37 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial /** * Return the previous symmetric component, or null if none exists. - * NOTE: This method currently assumes that there are no external - * "pods". * * @return the previous SymmetricComponent, or null. */ public final SymmetricComponent getPreviousSymmetricComponent() { RocketComponent c; for (c = this.getPreviousComponent(); c != null; c = c.getPreviousComponent()) { + if (c instanceof PodSet) { + return null; + } if (c instanceof SymmetricComponent) { return (SymmetricComponent) c; } if (!(c instanceof AxialStage) && - (c.axialMethod == AxialMethod.AFTER)) + (c.axialMethod == AxialMethod.AFTER)) { return null; // Bad component type as "parent" + } } return null; } /** * Return the next symmetric component, or null if none exists. - * NOTE: This method currently assumes that there are no external - * "pods". * * @return the next SymmetricComponent, or null. */ - protected final SymmetricComponent getNextSymmetricComponent() { + public final SymmetricComponent getNextSymmetricComponent() { RocketComponent c; for (c = this.getNextComponent(); c != null; c = c.getNextComponent()) { + if (c instanceof PodSet) { + return null; + } if (c instanceof SymmetricComponent) { return (SymmetricComponent) c; }