1 package net.sf.openrocket.simulation;
3 import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
4 import net.sf.openrocket.rocketcomponent.RecoveryDevice;
5 import net.sf.openrocket.simulation.exception.SimulationException;
6 import net.sf.openrocket.util.Coordinate;
7 import net.sf.openrocket.util.MathUtil;
9 public class BasicLandingStepper extends AbstractSimulationStepper {
11 private static final double RECOVERY_TIME_STEP = 0.5;
13 // FIXME: Add lat/lon code here as well
16 public SimulationStatus initialize(SimulationStatus status) throws SimulationException {
21 public void step(SimulationStatus status, double maxTimeStep) throws SimulationException {
23 double refArea = status.getConfiguration().getReferenceArea();
25 // Get the atmospheric conditions
26 AtmosphericConditions atmosphere = modelAtmosphericConditions(status);
28 //// Local wind speed and direction
29 Coordinate windSpeed = modelWindVelocity(status);
30 Coordinate airSpeed = status.getRocketVelocity().add(windSpeed);
33 double mach = airSpeed.length() / atmosphere.getMachSpeed();
34 for (RecoveryDevice c : status.getDeployedRecoveryDevices()) {
35 totalCD += c.getCD(mach) * c.getArea() / refArea;
39 double dynP = (0.5 * atmosphere.getDensity() * airSpeed.length2());
40 double dragForce = totalCD * dynP * refArea;
41 MassData massData = calculateMassData(status);
42 double mass = massData.getCG().weight;
45 // Compute drag acceleration
46 Coordinate linearAcceleration;
47 if (airSpeed.length() > 0.001) {
48 linearAcceleration = airSpeed.normalize().multiply(-dragForce / mass);
50 linearAcceleration = Coordinate.NUL;
53 // Add effect of gravity
54 double gravity = modelGravity(status);
55 linearAcceleration = linearAcceleration.sub(0, 0, gravity);
59 double timeStep = MathUtil.min(0.5 / linearAcceleration.length(), RECOVERY_TIME_STEP);
61 // Perform Euler integration
62 status.setRocketPosition(status.getRocketPosition().add(status.getRocketVelocity().multiply(timeStep)).
63 add(linearAcceleration.multiply(MathUtil.pow2(timeStep) / 2)));
64 status.setRocketVelocity(status.getRocketVelocity().add(linearAcceleration.multiply(timeStep)));
65 status.setSimulationTime(status.getSimulationTime() + timeStep);
69 FlightDataBranch data = status.getFlightData();
70 boolean extra = status.getSimulationConditions().isCalculateExtras();
73 data.setValue(FlightDataType.TYPE_TIME, status.getSimulationTime());
74 data.setValue(FlightDataType.TYPE_ALTITUDE, status.getRocketPosition().z);
75 data.setValue(FlightDataType.TYPE_POSITION_X, status.getRocketPosition().x);
76 data.setValue(FlightDataType.TYPE_POSITION_Y, status.getRocketPosition().y);
78 data.setValue(FlightDataType.TYPE_POSITION_XY,
79 MathUtil.hypot(status.getRocketPosition().x, status.getRocketPosition().y));
80 data.setValue(FlightDataType.TYPE_POSITION_DIRECTION,
81 Math.atan2(status.getRocketPosition().y, status.getRocketPosition().x));
83 data.setValue(FlightDataType.TYPE_VELOCITY_XY,
84 MathUtil.hypot(status.getRocketVelocity().x, status.getRocketVelocity().y));
85 data.setValue(FlightDataType.TYPE_ACCELERATION_XY,
86 MathUtil.hypot(linearAcceleration.x, linearAcceleration.y));
88 data.setValue(FlightDataType.TYPE_ACCELERATION_TOTAL, linearAcceleration.length());
90 double Re = airSpeed.length() *
91 status.getConfiguration().getLength() /
92 atmosphere.getKinematicViscosity();
93 data.setValue(FlightDataType.TYPE_REYNOLDS_NUMBER, Re);
96 data.setValue(FlightDataType.TYPE_VELOCITY_Z, status.getRocketVelocity().z);
97 data.setValue(FlightDataType.TYPE_ACCELERATION_Z, linearAcceleration.z);
99 data.setValue(FlightDataType.TYPE_VELOCITY_TOTAL, airSpeed.length());
100 data.setValue(FlightDataType.TYPE_MACH_NUMBER, mach);
102 data.setValue(FlightDataType.TYPE_MASS, mass);
104 data.setValue(FlightDataType.TYPE_THRUST_FORCE, 0);
105 data.setValue(FlightDataType.TYPE_DRAG_FORCE, dragForce);
107 data.setValue(FlightDataType.TYPE_WIND_VELOCITY, windSpeed.length());
108 data.setValue(FlightDataType.TYPE_AIR_TEMPERATURE, atmosphere.getTemperature());
109 data.setValue(FlightDataType.TYPE_AIR_PRESSURE, atmosphere.getPressure());
110 data.setValue(FlightDataType.TYPE_SPEED_OF_SOUND, atmosphere.getMachSpeed());
112 data.setValue(FlightDataType.TYPE_TIME_STEP, timeStep);
113 data.setValue(FlightDataType.TYPE_COMPUTATION_TIME,
114 (System.nanoTime() - status.getSimulationStartWallTime()) / 1000000000.0);