Corrected calculateBaseDrag to iterate through all instances of components
Corrected getPreviousSymmetricComponent and getNextSymmetricComponent to stop searching and return null when a PodSet is encountered in search (so it only returns the previous/next component if it's a child of the same pod).
This commit is contained in:
parent
dd3bda8d7e
commit
5e5ce3d06e
@ -571,11 +571,9 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
|
||||
* @return
|
||||
*/
|
||||
private double calculateBaseDrag(FlightConfiguration configuration, FlightConditions conditions,
|
||||
Map<RocketComponent, AerodynamicForces> map, WarningSet warnings) {
|
||||
Map<RocketComponent, AerodynamicForces> 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<RocketComponent, ArrayList<InstanceContext>> 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<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
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user