Merge pull request #2352 from JoePfeiffer/fix-acceleration-status
Bug fixes in RK4SimulationStepper and RK4SimulationStatus
This commit is contained in:
commit
1ab0f4344b
@ -8,7 +8,6 @@ public class RK4SimulationStatus extends SimulationStatus implements Cloneable {
|
||||
private Coordinate launchRodDirection;
|
||||
|
||||
private double previousAcceleration = 0;
|
||||
private AtmosphericConditions previousAtmosphericConditions;
|
||||
|
||||
// Used for determining when to store aerodynamic computation warnings:
|
||||
private double maxZVelocity = 0;
|
||||
@ -26,7 +25,6 @@ public class RK4SimulationStatus extends SimulationStatus implements Cloneable {
|
||||
this.previousAcceleration = ((RK4SimulationStatus) other).previousAcceleration;
|
||||
this.maxZVelocity = ((RK4SimulationStatus) other).maxZVelocity;
|
||||
this.startWarningTime = ((RK4SimulationStatus) other).startWarningTime;
|
||||
this.previousAtmosphericConditions = ((RK4SimulationStatus) other).previousAtmosphericConditions;
|
||||
}
|
||||
}
|
||||
public void setLaunchRodDirection(Coordinate launchRodDirection) {
|
||||
@ -49,18 +47,6 @@ public class RK4SimulationStatus extends SimulationStatus implements Cloneable {
|
||||
this.previousAcceleration = previousAcceleration;
|
||||
}
|
||||
|
||||
|
||||
public AtmosphericConditions getPreviousAtmosphericConditions() {
|
||||
return previousAtmosphericConditions;
|
||||
}
|
||||
|
||||
|
||||
public void setPreviousAtmosphericConditions(
|
||||
AtmosphericConditions previousAtmosphericConditions) {
|
||||
this.previousAtmosphericConditions = previousAtmosphericConditions;
|
||||
}
|
||||
|
||||
|
||||
public double getMaxZVelocity() {
|
||||
return maxZVelocity;
|
||||
}
|
||||
|
@ -59,9 +59,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
||||
private static final double MAX_PITCH_CHANGE = 4 * Math.PI / 180;
|
||||
|
||||
private Random random;
|
||||
|
||||
|
||||
|
||||
DataStore store = new DataStore();
|
||||
|
||||
@Override
|
||||
public RK4SimulationStatus initialize(SimulationStatus original) {
|
||||
@ -90,28 +88,32 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
||||
public void step(SimulationStatus simulationStatus, double maxTimeStep) throws SimulationException {
|
||||
|
||||
RK4SimulationStatus status = (RK4SimulationStatus) simulationStatus;
|
||||
DataStore store = new DataStore();
|
||||
|
||||
//////// Perform RK4 integration: ////////
|
||||
|
||||
RK4SimulationStatus status2;
|
||||
RK4Parameters k1, k2, k3, k4;
|
||||
|
||||
|
||||
/*
|
||||
* Start with previous time step which is used to compute the initial thrust estimate.
|
||||
* Don't make it longer than maxTimeStep, but at least MIN_TIME_STEP.
|
||||
*/
|
||||
store.timestep = status.getPreviousTimeStep();
|
||||
store.timestep = MathUtil.max(MathUtil.min(store.timestep, maxTimeStep), MIN_TIME_STEP);
|
||||
checkNaN(store.timestep);
|
||||
|
||||
|
||||
/*
|
||||
* Get the current atmospheric conditions
|
||||
*/
|
||||
calculateFlightConditions(status, store);
|
||||
store.atmosphericConditions = store.flightConditions.getAtmosphericConditions();
|
||||
|
||||
/*
|
||||
* Compute the initial thrust estimate. This is used for the first time step computation.
|
||||
*/
|
||||
store.thrustForce = calculateAverageThrust(status, store.timestep, status.getPreviousAcceleration(),
|
||||
status.getPreviousAtmosphericConditions(), false);
|
||||
store.thrustForce = calculateAverageThrust(status, store.timestep, store.longitudinalAcceleration,
|
||||
store.atmosphericConditions, false);
|
||||
|
||||
|
||||
/*
|
||||
* Perform RK4 integration. Decide the time step length after the first step.
|
||||
*/
|
||||
@ -150,7 +152,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
||||
dt[0] /= 5.0;
|
||||
dt[6] = status.getSimulationConditions().getLaunchRodLength() / k1.v.length() / 10;
|
||||
}
|
||||
dt[7] = 1.5 * status.getPreviousTimeStep();
|
||||
dt[7] = 1.5 * store.timestep;
|
||||
|
||||
store.timestep = Double.MAX_VALUE;
|
||||
int limitingValue = -1;
|
||||
@ -261,8 +263,6 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
||||
}
|
||||
status.setSimulationTime(status.getSimulationTime() + store.timestep);
|
||||
|
||||
status.setPreviousTimeStep(store.timestep);
|
||||
|
||||
// Store data
|
||||
// TODO: MEDIUM: Store acceleration etc of entire RK4 step, store should be cloned or something...
|
||||
storeData(status, store);
|
||||
@ -283,11 +283,17 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
||||
throws SimulationException {
|
||||
RK4Parameters params = new RK4Parameters();
|
||||
|
||||
// if (dataStore == null) {
|
||||
// dataStore = new DataStore();
|
||||
// }
|
||||
// Call pre-listeners
|
||||
store.accelerationData = SimulationListenerHelper.firePreAccelerationCalculation(status);
|
||||
|
||||
// Calculate acceleration (if not overridden by pre-listeners)
|
||||
if (store.accelerationData == null) {
|
||||
store.accelerationData = calculateAcceleration(status, dataStore);
|
||||
}
|
||||
|
||||
// Call post-listeners
|
||||
store.accelerationData = SimulationListenerHelper.firePostAccelerationCalculation(status, store.accelerationData);
|
||||
|
||||
calculateAcceleration(status, dataStore);
|
||||
params.a = dataStore.linearAcceleration;
|
||||
params.ra = dataStore.angularAcceleration;
|
||||
params.v = status.getRocketVelocity();
|
||||
@ -312,13 +318,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
||||
* @param status the status of the rocket.
|
||||
* @throws SimulationException
|
||||
*/
|
||||
private void calculateAcceleration(RK4SimulationStatus status, DataStore store) throws SimulationException {
|
||||
|
||||
// Call pre-listeners
|
||||
store.accelerationData = SimulationListenerHelper.firePreAccelerationCalculation(status);
|
||||
if (store.accelerationData != null) {
|
||||
return;
|
||||
}
|
||||
private AccelerationData calculateAcceleration(RK4SimulationStatus status, DataStore store) throws SimulationException {
|
||||
|
||||
// Compute the forces affecting the rocket
|
||||
calculateForces(status, store);
|
||||
@ -403,9 +403,8 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
||||
store.angularAcceleration = status.getRocketOrientationQuaternion().rotate(store.angularAcceleration);
|
||||
|
||||
}
|
||||
|
||||
// Call post-listeners
|
||||
store.accelerationData = SimulationListenerHelper.firePostAccelerationCalculation(status, store.accelerationData);
|
||||
|
||||
return new AccelerationData(null, null, store.linearAcceleration, store.angularAcceleration, status.getRocketOrientationQuaternion());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user