Move data from RK4SimulationStatus to RK4SimulationStepper.DataStore and eliminate RK4SimulationStatus
This commit is contained in:
parent
7b0637e800
commit
6ef9197d72
@ -1,68 +0,0 @@
|
|||||||
package info.openrocket.core.simulation;
|
|
||||||
|
|
||||||
import info.openrocket.core.models.atmosphere.AtmosphericConditions;
|
|
||||||
import info.openrocket.core.rocketcomponent.FlightConfiguration;
|
|
||||||
import info.openrocket.core.util.Coordinate;
|
|
||||||
|
|
||||||
public class RK4SimulationStatus extends SimulationStatus implements Cloneable {
|
|
||||||
private Coordinate launchRodDirection;
|
|
||||||
|
|
||||||
private double previousAcceleration = 0;
|
|
||||||
|
|
||||||
// Used for determining when to store aerodynamic computation warnings:
|
|
||||||
private double maxZVelocity = 0;
|
|
||||||
private double startWarningTime = -1;
|
|
||||||
|
|
||||||
public RK4SimulationStatus(FlightConfiguration configuration,
|
|
||||||
SimulationConditions simulationConditions ) {
|
|
||||||
super(configuration, simulationConditions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RK4SimulationStatus(SimulationStatus other) {
|
|
||||||
super(other);
|
|
||||||
if (other instanceof RK4SimulationStatus) {
|
|
||||||
this.launchRodDirection = ((RK4SimulationStatus) other).launchRodDirection;
|
|
||||||
this.previousAcceleration = ((RK4SimulationStatus) other).previousAcceleration;
|
|
||||||
this.maxZVelocity = ((RK4SimulationStatus) other).maxZVelocity;
|
|
||||||
this.startWarningTime = ((RK4SimulationStatus) other).startWarningTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLaunchRodDirection(Coordinate launchRodDirection) {
|
|
||||||
this.launchRodDirection = launchRodDirection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Coordinate getLaunchRodDirection() {
|
|
||||||
return launchRodDirection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getPreviousAcceleration() {
|
|
||||||
return previousAcceleration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPreviousAcceleration(double previousAcceleration) {
|
|
||||||
this.previousAcceleration = previousAcceleration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getMaxZVelocity() {
|
|
||||||
return maxZVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxZVelocity(double maxZVelocity) {
|
|
||||||
this.maxZVelocity = maxZVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getStartWarningTime() {
|
|
||||||
return startWarningTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartWarningTime(double startWarningTime) {
|
|
||||||
this.startWarningTime = startWarningTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RK4SimulationStatus clone() {
|
|
||||||
return (RK4SimulationStatus) super.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -63,18 +63,18 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
DataStore store = new DataStore();
|
DataStore store = new DataStore();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RK4SimulationStatus initialize(SimulationStatus original) {
|
public SimulationStatus initialize(SimulationStatus original) {
|
||||||
|
|
||||||
RK4SimulationStatus status = new RK4SimulationStatus(original);
|
SimulationStatus status = new SimulationStatus(original);
|
||||||
// Copy the existing warnings
|
// Copy the existing warnings
|
||||||
status.setWarnings(original.getWarnings());
|
status.setWarnings(original.getWarnings());
|
||||||
|
|
||||||
SimulationConditions sim = original.getSimulationConditions();
|
SimulationConditions sim = original.getSimulationConditions();
|
||||||
|
|
||||||
status.setLaunchRodDirection(new Coordinate(
|
store.launchRodDirection = new Coordinate(
|
||||||
Math.sin(sim.getLaunchRodAngle()) * Math.cos(Math.PI / 2.0 - sim.getLaunchRodDirection()),
|
Math.sin(sim.getLaunchRodAngle()) * Math.cos(Math.PI / 2.0 - sim.getLaunchRodDirection()),
|
||||||
Math.sin(sim.getLaunchRodAngle()) * Math.sin(Math.PI / 2.0 - sim.getLaunchRodDirection()),
|
Math.sin(sim.getLaunchRodAngle()) * Math.sin(Math.PI / 2.0 - sim.getLaunchRodDirection()),
|
||||||
Math.cos(sim.getLaunchRodAngle())));
|
Math.cos(sim.getLaunchRodAngle()));
|
||||||
|
|
||||||
this.random = new Random(original.getSimulationConditions().getRandomSeed() ^ SEED_RANDOMIZATION);
|
this.random = new Random(original.getSimulationConditions().getRandomSeed() ^ SEED_RANDOMIZATION);
|
||||||
|
|
||||||
@ -87,11 +87,11 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
@Override
|
@Override
|
||||||
public void step(SimulationStatus simulationStatus, double maxTimeStep) throws SimulationException {
|
public void step(SimulationStatus simulationStatus, double maxTimeStep) throws SimulationException {
|
||||||
|
|
||||||
RK4SimulationStatus status = (RK4SimulationStatus) simulationStatus;
|
SimulationStatus status = simulationStatus;
|
||||||
|
|
||||||
//////// Perform RK4 integration: ////////
|
//////// Perform RK4 integration: ////////
|
||||||
|
|
||||||
RK4SimulationStatus status2;
|
SimulationStatus status2;
|
||||||
RK4Parameters k1, k2, k3, k4;
|
RK4Parameters k1, k2, k3, k4;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -257,7 +257,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private RK4Parameters computeParameters(RK4SimulationStatus status, DataStore dataStore)
|
private RK4Parameters computeParameters(SimulationStatus status, DataStore dataStore)
|
||||||
throws SimulationException {
|
throws SimulationException {
|
||||||
RK4Parameters params = new RK4Parameters();
|
RK4Parameters params = new RK4Parameters();
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
* @param status the status of the rocket.
|
* @param status the status of the rocket.
|
||||||
* @throws SimulationException
|
* @throws SimulationException
|
||||||
*/
|
*/
|
||||||
private AccelerationData calculateAcceleration(RK4SimulationStatus status, DataStore store) throws SimulationException {
|
private AccelerationData calculateAcceleration(SimulationStatus status, DataStore store) throws SimulationException {
|
||||||
|
|
||||||
// Compute the forces affecting the rocket
|
// Compute the forces affecting the rocket
|
||||||
calculateForces(status, store);
|
calculateForces(status, store);
|
||||||
@ -349,8 +349,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
// set angular acceleration to zero.
|
// set angular acceleration to zero.
|
||||||
if (!status.isLaunchRodCleared()) {
|
if (!status.isLaunchRodCleared()) {
|
||||||
|
|
||||||
store.linearAcceleration = status.getLaunchRodDirection().multiply(
|
store.linearAcceleration = store.launchRodDirection.multiply(store.linearAcceleration.dot(store.launchRodDirection));
|
||||||
store.linearAcceleration.dot(status.getLaunchRodDirection()));
|
|
||||||
store.angularAcceleration = Coordinate.NUL;
|
store.angularAcceleration = Coordinate.NUL;
|
||||||
store.rollAcceleration = 0;
|
store.rollAcceleration = 0;
|
||||||
store.lateralPitchAcceleration = 0;
|
store.lateralPitchAcceleration = 0;
|
||||||
@ -391,7 +390,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
* Calculate the aerodynamic forces into the data store. This method also handles
|
* Calculate the aerodynamic forces into the data store. This method also handles
|
||||||
* whether to include aerodynamic computation warnings or not.
|
* whether to include aerodynamic computation warnings or not.
|
||||||
*/
|
*/
|
||||||
private void calculateForces(RK4SimulationStatus status, DataStore store) throws SimulationException {
|
private void calculateForces(SimulationStatus status, DataStore store) throws SimulationException {
|
||||||
|
|
||||||
// Call pre-listeners
|
// Call pre-listeners
|
||||||
store.forces = SimulationListenerHelper.firePreAerodynamicCalculation(status);
|
store.forces = SimulationListenerHelper.firePreAerodynamicCalculation(status);
|
||||||
@ -408,19 +407,21 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
* below 20% of the max. velocity.
|
* below 20% of the max. velocity.
|
||||||
*/
|
*/
|
||||||
WarningSet warnings = status.getWarnings();
|
WarningSet warnings = status.getWarnings();
|
||||||
status.setMaxZVelocity(MathUtil.max(status.getMaxZVelocity(), status.getRocketVelocity().z));
|
store.maxZvelocity = MathUtil.max(store.maxZvelocity, status.getRocketVelocity().z);
|
||||||
|
|
||||||
if (!status.isLaunchRodCleared()) {
|
if (!status.isLaunchRodCleared()) {
|
||||||
warnings = null;
|
warnings = null;
|
||||||
} else {
|
} else {
|
||||||
if (status.getRocketVelocity().z < 0.2 * status.getMaxZVelocity())
|
if (status.getRocketVelocity().z < 0.2 * store.maxZvelocity) {
|
||||||
warnings = null;
|
warnings = null;
|
||||||
if (status.getStartWarningTime() < 0)
|
|
||||||
status.setStartWarningTime(status.getSimulationTime() + 0.25);
|
|
||||||
}
|
}
|
||||||
if (status.getSimulationTime() < status.getStartWarningTime())
|
if (Double.isNaN(store.startWarningTime)) {
|
||||||
warnings = null;
|
store.startWarningTime = status.getSimulationTime() + 0.25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(status.getSimulationTime() > store.startWarningTime))
|
||||||
|
warnings = null;
|
||||||
|
|
||||||
// Calculate aerodynamic forces
|
// Calculate aerodynamic forces
|
||||||
store.forces = status.getSimulationConditions().getAerodynamicCalculator()
|
store.forces = status.getSimulationConditions().getAerodynamicCalculator()
|
||||||
@ -446,7 +447,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
* Additionally the fields thetaRotation and lateralPitchRate are defined in
|
* Additionally the fields thetaRotation and lateralPitchRate are defined in
|
||||||
* the data store, and can be used after calling this method.
|
* the data store, and can be used after calling this method.
|
||||||
*/
|
*/
|
||||||
private void calculateFlightConditions(RK4SimulationStatus status, DataStore store)
|
private void calculateFlightConditions(SimulationStatus status, DataStore store)
|
||||||
throws SimulationException {
|
throws SimulationException {
|
||||||
|
|
||||||
// Call pre listeners, allow complete override
|
// Call pre listeners, allow complete override
|
||||||
@ -555,6 +556,11 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
public Coordinate linearAcceleration;
|
public Coordinate linearAcceleration;
|
||||||
public Coordinate angularAcceleration;
|
public Coordinate angularAcceleration;
|
||||||
|
|
||||||
|
public Coordinate launchRodDirection = null;
|
||||||
|
|
||||||
|
public double maxZvelocity = Double.NaN;
|
||||||
|
public double startWarningTime = Double.NaN;
|
||||||
|
|
||||||
// set by calculateFlightConditions and calculateAcceleration:
|
// set by calculateFlightConditions and calculateAcceleration:
|
||||||
public AerodynamicForces forces;
|
public AerodynamicForces forces;
|
||||||
public double windSpeed = Double.NaN;
|
public double windSpeed = Double.NaN;
|
||||||
@ -568,7 +574,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
|
|||||||
|
|
||||||
public Rotation2D thetaRotation;
|
public Rotation2D thetaRotation;
|
||||||
|
|
||||||
void storeData(RK4SimulationStatus status) {
|
void storeData(SimulationStatus status) {
|
||||||
|
|
||||||
FlightDataBranch dataBranch = status.getFlightDataBranch();
|
FlightDataBranch dataBranch = status.getFlightDataBranch();
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SimulationStatus implements Monitorable {
|
public class SimulationStatus implements Cloneable, Monitorable {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(BasicEventSimulationEngine.class);
|
private static final Logger log = LoggerFactory.getLogger(BasicEventSimulationEngine.class);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user