Fixes to make simulations finally work again.

This commit is contained in:
Kevin Ruland 2016-01-16 22:14:09 -06:00
parent dbde8a5a40
commit e174e4f0f6
5 changed files with 21 additions and 5 deletions

View File

@ -43,15 +43,14 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public MotorState getSimulationState() {
MotorState state = motor.getNewInstance();
state.setEjectionDelay( this.ejectionDelay );
if( ignitionOveride ) {
state.setIgnitionEvent( this.ignitionEvent );
state.setIgnitionDelay( this.ignitionDelay );
state.setEjectionDelay( this.ejectionDelay );
} else {
MotorConfiguration defInstance = mount.getDefaultMotorInstance();
state.setIgnitionEvent( defInstance.ignitionEvent );
state.setIgnitionDelay( defInstance.ignitionDelay );
state.setEjectionDelay( defInstance.ejectionDelay );
}
state.setMount( mount );
state.setId( id );
@ -70,7 +69,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
if( motor == null ){
return EMPTY_DESCRIPTION;
}else{
return this.motor.getDesignation() + " - " + this.getEjectionDelay();
return this.motor.getDesignation() + "-" + (int)this.getEjectionDelay();
}
}

View File

@ -4,6 +4,7 @@ import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
import net.sf.openrocket.rocketcomponent.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.simulation.MotorState;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Inertia;
import net.sf.openrocket.util.MathUtil;
@ -15,7 +16,7 @@ public class ThrustCurveMotorState implements MotorState {
protected MotorMount mount = null;
protected MotorInstanceId id = null;
private double ignitionTime;
private double ignitionTime = -1;
private double ignitionDelay;
private IgnitionEvent ignitionEvent;
private double ejectionDelay;
@ -56,6 +57,15 @@ public class ThrustCurveMotorState implements MotorState {
}
@Override
public ThrustCurveMotorState clone() {
try {
return (ThrustCurveMotorState) super.clone();
} catch (CloneNotSupportedException e) {
throw new BugException("CloneNotSupportedException", e);
}
}
@Override
public double getIgnitionTime() {
return ignitionTime;

View File

@ -174,6 +174,9 @@ public abstract class AbstractSimulationStepper implements SimulationStepper {
final double currentTime = status.getSimulationTime() + timestep;
Collection<MotorState> activeMotorList = status.getActiveMotors();
for (MotorState currentMotorInstance : activeMotorList ) {
if ( !stepMotors ) {
currentMotorInstance = currentMotorInstance.clone();
}
// old: transplanted from MotorInstanceConfiguration
double instanceTime = currentTime - currentMotorInstance.getIgnitionTime();
if (instanceTime >= 0) {

View File

@ -5,7 +5,7 @@ import net.sf.openrocket.motor.MotorInstanceId;
import net.sf.openrocket.rocketcomponent.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount;
public interface MotorState {
public interface MotorState extends Cloneable {
public void step(double nextTime, double acceleration, AtmosphericConditions cond);
public double getThrust();
@ -28,4 +28,7 @@ public interface MotorState {
public double getEjectionDelay();
public void setEjectionDelay( double delay);
public MotorState clone();
}

View File

@ -182,6 +182,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
double thrustEstimate = store.thrustForce;
store.thrustForce = calculateThrust(status, store.timestep, store.longitudinalAcceleration,
store.atmosphericConditions, true);
log.trace("Thrust at time " + store.timestep + " thrustForce = " + store.thrustForce);
double thrustDiff = Math.abs(store.thrustForce - thrustEstimate);
// Log if difference over 1%, recompute if over 10%
if (thrustDiff > 0.01 * thrustEstimate) {