1 package net.sf.openrocket.simulation;
3 import java.util.ArrayList;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.util.MathUtil;
10 public class FlightData {
13 * An immutable FlightData object with NaN data.
15 public static final FlightData NaN_DATA;
17 FlightData data = new FlightData();
22 private boolean mutable = true;
23 private final ArrayList<FlightDataBranch> branches = new ArrayList<FlightDataBranch>();
25 private final WarningSet warnings = new WarningSet();
27 private double maxAltitude = Double.NaN;
28 private double maxVelocity = Double.NaN;
29 private double maxAcceleration = Double.NaN;
30 private double maxMachNumber = Double.NaN;
31 private double timeToApogee = Double.NaN;
32 private double flightTime = Double.NaN;
33 private double groundHitVelocity = Double.NaN;
37 * Create a FlightData object with no content. The resulting object is mutable.
45 * Construct an immutable FlightData object with no data branches but the specified
46 * summary information.
48 * @param maxAltitude maximum altitude.
49 * @param maxVelocity maximum velocity.
50 * @param maxAcceleration maximum acceleration.
51 * @param maxMachNumber maximum Mach number.
52 * @param timeToApogee time to apogee.
53 * @param flightTime total flight time.
54 * @param groundHitVelocity ground hit velocity.
56 public FlightData(double maxAltitude, double maxVelocity, double maxAcceleration,
57 double maxMachNumber, double timeToApogee, double flightTime,
58 double groundHitVelocity) {
59 this.maxAltitude = maxAltitude;
60 this.maxVelocity = maxVelocity;
61 this.maxAcceleration = maxAcceleration;
62 this.maxMachNumber = maxMachNumber;
63 this.timeToApogee = timeToApogee;
64 this.flightTime = flightTime;
65 this.groundHitVelocity = groundHitVelocity;
72 * Create an immutable FlightData object with the specified branches.
74 * @param branches the branches.
76 public FlightData(FlightDataBranch ... branches) {
79 for (FlightDataBranch b: branches)
82 calculateIntrestingValues();
90 * Returns the warning set associated with this object. This WarningSet cannot be
91 * set, so simulations must use this warning set to store their warnings.
92 * The returned WarningSet should not be modified otherwise.
94 * @return the warnings generated during this simulation.
96 public WarningSet getWarningSet() {
101 public void addBranch(FlightDataBranch branch) {
103 throw new IllegalStateException("FlightData has been made immutable");
106 branches.add(branch);
108 if (branches.size() == 1) {
109 calculateIntrestingValues();
113 public int getBranchCount() {
114 return branches.size();
117 public FlightDataBranch getBranch(int n) {
118 return branches.get(n);
123 public double getMaxAltitude() {
127 public double getMaxVelocity() {
131 public double getMaxAcceleration() {
132 return maxAcceleration;
135 public double getMaxMachNumber() {
136 return maxMachNumber;
139 public double getTimeToApogee() {
143 public double getFlightTime() {
147 public double getGroundHitVelocity() {
148 return groundHitVelocity;
154 * Calculate the max. altitude/velocity/acceleration, time to apogee, flight time
155 * and ground hit velocity.
157 private void calculateIntrestingValues() {
158 if (branches.isEmpty())
161 FlightDataBranch branch = branches.get(0);
162 maxAltitude = branch.getMaximum(FlightDataBranch.TYPE_ALTITUDE);
163 maxVelocity = branch.getMaximum(FlightDataBranch.TYPE_VELOCITY_TOTAL);
164 maxAcceleration = branch.getMaximum(FlightDataBranch.TYPE_ACCELERATION_TOTAL);
165 maxMachNumber = branch.getMaximum(FlightDataBranch.TYPE_MACH_NUMBER);
167 flightTime = branch.getLast(FlightDataBranch.TYPE_TIME);
168 if (branch.getLast(FlightDataBranch.TYPE_ALTITUDE) < 10) {
169 groundHitVelocity = branch.getLast(FlightDataBranch.TYPE_VELOCITY_TOTAL);
171 groundHitVelocity = Double.NaN;
175 List<Double> time = branch.get(FlightDataBranch.TYPE_TIME);
176 List<Double> altitude = branch.get(FlightDataBranch.TYPE_ALTITUDE);
178 if (time == null || altitude == null) {
179 timeToApogee = Double.NaN;
183 for (Double alt: altitude) {
185 if (MathUtil.equals(alt, maxAltitude))
191 if (index < time.size())
192 timeToApogee = time.get(index);
194 timeToApogee = Double.NaN;
198 public void immute() {
201 public boolean isMutable() {