Don't use store.linearAcceleration and store.angularAcceleration in RK4SimulationStepper. Use local variables in calculateAcceleration, and pull values out of store.accelerationData, instead

This commit is contained in:
JoePfeiffer 2024-07-12 09:25:05 -06:00
parent 96f0985100
commit e07eaf7297

View File

@ -273,8 +273,8 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
// Call post-listeners // Call post-listeners
store.accelerationData = SimulationListenerHelper.firePostAccelerationCalculation(status, store.accelerationData); store.accelerationData = SimulationListenerHelper.firePostAccelerationCalculation(status, store.accelerationData);
params.a = dataStore.linearAcceleration; params.a = dataStore.accelerationData.getLinearAccelerationWC();
params.ra = dataStore.angularAcceleration; params.ra = dataStore.accelerationData.getRotationalAccelerationWC();
params.v = status.getRocketVelocity(); params.v = status.getRocketVelocity();
params.rv = status.getRocketRotationVelocity(); params.rv = status.getRocketRotationVelocity();
@ -298,6 +298,8 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
* @throws SimulationException * @throws SimulationException
*/ */
private AccelerationData calculateAcceleration(SimulationStatus status, DataStore store) throws SimulationException { private AccelerationData calculateAcceleration(SimulationStatus status, DataStore store) throws SimulationException {
Coordinate linearAcceleration;
Coordinate angularAcceleration;
// Compute the forces affecting the rocket // Compute the forces affecting the rocket
calculateForces(status, store); calculateForces(status, store);
@ -328,30 +330,30 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
store.thrustForce = calculateThrust(status, store, false); store.thrustForce = calculateThrust(status, store, false);
double forceZ = store.thrustForce - store.dragForce; double forceZ = store.thrustForce - store.dragForce;
store.linearAcceleration = new Coordinate(-fN / store.rocketMass.getMass(), linearAcceleration = new Coordinate(-fN / store.rocketMass.getMass(),
-fSide / store.rocketMass.getMass(), -fSide / store.rocketMass.getMass(),
forceZ / store.rocketMass.getMass()); forceZ / store.rocketMass.getMass());
store.linearAcceleration = store.thetaRotation.rotateZ(store.linearAcceleration); linearAcceleration = store.thetaRotation.rotateZ(linearAcceleration);
// Convert into rocket world coordinates // Convert into rocket world coordinates
store.linearAcceleration = status.getRocketOrientationQuaternion().rotate(store.linearAcceleration); linearAcceleration = status.getRocketOrientationQuaternion().rotate(linearAcceleration);
// add effect of gravity // add effect of gravity
store.gravity = modelGravity(status); store.gravity = modelGravity(status);
store.linearAcceleration = store.linearAcceleration.sub(0, 0, store.gravity); linearAcceleration = linearAcceleration.sub(0, 0, store.gravity);
// add effect of Coriolis acceleration // add effect of Coriolis acceleration
store.coriolisAcceleration = status.getSimulationConditions().getGeodeticComputation() store.coriolisAcceleration = status.getSimulationConditions().getGeodeticComputation()
.getCoriolisAcceleration(status.getRocketWorldPosition(), status.getRocketVelocity()); .getCoriolisAcceleration(status.getRocketWorldPosition(), status.getRocketVelocity());
store.linearAcceleration = store.linearAcceleration.add(store.coriolisAcceleration); linearAcceleration = linearAcceleration.add(store.coriolisAcceleration);
// If still on the launch rod, project acceleration onto launch rod direction and // If still on the launch rod, project acceleration onto launch rod direction and
// set angular acceleration to zero. // set angular acceleration to zero.
if (!status.isLaunchRodCleared()) { if (!status.isLaunchRodCleared()) {
store.linearAcceleration = store.launchRodDirection.multiply(store.linearAcceleration.dot(store.launchRodDirection)); linearAcceleration = store.launchRodDirection.multiply(linearAcceleration.dot(store.launchRodDirection));
store.angularAcceleration = Coordinate.NUL; angularAcceleration = Coordinate.NUL;
store.rollAcceleration = 0; store.rollAcceleration = 0;
store.lateralPitchAcceleration = 0; store.lateralPitchAcceleration = 0;
@ -367,23 +369,23 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
double momZ = store.forces.getCroll() * dynP * refArea * refLength; double momZ = store.forces.getCroll() * dynP * refArea * refLength;
// Compute acceleration in rocket coordinates // Compute acceleration in rocket coordinates
store.angularAcceleration = new Coordinate(momX / store.rocketMass.getLongitudinalInertia(), angularAcceleration = new Coordinate(momX / store.rocketMass.getLongitudinalInertia(),
momY / store.rocketMass.getLongitudinalInertia(), momY / store.rocketMass.getLongitudinalInertia(),
momZ / store.rocketMass.getRotationalInertia()); momZ / store.rocketMass.getRotationalInertia());
store.rollAcceleration = store.angularAcceleration.z; store.rollAcceleration = angularAcceleration.z;
// TODO: LOW: This should be hypot, but does it matter? // TODO: LOW: This should be hypot, but does it matter?
store.lateralPitchAcceleration = MathUtil.max(Math.abs(store.angularAcceleration.x), store.lateralPitchAcceleration = MathUtil.max(Math.abs(angularAcceleration.x),
Math.abs(store.angularAcceleration.y)); Math.abs(angularAcceleration.y));
store.angularAcceleration = store.thetaRotation.rotateZ(store.angularAcceleration); angularAcceleration = store.thetaRotation.rotateZ(angularAcceleration);
// Convert to world coordinates // Convert to world coordinates
store.angularAcceleration = status.getRocketOrientationQuaternion().rotate(store.angularAcceleration); angularAcceleration = status.getRocketOrientationQuaternion().rotate(angularAcceleration);
} }
return new AccelerationData(null, null, store.linearAcceleration, store.angularAcceleration, status.getRocketOrientationQuaternion()); return new AccelerationData(null, null, linearAcceleration, angularAcceleration, status.getRocketOrientationQuaternion());
} }