[refactor] Pods and ParallelStages are now attached to BodyTubes *only*

This commit is contained in:
Daniel_M_Williams 2018-01-07 14:19:02 -05:00
parent 20eff575f4
commit 23d7397fa6
13 changed files with 436 additions and 521 deletions

View File

@ -38,7 +38,7 @@ public enum IgnitionEvent {
AxialStage targetStage = (AxialStage)targetComponent.getStage();
AxialStage eventStage = (AxialStage)testEvent.getSource().getStage();
AxialStage eventParentStage = eventStage.getPreviousStage();
AxialStage eventParentStage = eventStage.getUpperStage();
return ( targetStage.equals(eventParentStage));
}
},
@ -50,7 +50,7 @@ public enum IgnitionEvent {
AxialStage targetStage = (AxialStage)targetComponent.getStage();
AxialStage eventStage = (AxialStage)testEvent.getSource().getStage();
AxialStage eventParentStage = eventStage.getPreviousStage();
AxialStage eventParentStage = eventStage.getUpperStage();
return ( targetStage.equals(eventParentStage));
}
},

View File

@ -82,13 +82,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
*/
@Override
public boolean isCompatible(Class<? extends RocketComponent> type) {
if (ParallelStage.class.isAssignableFrom(type)) {
return true;
} else if (PodSet.class.isAssignableFrom(type)) {
return true;
}
return BodyComponent.class.isAssignableFrom(type);
return BodyComponent.class.isAssignableFrom(type);
}
@Override
@ -180,18 +174,18 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
* returns null if this is the first stage
* @return the previous stage in the rocket
*/
public AxialStage getPreviousStage() {
if( this instanceof ParallelStage ){
return (AxialStage) this.parent;
}
AxialStage thisStage = this.getStage(); // necessary in case of pods or other assemblies
if( thisStage.parent instanceof Rocket ){
final int thisIndex = parent.getChildPosition( thisStage );
public AxialStage getUpperStage() {
if( null == this.parent ) {
return null;
}else if(Rocket.class.isAssignableFrom(this.parent.getClass()) ){
final int thisIndex = getStageNumber();
if( 0 < thisIndex ){
return (AxialStage)thisStage.parent.getChild(thisIndex-1);
return (AxialStage)parent.getChild(thisIndex-1);
}
}else {
return this.parent.getStage();
}
return null;
return null;
}
@Override

View File

@ -351,6 +351,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
*/
@Override
public boolean isCompatible(Class<? extends RocketComponent> type) {
if (ParallelStage.class.isAssignableFrom(type))
return true;
if (PodSet.class.isAssignableFrom(type))
return true;
if (InternalComponent.class.isAssignableFrom(type))
return true;
if (ExternalComponent.class.isAssignableFrom(type) &&

View File

@ -38,7 +38,7 @@ public abstract class ComponentAssembly extends RocketComponent {
@Override
public double getAxialOffset() {
return super.asPositionValue(this.relativePosition);
return asPositionValue(this.relativePosition);
}
/**

View File

@ -183,6 +183,7 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
return this.autoRadialPosition;
}
@Override
public void setAutoRadialOffset( final boolean enabled ){
this.autoRadialPosition = enabled;
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
@ -205,13 +206,13 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
@Override
protected void update() {
super.update();
if( this.autoRadialPosition ){
ComponentAssembly parentAssembly = (ComponentAssembly)this.parent;
if( null == parentAssembly ){
if( this.autoRadialPosition){
if( null == this.parent ){
this.radialPosition_m = this.getOuterRadius();
}else{
this.radialPosition_m = this.getOuterRadius() + parentAssembly.getOuterRadius();
}else if( BodyTube.class.isAssignableFrom(this.parent.getClass())) {
BodyTube parentBody = (BodyTube)this.parent;
this.radialPosition_m = this.getOuterRadius() + parentBody.getOuterRadius();
}
}
}

View File

@ -227,11 +227,11 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
super.update();
if( this.autoRadialPosition){
ComponentAssembly parentAssembly = (ComponentAssembly)this.parent;
if( null == parentAssembly ){
if( null == this.parent ){
this.radialPosition_m = this.getOuterRadius();
}else{
this.radialPosition_m = this.getOuterRadius() + parentAssembly.getOuterRadius();
}else if( BodyTube.class.isAssignableFrom(this.parent.getClass())) {
BodyTube parentBody = (BodyTube)this.parent;
this.radialPosition_m = this.getOuterRadius() + parentBody.getOuterRadius();
}
}
}

View File

@ -11,6 +11,7 @@ import java.util.NoSuchElementException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import junit.framework.Assert;
import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.motor.Motor;
@ -110,7 +111,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
protected double length = 0;
/**
* Positioning of this component relative to the parent component.
* How this component is axially positioned, possibly in relative to the parent component.
*/
protected Position relativePosition = Position.AFTER;
@ -992,32 +993,29 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
* @return double position of the component relative to the parent, with respect to <code>position</code>
*/
public double asPositionValue(Position thePosition) {
double relativeLength;
double parentLength;
if (null == this.parent) {
relativeLength = 0;
parentLength = 0;
}else{
relativeLength = this.parent.length;
parentLength = this.parent.length;
}
double thisX = this.position.x;
double result = Double.NaN;
switch (thePosition) {
case AFTER:
result = thisX - relativeLength;
result = this.position.x - parentLength;
break;
case ABSOLUTE:
Coordinate[] insts = this.getLocations();
result = insts[0].x;
result = this.getComponentLocations()[0].x;
break;
case TOP:
result = thisX;
result = this.position.x;
break;
case MIDDLE:
result = thisX + (-relativeLength + this.getLength()) / 2;
result = this.position.x + ( this.length - parentLength) / 2;
break;
case BOTTOM:
result = thisX + (-relativeLength + this.getLength());
result = this.position.x + ( this.length - parentLength);
break;
default:
throw new BugException("Unknown position type: " + thePosition);
@ -1096,6 +1094,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
}else{
this.relativePosition = positionMethod;
}
if (null == this.parent) {
// if this is the root of a hierarchy, constrain the position to zero.
if( this instanceof Rocket ){
@ -1113,9 +1112,10 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
final double EPSILON = 0.000001;
double newAxialPosition = Double.NaN;
final double refLength = this.parent.getLength();
switch (this.relativePosition) {
case ABSOLUTE:
newAxialPosition = newOffset - this.parent.position.x;
newAxialPosition = newOffset - this.parent.getComponentLocations()[0].x;
break;
case AFTER:
// no-op
@ -1129,6 +1129,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
break;
case BOTTOM:
newAxialPosition = (refLength - this.length) + newOffset;
//System.err.println(String.format("____( %.6g - %.6g) + %.6g = %.6g", refLength, this.length, newOffset, newAxialPosition ));
break;
default:
throw new BugException("Unknown position type: " + this.relativePosition);

View File

@ -935,75 +935,75 @@ public class TestRockets {
coreBody.setMotorMount(true);
coreStage.addChild( coreBody);
{
MotorConfiguration motorConfig = new MotorConfiguration(coreBody, selFCID);
MotorConfiguration coreMotorConfig = new MotorConfiguration(coreBody, selFCID);
Motor mtr = TestRockets.generateMotor_M1350_75mm();
motorConfig.setMotor( mtr);
coreMotorConfig.setMotor( mtr);
coreBody.setMotorMount( true);
FlightConfigurationId motorConfigId = selFCID;
coreBody.setMotorConfig( motorConfig, motorConfigId);
}
coreBody.setMotorConfig( coreMotorConfig, motorConfigId);
TrapezoidFinSet coreFins = new TrapezoidFinSet();
coreFins.setName("Core Fins");
coreFins.setFinCount(4);
coreFins.setRelativePosition(Position.BOTTOM);
coreFins.setAxialOffset(0.0);
coreFins.setBaseRotation( Math.PI / 4);
coreFins.setThickness(0.003);
coreFins.setCrossSection(CrossSection.ROUNDED);
coreFins.setRootChord(0.32);
coreFins.setTipChord(0.12);
coreFins.setHeight(0.12);
coreFins.setSweep(0.18);
coreBody.addChild(coreFins);
TrapezoidFinSet coreFins = new TrapezoidFinSet();
coreFins.setName("Core Fins");
coreFins.setFinCount(4);
coreFins.setRelativePosition(Position.BOTTOM);
coreFins.setAxialOffset(0.0);
coreFins.setBaseRotation( Math.PI / 4);
coreFins.setThickness(0.003);
coreFins.setCrossSection(CrossSection.ROUNDED);
coreFins.setRootChord(0.32);
coreFins.setTipChord(0.12);
coreFins.setHeight(0.12);
coreFins.setSweep(0.18);
coreBody.addChild(coreFins);
// ====== Booster Stage Set ======
// ====== ====== ====== ======
ParallelStage boosterStage = new ParallelStage();
boosterStage.setName("Booster Stage");
coreStage.addChild( boosterStage);
boosterStage.setRelativePositionMethod(Position.BOTTOM);
boosterStage.setAxialOffset(0.0);
boosterStage.setInstanceCount(2);
boosterStage.setRadialOffset(0.075);
{
NoseCone boosterCone = new NoseCone(Transition.Shape.POWER, 0.08, 0.0385);
boosterCone.setShapeParameter(0.5);
boosterCone.setName("Booster Nose");
boosterCone.setThickness(0.002);
//payloadFairingNoseCone.setLength(0.118);
//payloadFairingNoseCone.setAftRadius(0.052);
boosterCone.setAftShoulderRadius( 0.051 );
boosterCone.setAftShoulderLength( 0.02 );
boosterCone.setAftShoulderThickness( 0.001 );
boosterCone.setAftShoulderCapped( false );
boosterStage.addChild( boosterCone);
BodyTube boosterBody = new BodyTube(0.8, 0.0385, 0.001);
boosterBody.setName("Booster Body");
boosterBody.setOuterRadiusAutomatic(true);
boosterStage.addChild( boosterBody);
// ====== Booster Stage Set ======
// ====== ====== ====== ======
ParallelStage boosterStage = new ParallelStage();
boosterStage.setName("Booster Stage");
coreBody.addChild( boosterStage);
boosterStage.setRelativePositionMethod(Position.BOTTOM);
boosterStage.setAxialOffset(0.0);
boosterStage.setInstanceCount(2);
boosterStage.setRadialOffset(0.075);
{
InnerTube boosterMotorTubes = new InnerTube();
boosterMotorTubes.setName("Booster Motor Tubes");
boosterMotorTubes.setLength(0.15);
boosterMotorTubes.setOuterRadius(0.015); // => 29mm motors
boosterMotorTubes.setThickness(0.0005);
boosterMotorTubes.setClusterConfiguration( ClusterConfiguration.CONFIGURATIONS[5]); // 4-ring
//boosterMotorTubes.setClusterConfiguration( ClusterConfiguration.CONFIGURATIONS[13]); // 9-star
boosterMotorTubes.setClusterScale(1.0);
boosterBody.addChild( boosterMotorTubes);
NoseCone boosterCone = new NoseCone(Transition.Shape.POWER, 0.08, 0.0385);
boosterCone.setShapeParameter(0.5);
boosterCone.setName("Booster Nose");
boosterCone.setThickness(0.002);
//payloadFairingNoseCone.setLength(0.118);
//payloadFairingNoseCone.setAftRadius(0.052);
boosterCone.setAftShoulderRadius( 0.051 );
boosterCone.setAftShoulderLength( 0.02 );
boosterCone.setAftShoulderThickness( 0.001 );
boosterCone.setAftShoulderCapped( false );
boosterStage.addChild( boosterCone);
FlightConfigurationId motorConfigId = selFCID;
MotorConfiguration motorConfig = new MotorConfiguration( boosterMotorTubes, selFCID);
Motor mtr = TestRockets.generateMotor_G77_29mm();
motorConfig.setMotor(mtr);
boosterMotorTubes.setMotorConfig( motorConfig, motorConfigId);
boosterMotorTubes.setMotorOverhang(0.01234);
BodyTube boosterBody = new BodyTube(0.8, 0.0385, 0.001);
boosterBody.setName("Booster Body");
boosterBody.setOuterRadiusAutomatic(true);
boosterStage.addChild( boosterBody);
{
InnerTube boosterMotorTubes = new InnerTube();
boosterMotorTubes.setName("Booster Motor Tubes");
boosterMotorTubes.setLength(0.15);
boosterMotorTubes.setOuterRadius(0.015); // => 29mm motors
boosterMotorTubes.setThickness(0.0005);
boosterMotorTubes.setClusterConfiguration( ClusterConfiguration.CONFIGURATIONS[5]); // 4-ring
//boosterMotorTubes.setClusterConfiguration( ClusterConfiguration.CONFIGURATIONS[13]); // 9-star
boosterMotorTubes.setClusterScale(1.0);
boosterBody.addChild( boosterMotorTubes);
MotorConfiguration boosterMotorConfig = new MotorConfiguration( boosterMotorTubes, selFCID);
Motor boosterMotor = TestRockets.generateMotor_G77_29mm();
boosterMotorConfig.setMotor( boosterMotor );
boosterMotorTubes.setMotorConfig( boosterMotorConfig, motorConfigId);
boosterMotorTubes.setMotorOverhang(0.01234);
}
}
}
}

View File

@ -180,7 +180,7 @@ public class BarrowmanCalculatorTest {
Rocket rocket = TestRockets.makeFalcon9Heavy();
AerodynamicCalculator calc = new BarrowmanCalculator();
ParallelStage booster = (ParallelStage)rocket.getChild(1).getChild(1);
ParallelStage booster = (ParallelStage)rocket.getChild(1).getChild(0).getChild(1);
NoseCone nose = (NoseCone)booster.getChild(0);
BodyTube body = (BodyTube)booster.getChild(1);

View File

@ -205,7 +205,7 @@ public class MassCalculatorTest extends BaseTestCase {
// ====== Booster Set Stage ======
// ====== ====== ======
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(1);
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(0).getChild(1);
{
expMass = 0.0222459863653;
// think of the casts as an assert that ( child instanceof NoseCone) == true
@ -288,7 +288,7 @@ public class MassCalculatorTest extends BaseTestCase {
// ====== Booster Set Stage ======
// ====== ====== ======
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(1);
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(0).getChild(1);
{
expCMx = 0.055710581052;
// think of the casts as an assert that ( child instanceof NoseCone) == true
@ -406,7 +406,7 @@ public class MassCalculatorTest extends BaseTestCase {
// ====== Booster Set Stage ======
// ====== ====== ======
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
{
cc= boosters.getChild(0);
expInertia = 1.82665797857e-5;
@ -535,7 +535,7 @@ public class MassCalculatorTest extends BaseTestCase {
FlightConfiguration config = rocket.getEmptyConfiguration();
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
config.setOnlyStage( boosters.getStageNumber() );
final RigidBody actualData = MassCalculator.calculateStructure( config );
@ -606,7 +606,7 @@ public class MassCalculatorTest extends BaseTestCase {
RigidBody actualPropellant = MassCalculator.calculateMotor( config );
final Coordinate actCM= actualPropellant.getCM();
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
final MotorMount mnt = (MotorMount)boosters.getChild(1).getChild(0);
final Motor boosterMotor = mnt.getMotorConfig( config.getFlightConfigurationID()).getMotor();
@ -690,7 +690,7 @@ public class MassCalculatorTest extends BaseTestCase {
rocket.setSelectedConfiguration( config.getId() );
config.setOnlyStage( TestRockets.FALCON_9H_BOOSTER_STAGE_NUMBER );
final ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
final ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
final double overrideMass = 0.5;
boosters.setOverrideSubcomponents(true);
boosters.setMassOverridden(true);
@ -730,7 +730,7 @@ public class MassCalculatorTest extends BaseTestCase {
FlightConfiguration config = rocket.getEmptyConfiguration();
rocket.setSelectedConfiguration( config.getId() );
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
config.setOnlyStage( boosters.getStageNumber() );
NoseCone nose = (NoseCone)boosters.getChild(0);
@ -777,7 +777,7 @@ public class MassCalculatorTest extends BaseTestCase {
rocket.setSelectedConfiguration( config.getId() );
config.setOnlyStage( TestRockets.FALCON_9H_BOOSTER_STAGE_NUMBER );
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
NoseCone nose = (NoseCone)boosters.getChild(0);
nose.setCGOverridden(true);