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
store.accelerationData = SimulationListenerHelper.firePostAccelerationCalculation(status, store.accelerationData);
params.a = dataStore.linearAcceleration;
params.ra = dataStore.angularAcceleration;
params.a = dataStore.accelerationData.getLinearAccelerationWC();
params.ra = dataStore.accelerationData.getRotationalAccelerationWC();
params.v = status.getRocketVelocity();
params.rv = status.getRocketRotationVelocity();
@ -298,7 +298,9 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
* @throws SimulationException
*/
private AccelerationData calculateAcceleration(SimulationStatus status, DataStore store) throws SimulationException {
Coordinate linearAcceleration;
Coordinate angularAcceleration;
// Compute the forces affecting the rocket
calculateForces(status, store);
@ -328,30 +330,30 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
store.thrustForce = calculateThrust(status, store, false);
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(),
forceZ / store.rocketMass.getMass());
store.linearAcceleration = store.thetaRotation.rotateZ(store.linearAcceleration);
linearAcceleration = store.thetaRotation.rotateZ(linearAcceleration);
// Convert into rocket world coordinates
store.linearAcceleration = status.getRocketOrientationQuaternion().rotate(store.linearAcceleration);
linearAcceleration = status.getRocketOrientationQuaternion().rotate(linearAcceleration);
// add effect of gravity
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
store.coriolisAcceleration = status.getSimulationConditions().getGeodeticComputation()
.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
// set angular acceleration to zero.
if (!status.isLaunchRodCleared()) {
store.linearAcceleration = store.launchRodDirection.multiply(store.linearAcceleration.dot(store.launchRodDirection));
store.angularAcceleration = Coordinate.NUL;
linearAcceleration = store.launchRodDirection.multiply(linearAcceleration.dot(store.launchRodDirection));
angularAcceleration = Coordinate.NUL;
store.rollAcceleration = 0;
store.lateralPitchAcceleration = 0;
@ -367,23 +369,23 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
double momZ = store.forces.getCroll() * dynP * refArea * refLength;
// Compute acceleration in rocket coordinates
store.angularAcceleration = new Coordinate(momX / store.rocketMass.getLongitudinalInertia(),
angularAcceleration = new Coordinate(momX / store.rocketMass.getLongitudinalInertia(),
momY / store.rocketMass.getLongitudinalInertia(),
momZ / store.rocketMass.getRotationalInertia());
store.rollAcceleration = store.angularAcceleration.z;
store.rollAcceleration = angularAcceleration.z;
// TODO: LOW: This should be hypot, but does it matter?
store.lateralPitchAcceleration = MathUtil.max(Math.abs(store.angularAcceleration.x),
Math.abs(store.angularAcceleration.y));
store.lateralPitchAcceleration = MathUtil.max(Math.abs(angularAcceleration.x),
Math.abs(angularAcceleration.y));
store.angularAcceleration = store.thetaRotation.rotateZ(store.angularAcceleration);
angularAcceleration = store.thetaRotation.rotateZ(angularAcceleration);
// 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());
}