1 package net.sf.openrocket.simulation;
3 import java.util.Arrays;
4 import java.util.Random;
6 import net.sf.openrocket.aerodynamics.AerodynamicForces;
7 import net.sf.openrocket.aerodynamics.FlightConditions;
8 import net.sf.openrocket.aerodynamics.WarningSet;
9 import net.sf.openrocket.logging.LogHelper;
10 import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
11 import net.sf.openrocket.simulation.exception.SimulationException;
12 import net.sf.openrocket.simulation.listeners.SimulationListenerHelper;
13 import net.sf.openrocket.startup.Application;
14 import net.sf.openrocket.util.Coordinate;
15 import net.sf.openrocket.util.MathUtil;
16 import net.sf.openrocket.util.Quaternion;
17 import net.sf.openrocket.util.Rotation2D;
20 public class RK4SimulationStepper extends AbstractSimulationStepper {
22 private static final LogHelper log = Application.getLogger();
26 * A recommended reasonably accurate time step.
28 public static final double RECOMMENDED_TIME_STEP = 0.05;
31 * A recommended maximum angle step value.
33 public static final double RECOMMENDED_ANGLE_STEP = 3 * Math.PI / 180;
36 * A random amount that is added to pitch and yaw coefficients, plus or minus.
38 public static final double PITCH_YAW_RANDOM = 0.0005;
41 * Maximum roll step allowed. This is selected as an uneven division of the full
42 * circle so that the simulation will sample the most wind directions
44 private static final double MAX_ROLL_STEP_ANGLE = 2 * 28.32 * Math.PI / 180;
45 // private static final double MAX_ROLL_STEP_ANGLE = 8.32 * Math.PI/180;
47 private static final double MAX_ROLL_RATE_CHANGE = 2 * Math.PI / 180;
48 private static final double MAX_PITCH_CHANGE = 4 * Math.PI / 180;
50 private static final double MIN_TIME_STEP = 0.001;
54 private final Random random = new Random();
60 public RK4SimulationStatus initialize(SimulationStatus original) {
62 log.info("Performing RK4SimulationStepper initialization");
64 RK4SimulationStatus status = new RK4SimulationStatus();
66 status.copyFrom(original);
68 SimulationConditions sim = original.getSimulationConditions();
69 status.setLaunchRodDirection(new Coordinate(
70 Math.sin(sim.getLaunchRodAngle()) * Math.cos(sim.getLaunchRodDirection()),
71 Math.sin(sim.getLaunchRodAngle()) * Math.sin(sim.getLaunchRodDirection()),
72 Math.cos(sim.getLaunchRodAngle())
82 public void step(SimulationStatus simulationStatus, double maxTimeStep) throws SimulationException {
84 RK4SimulationStatus status = (RK4SimulationStatus) simulationStatus;
85 DataStore store = new DataStore();
88 //////// Perform RK4 integration: ////////
90 RK4SimulationStatus status2;
91 RK4Parameters k1, k2, k3, k4;
94 * Start with previous time step which is used to compute the initial thrust estimate.
95 * Don't make it longer than maxTimeStep, but at least MIN_TIME_STEP.
97 store.timestep = status.getPreviousTimeStep();
98 store.timestep = MathUtil.max(MathUtil.min(store.timestep, maxTimeStep), MIN_TIME_STEP);
99 checkNaN(store.timestep);
102 * Compute the initial thrust estimate. This is used for the first time step computation.
104 store.thrustForce = calculateThrust(status, store.timestep, status.getPreviousAcceleration(),
105 status.getPreviousAtmosphericConditions(), false);
109 * Perform RK4 integration. Decide the time step length after the first step.
112 //// First position, k1 = f(t, y)
114 k1 = computeParameters(status, store);
117 * Select the actual time step to use. It is the minimum of the following:
118 * dt[0]: the user-specified time step (or 1/5th of it if still on the launch rod)
119 * dt[1]: the value of maxTimeStep
120 * dt[2]: the maximum pitch step angle limit
121 * dt[3]: the maximum roll step angle limit
122 * dt[4]: the maximum roll rate change limit
123 * dt[5]: the maximum pitch change limit
124 * dt[6]: 1/10th of the launch rod length if still on the launch rod
125 * dt[7]: 1.50 times the previous time step
127 * The limits #5 and #6 are required since near the steady-state roll rate the roll rate
128 * may oscillate significantly even between the sub-steps of the RK4 integration.
130 * The step is still at least 1/20th of the user-selected time step.
132 double[] dt = new double[8];
133 Arrays.fill(dt, Double.MAX_VALUE);
135 dt[0] = status.getSimulationConditions().getTimeStep();
137 dt[2] = status.getSimulationConditions().getMaximumAngleStep() / store.lateralPitchRate;
138 dt[3] = Math.abs(MAX_ROLL_STEP_ANGLE / store.flightConditions.getRollRate());
139 dt[4] = Math.abs(MAX_ROLL_RATE_CHANGE / store.rollAcceleration);
140 dt[5] = Math.abs(MAX_PITCH_CHANGE / store.lateralPitchAcceleration);
141 if (!status.isLaunchRodCleared()) {
143 dt[6] = status.getSimulationConditions().getLaunchRodLength() / k1.v.length() / 10;
145 dt[7] = 1.5 * status.getPreviousTimeStep();
147 store.timestep = Double.MAX_VALUE;
148 int limitingValue = -1;
149 for (int i = 0; i < dt.length; i++) {
150 if (dt[i] < store.timestep) {
151 store.timestep = dt[i];
156 double minTimeStep = status.getSimulationConditions().getTimeStep() / 20;
157 if (store.timestep < minTimeStep) {
158 log.debug("Too small time step " + store.timestep + " (limiting factor " + limitingValue + "), using " +
159 minTimeStep + " instead.");
160 store.timestep = minTimeStep;
162 log.debug("Selected time step " + store.timestep + " (limiting factor " + limitingValue + ")");
164 checkNaN(store.timestep);
167 * Compute the correct thrust for this time step. If the original thrust estimate differs more
168 * than 10% from the true value then recompute the RK4 step 1. The 10% error in step 1 is
169 * diminished by it affecting only 1/6th of the total, so it's an acceptable error.
171 double thrustEstimate = store.thrustForce;
172 store.thrustForce = calculateThrust(status, store.timestep, store.longitudalAcceleration,
173 store.atmosphericConditions, true);
174 double thrustDiff = Math.abs(store.thrustForce - thrustEstimate);
175 // Log if difference over 1%, recompute if over 10%
176 if (thrustDiff > 0.01 * thrustEstimate) {
177 if (thrustDiff > 0.1 * thrustEstimate + 0.001) {
178 log.info("Thrust estimate differs from correct value by " +
179 (Math.rint(1000 * (thrustDiff + 0.000001) / thrustEstimate) / 10.0) + "%," +
180 " estimate=" + thrustEstimate +
181 " correct=" + store.thrustForce +
182 " timestep=" + store.timestep +
183 ", recomputing k1 parameters");
184 k1 = computeParameters(status, store);
186 log.debug("Thrust estimate differs from correct value by " +
187 (Math.rint(1000 * (thrustDiff + 0.000001) / thrustEstimate) / 10.0) + "%," +
188 " estimate=" + thrustEstimate +
189 " correct=" + store.thrustForce +
190 " timestep=" + store.timestep +
191 ", error acceptable");
196 // TODO: MEDIUM: Store acceleration etc of entire RK4 step, store should be cloned or something...
197 storeData(status, store);
200 //// Second position, k2 = f(t + h/2, y + k1*h/2)
202 status2 = status.clone();
203 status2.setSimulationTime(status.getSimulationTime() + store.timestep / 2);
204 status2.setRocketPosition(status.getRocketPosition().add(k1.v.multiply(store.timestep / 2)));
205 status2.setRocketVelocity(status.getRocketVelocity().add(k1.a.multiply(store.timestep / 2)));
206 status2.setRocketOrientationQuaternion(status.getRocketOrientationQuaternion().multiplyLeft(Quaternion.rotation(k1.rv.multiply(store.timestep / 2))));
207 status2.setRocketRotationVelocity(status.getRocketRotationVelocity().add(k1.ra.multiply(store.timestep / 2)));
209 k2 = computeParameters(status2, store);
212 //// Third position, k3 = f(t + h/2, y + k2*h/2)
214 status2 = status.clone();
215 status2.setSimulationTime(status.getSimulationTime() + store.timestep / 2);
216 status2.setRocketPosition(status.getRocketPosition().add(k2.v.multiply(store.timestep / 2)));
217 status2.setRocketVelocity(status.getRocketVelocity().add(k2.a.multiply(store.timestep / 2)));
218 status2.setRocketOrientationQuaternion(status2.getRocketOrientationQuaternion().multiplyLeft(Quaternion.rotation(k2.rv.multiply(store.timestep / 2))));
219 status2.setRocketRotationVelocity(status.getRocketRotationVelocity().add(k2.ra.multiply(store.timestep / 2)));
221 k3 = computeParameters(status2, store);
224 //// Fourth position, k4 = f(t + h, y + k3*h)
226 status2 = status.clone();
227 status2.setSimulationTime(status.getSimulationTime() + store.timestep);
228 status2.setRocketPosition(status.getRocketPosition().add(k3.v.multiply(store.timestep)));
229 status2.setRocketVelocity(status.getRocketVelocity().add(k3.a.multiply(store.timestep)));
230 status2.setRocketOrientationQuaternion(status2.getRocketOrientationQuaternion().multiplyLeft(Quaternion.rotation(k3.rv.multiply(store.timestep))));
231 status2.setRocketRotationVelocity(status.getRocketRotationVelocity().add(k3.ra.multiply(store.timestep)));
233 k4 = computeParameters(status2, store);
236 //// Sum all together, y(n+1) = y(n) + h*(k1 + 2*k2 + 2*k3 + k4)/6
240 Coordinate deltaV, deltaP, deltaR, deltaO;
241 deltaV = k2.a.add(k3.a).multiply(2).add(k1.a).add(k4.a).multiply(store.timestep / 6);
242 deltaP = k2.v.add(k3.v).multiply(2).add(k1.v).add(k4.v).multiply(store.timestep / 6);
243 deltaR = k2.ra.add(k3.ra).multiply(2).add(k1.ra).add(k4.ra).multiply(store.timestep / 6);
244 deltaO = k2.rv.add(k3.rv).multiply(2).add(k1.rv).add(k4.rv).multiply(store.timestep / 6);
248 status.setRocketVelocity(status.getRocketVelocity().add(deltaV));
249 status.setRocketPosition(status.getRocketPosition().add(deltaP));
250 status.setRocketRotationVelocity(status.getRocketRotationVelocity().add(deltaR));
251 status.setRocketOrientationQuaternion(status.getRocketOrientationQuaternion().multiplyLeft(Quaternion.rotation(deltaO)).normalizeIfNecessary());
253 status.setSimulationTime(status.getSimulationTime() + store.timestep);
255 status.setPreviousTimeStep(store.timestep);
262 private RK4Parameters computeParameters(RK4SimulationStatus status, DataStore dataStore)
263 throws SimulationException {
264 RK4Parameters params = new RK4Parameters();
266 // if (dataStore == null) {
267 // dataStore = new DataStore();
270 calculateAcceleration(status, dataStore);
271 params.a = dataStore.linearAcceleration;
272 params.ra = dataStore.angularAcceleration;
273 params.v = status.getRocketVelocity();
274 params.rv = status.getRocketRotationVelocity();
289 * Calculate the linear and angular acceleration at the given status. The results
290 * are stored in the fields {@link #linearAcceleration} and {@link #angularAcceleration}.
292 * @param status the status of the rocket.
293 * @throws SimulationException
295 private void calculateAcceleration(RK4SimulationStatus status, DataStore store) throws SimulationException {
297 // Call pre-listeners
298 store.accelerationData = SimulationListenerHelper.firePreAccelerationCalculation(status);
299 if (store.accelerationData != null) {
303 // Compute the forces affecting the rocket
304 calculateForces(status, store);
306 // Calculate mass data
307 store.massData = calculateMassData(status);
310 // Calculate the forces from the aerodynamic coefficients
312 double dynP = (0.5 * store.flightConditions.getAtmosphericConditions().getDensity() *
313 MathUtil.pow2(store.flightConditions.getVelocity()));
314 double refArea = store.flightConditions.getRefArea();
315 double refLength = store.flightConditions.getRefLength();
318 // Linear forces in rocket coordinates
319 store.dragForce = store.forces.getCaxial() * dynP * refArea;
320 double fN = store.forces.getCN() * dynP * refArea;
321 double fSide = store.forces.getCside() * dynP * refArea;
323 double forceZ = store.thrustForce - store.dragForce;
325 store.linearAcceleration = new Coordinate(-fN / store.massData.getCG().weight,
326 -fSide / store.massData.getCG().weight,
327 forceZ / store.massData.getCG().weight);
329 store.linearAcceleration = store.thetaRotation.rotateZ(store.linearAcceleration);
331 // Convert into world coordinates and add effect of gravity
332 store.linearAcceleration = status.getRocketOrientationQuaternion().rotate(store.linearAcceleration);
334 store.gravity = modelGravity(status);
335 store.linearAcceleration = store.linearAcceleration.sub(0, 0, store.gravity);
338 // If still on the launch rod, project acceleration onto launch rod direction and
339 // set angular acceleration to zero.
340 if (!status.isLaunchRodCleared()) {
342 store.linearAcceleration = status.getLaunchRodDirection().multiply(
343 store.linearAcceleration.dot(status.getLaunchRodDirection()));
344 store.angularAcceleration = Coordinate.NUL;
345 store.rollAcceleration = 0;
346 store.lateralPitchAcceleration = 0;
350 // Shift moments to CG
351 double Cm = store.forces.getCm() - store.forces.getCN() * store.massData.getCG().x / refLength;
352 double Cyaw = store.forces.getCyaw() - store.forces.getCside() * store.massData.getCG().x / refLength;
355 double momX = -Cyaw * dynP * refArea * refLength;
356 double momY = Cm * dynP * refArea * refLength;
357 double momZ = store.forces.getCroll() * dynP * refArea * refLength;
359 // Compute acceleration in rocket coordinates
360 store.angularAcceleration = new Coordinate(momX / store.massData.getLongitudalInertia(),
361 momY / store.massData.getLongitudalInertia(), momZ / store.massData.getRotationalInertia());
363 store.rollAcceleration = store.angularAcceleration.z;
364 // TODO: LOW: This should be hypot, but does it matter?
365 store.lateralPitchAcceleration = MathUtil.max(Math.abs(store.angularAcceleration.x),
366 Math.abs(store.angularAcceleration.y));
368 store.angularAcceleration = store.thetaRotation.rotateZ(store.angularAcceleration);
370 // Convert to world coordinates
371 store.angularAcceleration = status.getRocketOrientationQuaternion().rotate(store.angularAcceleration);
375 // Call post-listeners
376 store.accelerationData = SimulationListenerHelper.firePostAccelerationCalculation(status, store.accelerationData);
382 * Calculate the aerodynamic forces into the data store. This method also handles
383 * whether to include aerodynamic computation warnings or not.
385 private void calculateForces(RK4SimulationStatus status, DataStore store) throws SimulationException {
387 // Call pre-listeners
388 store.forces = SimulationListenerHelper.firePreAerodynamicCalculation(status);
389 if (store.forces != null) {
393 // Compute flight conditions
394 calculateFlightConditions(status, store);
397 * Check whether to store warnings or not. Warnings are ignored when on the
398 * launch rod or 0.25 seconds after departure, and when the velocity has dropped
399 * below 20% of the max. velocity.
401 WarningSet warnings = status.getWarnings();
402 status.setMaxZVelocity(MathUtil.max(status.getMaxZVelocity(), status.getRocketVelocity().z));
404 if (!status.isLaunchRodCleared()) {
407 if (status.getRocketVelocity().z < 0.2 * status.getMaxZVelocity())
409 if (status.getStartWarningTime() < 0)
410 status.setStartWarningTime(status.getSimulationTime() + 0.25);
412 if (status.getSimulationTime() < status.getStartWarningTime())
415 System.out.println("flightConditions=" + store.flightConditions);
417 // Calculate aerodynamic forces
418 store.forces = status.getSimulationConditions().getAerodynamicCalculator()
419 .getAerodynamicForces(status.getConfiguration(), store.flightConditions, warnings);
421 System.out.println("CP=" + store.forces.getCP());
423 // Add very small randomization to yaw & pitch moments to prevent over-perfect flight
424 // TODO: HIGH: This should rather be performed as a listener
425 store.forces.setCm(store.forces.getCm() + (PITCH_YAW_RANDOM * 2 * (random.nextDouble() - 0.5)));
426 store.forces.setCyaw(store.forces.getCyaw() + (PITCH_YAW_RANDOM * 2 * (random.nextDouble() - 0.5)));
429 // Call post-listeners
430 store.forces = SimulationListenerHelper.firePostAerodynamicCalculation(status, store.forces);
436 * Calculate and return the flight conditions for the current rocket status.
437 * Listeners can override these if necessary.
439 * Additionally the fields thetaRotation and lateralPitchRate are defined in
440 * the data store, and can be used after calling this method.
442 private void calculateFlightConditions(RK4SimulationStatus status, DataStore store)
443 throws SimulationException {
445 // Call pre listeners, allow complete override
446 store.flightConditions = SimulationListenerHelper.firePreFlightConditions(
448 if (store.flightConditions != null) {
449 // Compute the store values
450 store.thetaRotation = new Rotation2D(store.flightConditions.getTheta());
451 store.lateralPitchRate = Math.hypot(store.flightConditions.getPitchRate(), store.flightConditions.getYawRate());
457 //// Atmospheric conditions
458 AtmosphericConditions atmosphere = modelAtmosphericConditions(status);
459 store.flightConditions = new FlightConditions(status.getConfiguration());
460 store.flightConditions.setAtmosphericConditions(atmosphere);
463 //// Local wind speed and direction
464 Coordinate windSpeed = modelWindVelocity(status);
465 Coordinate airSpeed = status.getRocketVelocity().add(windSpeed);
466 airSpeed = status.getRocketOrientationQuaternion().invRotate(airSpeed);
469 // Lateral direction:
470 double len = MathUtil.hypot(airSpeed.x, airSpeed.y);
472 store.thetaRotation = new Rotation2D(airSpeed.y / len, airSpeed.x / len);
473 store.flightConditions.setTheta(Math.atan2(airSpeed.y, airSpeed.x));
475 store.thetaRotation = Rotation2D.ID;
476 store.flightConditions.setTheta(0);
479 double velocity = airSpeed.length();
480 store.flightConditions.setVelocity(velocity);
481 if (velocity > 0.01) {
482 // aoa must be calculated from the monotonous cosine
483 // sine can be calculated by a simple division
484 store.flightConditions.setAOA(Math.acos(airSpeed.z / velocity), len / velocity);
486 store.flightConditions.setAOA(0);
490 // Roll, pitch and yaw rate
491 Coordinate rot = status.getRocketOrientationQuaternion().invRotate(status.getRocketRotationVelocity());
492 rot = store.thetaRotation.invRotateZ(rot);
494 store.flightConditions.setRollRate(rot.z);
496 store.flightConditions.setPitchRate(0);
497 store.flightConditions.setYawRate(0);
498 store.lateralPitchRate = 0;
500 store.flightConditions.setPitchRate(rot.y);
501 store.flightConditions.setYawRate(rot.x);
502 // TODO: LOW: set this as power of two?
503 store.lateralPitchRate = MathUtil.hypot(rot.x, rot.y);
507 // Call post listeners
508 FlightConditions c = SimulationListenerHelper.firePostFlightConditions(
509 status, store.flightConditions);
510 if (c != store.flightConditions) {
511 // Listeners changed the values, recalculate data store
512 store.flightConditions = c;
513 store.thetaRotation = new Rotation2D(store.flightConditions.getTheta());
514 store.lateralPitchRate = Math.hypot(store.flightConditions.getPitchRate(), store.flightConditions.getYawRate());
521 private void storeData(RK4SimulationStatus status, DataStore store) {
523 FlightDataBranch data = status.getFlightData();
524 boolean extra = status.getSimulationConditions().isCalculateExtras();
527 data.setValue(FlightDataType.TYPE_TIME, status.getSimulationTime());
528 data.setValue(FlightDataType.TYPE_ALTITUDE, status.getRocketPosition().z);
529 data.setValue(FlightDataType.TYPE_POSITION_X, status.getRocketPosition().x);
530 data.setValue(FlightDataType.TYPE_POSITION_Y, status.getRocketPosition().y);
533 data.setValue(FlightDataType.TYPE_POSITION_XY,
534 MathUtil.hypot(status.getRocketPosition().x, status.getRocketPosition().y));
535 data.setValue(FlightDataType.TYPE_POSITION_DIRECTION,
536 Math.atan2(status.getRocketPosition().y, status.getRocketPosition().x));
538 data.setValue(FlightDataType.TYPE_VELOCITY_XY,
539 MathUtil.hypot(status.getRocketVelocity().x, status.getRocketVelocity().y));
541 if (store.linearAcceleration != null) {
542 data.setValue(FlightDataType.TYPE_ACCELERATION_XY,
543 MathUtil.hypot(store.linearAcceleration.x, store.linearAcceleration.y));
545 data.setValue(FlightDataType.TYPE_ACCELERATION_TOTAL, store.linearAcceleration.length());
548 if (store.flightConditions != null) {
549 double Re = (store.flightConditions.getVelocity() *
550 status.getConfiguration().getLength() /
551 store.flightConditions.getAtmosphericConditions().getKinematicViscosity());
552 data.setValue(FlightDataType.TYPE_REYNOLDS_NUMBER, Re);
556 data.setValue(FlightDataType.TYPE_VELOCITY_Z, status.getRocketVelocity().z);
557 if (store.linearAcceleration != null) {
558 data.setValue(FlightDataType.TYPE_ACCELERATION_Z, store.linearAcceleration.z);
561 if (store.flightConditions != null) {
562 data.setValue(FlightDataType.TYPE_VELOCITY_TOTAL, store.flightConditions.getVelocity());
563 data.setValue(FlightDataType.TYPE_MACH_NUMBER, store.flightConditions.getMach());
566 if (store.massData != null) {
567 data.setValue(FlightDataType.TYPE_CG_LOCATION, store.massData.getCG().x);
569 if (status.isLaunchRodCleared()) {
570 // Don't include CP and stability with huge launch AOA
571 if (store.forces != null) {
572 data.setValue(FlightDataType.TYPE_CP_LOCATION, store.forces.getCP().x);
574 if (store.forces != null && store.flightConditions != null && store.massData != null) {
575 data.setValue(FlightDataType.TYPE_STABILITY,
576 (store.forces.getCP().x - store.massData.getCG().x) / store.flightConditions.getRefLength());
579 if (store.massData != null) {
580 data.setValue(FlightDataType.TYPE_MASS, store.massData.getCG().weight);
583 data.setValue(FlightDataType.TYPE_THRUST_FORCE, store.thrustForce);
584 data.setValue(FlightDataType.TYPE_DRAG_FORCE, store.dragForce);
586 if (status.isLaunchRodCleared() && store.forces != null) {
587 if (store.massData != null && store.flightConditions != null) {
588 data.setValue(FlightDataType.TYPE_PITCH_MOMENT_COEFF,
589 store.forces.getCm() - store.forces.getCN() * store.massData.getCG().x / store.flightConditions.getRefLength());
590 data.setValue(FlightDataType.TYPE_YAW_MOMENT_COEFF,
591 store.forces.getCyaw() - store.forces.getCside() * store.massData.getCG().x / store.flightConditions.getRefLength());
593 data.setValue(FlightDataType.TYPE_NORMAL_FORCE_COEFF, store.forces.getCN());
594 data.setValue(FlightDataType.TYPE_SIDE_FORCE_COEFF, store.forces.getCside());
595 data.setValue(FlightDataType.TYPE_ROLL_MOMENT_COEFF, store.forces.getCroll());
596 data.setValue(FlightDataType.TYPE_ROLL_FORCING_COEFF, store.forces.getCrollForce());
597 data.setValue(FlightDataType.TYPE_ROLL_DAMPING_COEFF, store.forces.getCrollDamp());
598 data.setValue(FlightDataType.TYPE_PITCH_DAMPING_MOMENT_COEFF,
599 store.forces.getPitchDampingMoment());
602 if (store.forces != null) {
603 data.setValue(FlightDataType.TYPE_DRAG_COEFF, store.forces.getCD());
604 data.setValue(FlightDataType.TYPE_AXIAL_DRAG_COEFF, store.forces.getCaxial());
605 data.setValue(FlightDataType.TYPE_FRICTION_DRAG_COEFF, store.forces.getFrictionCD());
606 data.setValue(FlightDataType.TYPE_PRESSURE_DRAG_COEFF, store.forces.getPressureCD());
607 data.setValue(FlightDataType.TYPE_BASE_DRAG_COEFF, store.forces.getBaseCD());
610 if (store.flightConditions != null) {
611 data.setValue(FlightDataType.TYPE_REFERENCE_LENGTH, store.flightConditions.getRefLength());
612 data.setValue(FlightDataType.TYPE_REFERENCE_AREA, store.flightConditions.getRefArea());
614 data.setValue(FlightDataType.TYPE_PITCH_RATE, store.flightConditions.getPitchRate());
615 data.setValue(FlightDataType.TYPE_YAW_RATE, store.flightConditions.getYawRate());
616 data.setValue(FlightDataType.TYPE_ROLL_RATE, store.flightConditions.getRollRate());
618 data.setValue(FlightDataType.TYPE_AOA, store.flightConditions.getAOA());
623 Coordinate c = status.getRocketOrientationQuaternion().rotateZ();
624 double theta = Math.atan2(c.z, MathUtil.hypot(c.x, c.y));
625 double phi = Math.atan2(c.y, c.x);
626 if (phi < -(Math.PI - 0.0001))
628 data.setValue(FlightDataType.TYPE_ORIENTATION_THETA, theta);
629 data.setValue(FlightDataType.TYPE_ORIENTATION_PHI, phi);
632 data.setValue(FlightDataType.TYPE_WIND_VELOCITY, store.windSpeed);
634 if (store.flightConditions != null) {
635 data.setValue(FlightDataType.TYPE_AIR_TEMPERATURE,
636 store.flightConditions.getAtmosphericConditions().getTemperature());
637 data.setValue(FlightDataType.TYPE_AIR_PRESSURE,
638 store.flightConditions.getAtmosphericConditions().getPressure());
639 data.setValue(FlightDataType.TYPE_SPEED_OF_SOUND,
640 store.flightConditions.getAtmosphericConditions().getMachSpeed());
644 data.setValue(FlightDataType.TYPE_TIME_STEP, store.timestep);
645 data.setValue(FlightDataType.TYPE_COMPUTATION_TIME,
646 (System.nanoTime() - status.getSimulationStartWallTime()) / 1000000000.0);
652 private static class RK4Parameters {
653 /** Linear acceleration */
655 /** Linear velocity */
657 /** Rotational acceleration */
658 public Coordinate ra;
659 /** Rotational velocity */
660 public Coordinate rv;
663 private static class DataStore {
664 public double timestep = Double.NaN;
666 public AccelerationData accelerationData;
668 public AtmosphericConditions atmosphericConditions;
670 public FlightConditions flightConditions;
672 public double longitudalAcceleration = Double.NaN;
674 public MassData massData;
676 public Coordinate linearAcceleration;
677 public Coordinate angularAcceleration;
679 // set by calculateFlightConditions and calculateAcceleration:
680 public AerodynamicForces forces;
681 public double windSpeed = Double.NaN;
682 public double gravity = Double.NaN;
683 public double thrustForce = Double.NaN;
684 public double dragForce = Double.NaN;
685 public double lateralPitchRate = Double.NaN;
687 public double rollAcceleration = Double.NaN;
688 public double lateralPitchAcceleration = Double.NaN;
690 public Rotation2D thetaRotation;