From 4f4a55b8d22b24fa78b1dd88747529191aa13102 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Thu, 16 Mar 2023 19:29:38 -0600 Subject: [PATCH] Change BarrowmanCalculator to compute base drag for current component, not previous component --- .../aerodynamics/BarrowmanCalculator.java | 49 ++++++++----------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java b/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java index 63ede7ad9..97d7dd303 100644 --- a/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java +++ b/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java @@ -755,11 +755,17 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator { final InstanceMap imap = configuration.getActiveInstances(); for(Map.Entry> entry: imap.entrySet() ) { final RocketComponent c = entry.getKey(); - + if (!(c instanceof SymmetricComponent)) { continue; } + + if (c.isCDOverridden() || + c.isCDOverriddenByAncestor()) { + continue; + } + SymmetricComponent s = (SymmetricComponent) c; double foreRadius = s.getForeRadius(); double aftRadius = s.getAftRadius(); @@ -770,35 +776,20 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator { } int instanceCount = entry.getValue().size(); - - if (c.isCDOverridden() || - c.isCDOverriddenByAncestor()) { - continue; + + // get forward radius of next component + final SymmetricComponent nextComponent = s.getNextSymmetricComponent(); + double nextRadius; + if ((nextComponent != null) && configuration.isComponentActive(nextComponent)) { + nextRadius = nextComponent.getForeRadius(); + } else { + nextRadius = 0.0; } - - // 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 && configuration.isComponentActive(prevComponent)) { - radius = prevComponent.getAftRadius(); - } - - if (radius > foreRadius) { - double area = Math.PI * (pow2(radius) - pow2(foreRadius)); - double cd = base * area / conditions.getRefArea(); - total += instanceCount * cd; - if ((forceMap != null) && (prevComponent != null)) { - forceMap.get(prevComponent).setBaseCD(cd); - } - } - - // if I'm the last component, set my base CD - // note: the iterator *should* serve up the next component.... buuuut .... - // this code 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(aftRadius); + + // if fore radius of next component is less than my aft radius, set my + // base CD + if (nextRadius < aftRadius) { + double area = Math.PI * (pow2(aftRadius) - pow2(nextRadius)); double cd = base * area / conditions.getRefArea(); total += instanceCount * cd; if (forceMap != null) {