1 package net.sf.openrocket.simulation;
3 import java.util.ArrayList;
6 import net.sf.openrocket.unit.UnitGroup;
9 * A class defining a storable simulation variable type. This class defined numerous ready
10 * types, and allows also creating new types with any name. When retrieving types based on
11 * a name, you should use {@link #getType(String, UnitGroup)} to return the default unit type,
12 * or a new type if the name does not currently exist.
14 * Each type has a type name (description) and a unit group. The type is identified purely by its name.
16 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
18 public class FlightDataType implements Comparable<FlightDataType> {
20 /** Priority of custom-created variables */
21 private static final int DEFAULT_PRIORITY = 999;
23 /** List of existing types. MUST BE DEFINED BEFORE ANY TYPES!! */
24 private static final List<FlightDataType> EXISTING_TYPES = new ArrayList<FlightDataType>();
29 public static final FlightDataType TYPE_TIME =
30 newType("Time", UnitGroup.UNITS_FLIGHT_TIME, 1);
33 //// Vertical position and motion
34 public static final FlightDataType TYPE_ALTITUDE =
35 newType("Altitude", UnitGroup.UNITS_DISTANCE, 10);
36 public static final FlightDataType TYPE_VELOCITY_Z =
37 newType("Vertical velocity", UnitGroup.UNITS_VELOCITY, 11);
38 public static final FlightDataType TYPE_ACCELERATION_Z =
39 newType("Vertical acceleration", UnitGroup.UNITS_ACCELERATION, 12);
43 public static final FlightDataType TYPE_VELOCITY_TOTAL =
44 newType("Total velocity", UnitGroup.UNITS_VELOCITY, 20);
45 public static final FlightDataType TYPE_ACCELERATION_TOTAL =
46 newType("Total acceleration", UnitGroup.UNITS_ACCELERATION, 21);
49 //// Lateral position and motion
51 public static final FlightDataType TYPE_POSITION_X =
52 newType("Position upwind", UnitGroup.UNITS_DISTANCE, 30);
53 public static final FlightDataType TYPE_POSITION_Y =
54 newType("Position parallel to wind", UnitGroup.UNITS_DISTANCE, 31);
55 public static final FlightDataType TYPE_POSITION_XY =
56 newType("Lateral distance", UnitGroup.UNITS_DISTANCE, 32);
57 public static final FlightDataType TYPE_POSITION_DIRECTION =
58 newType("Lateral direction", UnitGroup.UNITS_ANGLE, 33);
60 public static final FlightDataType TYPE_VELOCITY_XY =
61 newType("Lateral velocity", UnitGroup.UNITS_VELOCITY, 34);
62 public static final FlightDataType TYPE_ACCELERATION_XY =
63 newType("Lateral acceleration", UnitGroup.UNITS_ACCELERATION, 35);
67 public static final FlightDataType TYPE_AOA = newType("Angle of attack", UnitGroup.UNITS_ANGLE, 40);
68 public static final FlightDataType TYPE_ROLL_RATE = newType("Roll rate", UnitGroup.UNITS_ROLL, 41);
69 public static final FlightDataType TYPE_PITCH_RATE = newType("Pitch rate", UnitGroup.UNITS_ROLL, 42);
70 public static final FlightDataType TYPE_YAW_RATE = newType("Yaw rate", UnitGroup.UNITS_ROLL, 43);
73 //// Stability information
74 public static final FlightDataType TYPE_MASS =
75 newType("Mass", UnitGroup.UNITS_MASS, 50);
76 public static final FlightDataType TYPE_CP_LOCATION =
77 newType("CP location", UnitGroup.UNITS_LENGTH, 51);
78 public static final FlightDataType TYPE_CG_LOCATION =
79 newType("CG location", UnitGroup.UNITS_LENGTH, 52);
80 public static final FlightDataType TYPE_STABILITY =
81 newType("Stability margin calibers", UnitGroup.UNITS_COEFFICIENT, 53);
82 // TODO: HIGH: Add moment of inertia
85 //// Characteristic numbers
86 public static final FlightDataType TYPE_MACH_NUMBER =
87 newType("Mach number", UnitGroup.UNITS_COEFFICIENT, 60);
88 public static final FlightDataType TYPE_REYNOLDS_NUMBER =
89 newType("Reynolds number", UnitGroup.UNITS_COEFFICIENT, 61);
93 public static final FlightDataType TYPE_THRUST_FORCE =
94 newType("Thrust", UnitGroup.UNITS_FORCE, 70);
95 public static final FlightDataType TYPE_DRAG_FORCE =
96 newType("Drag force", UnitGroup.UNITS_FORCE, 71);
98 public static final FlightDataType TYPE_DRAG_COEFF =
99 newType("Drag coefficient", UnitGroup.UNITS_COEFFICIENT, 72);
100 public static final FlightDataType TYPE_AXIAL_DRAG_COEFF =
101 newType("Axial drag coefficient", UnitGroup.UNITS_COEFFICIENT, 73);
104 //// Component drag coefficients
105 public static final FlightDataType TYPE_FRICTION_DRAG_COEFF =
106 newType("Friction drag coefficient", UnitGroup.UNITS_COEFFICIENT, 80);
107 public static final FlightDataType TYPE_PRESSURE_DRAG_COEFF =
108 newType("Pressure drag coefficient", UnitGroup.UNITS_COEFFICIENT, 81);
109 public static final FlightDataType TYPE_BASE_DRAG_COEFF =
110 newType("Base drag coefficient", UnitGroup.UNITS_COEFFICIENT, 82);
113 //// Other coefficients
114 public static final FlightDataType TYPE_NORMAL_FORCE_COEFF =
115 newType("Normal force coefficient", UnitGroup.UNITS_COEFFICIENT, 90);
116 public static final FlightDataType TYPE_PITCH_MOMENT_COEFF =
117 newType("Pitch moment coefficient", UnitGroup.UNITS_COEFFICIENT, 91);
118 public static final FlightDataType TYPE_YAW_MOMENT_COEFF =
119 newType("Yaw moment coefficient", UnitGroup.UNITS_COEFFICIENT, 92);
120 public static final FlightDataType TYPE_SIDE_FORCE_COEFF =
121 newType("Side force coefficient", UnitGroup.UNITS_COEFFICIENT, 93);
122 public static final FlightDataType TYPE_ROLL_MOMENT_COEFF =
123 newType("Roll moment coefficient", UnitGroup.UNITS_COEFFICIENT, 94);
124 public static final FlightDataType TYPE_ROLL_FORCING_COEFF =
125 newType("Roll forcing coefficient", UnitGroup.UNITS_COEFFICIENT, 95);
126 public static final FlightDataType TYPE_ROLL_DAMPING_COEFF =
127 newType("Roll damping coefficient", UnitGroup.UNITS_COEFFICIENT, 96);
129 public static final FlightDataType TYPE_PITCH_DAMPING_MOMENT_COEFF =
130 newType("Pitch damping coefficient", UnitGroup.UNITS_COEFFICIENT, 97);
131 public static final FlightDataType TYPE_YAW_DAMPING_MOMENT_COEFF =
132 newType("Yaw damping coefficient", UnitGroup.UNITS_COEFFICIENT, 98);
135 //// Reference length + area
136 public static final FlightDataType TYPE_REFERENCE_LENGTH =
137 newType("Reference length", UnitGroup.UNITS_LENGTH, 100);
138 public static final FlightDataType TYPE_REFERENCE_AREA =
139 newType("Reference area", UnitGroup.UNITS_AREA, 101);
143 public static final FlightDataType TYPE_ORIENTATION_THETA =
144 newType("Vertical orientation (zenith)", UnitGroup.UNITS_ANGLE, 106);
145 public static final FlightDataType TYPE_ORIENTATION_PHI =
146 newType("Lateral orientation (azimuth)", UnitGroup.UNITS_ANGLE, 107);
149 //// Atmospheric conditions
150 public static final FlightDataType TYPE_WIND_VELOCITY = newType("Wind velocity",
151 UnitGroup.UNITS_VELOCITY, 110);
152 public static final FlightDataType TYPE_AIR_TEMPERATURE = newType("Air temperature",
153 UnitGroup.UNITS_TEMPERATURE, 111);
154 public static final FlightDataType TYPE_AIR_PRESSURE = newType("Air pressure",
155 UnitGroup.UNITS_PRESSURE, 112);
156 public static final FlightDataType TYPE_SPEED_OF_SOUND = newType("Speed of sound",
157 UnitGroup.UNITS_VELOCITY, 113);
160 //// Simulation information
161 public static final FlightDataType TYPE_TIME_STEP = newType("Simulation time step",
162 UnitGroup.UNITS_TIME_STEP, 200);
163 public static final FlightDataType TYPE_COMPUTATION_TIME = newType("Computation time",
164 UnitGroup.UNITS_SHORT_TIME, 201);
169 * Return a {@link FlightDataType} based on a string description. This returns known data types
170 * if possible, or a new type otherwise.
172 * @param s the string description of the type.
173 * @param u the unit group the new type should belong to if a new group is created.
174 * @return a data type.
176 public static synchronized FlightDataType getType(String s, UnitGroup u) {
177 for (FlightDataType t : EXISTING_TYPES) {
178 if (t.getName().equalsIgnoreCase(s))
181 FlightDataType type = new FlightDataType(s, u, DEFAULT_PRIORITY);
182 EXISTING_TYPES.add(type);
187 * Used while initializing the class.
189 private static synchronized FlightDataType newType(String s, UnitGroup u, int priority) {
190 FlightDataType type = new FlightDataType(s, u, priority);
191 EXISTING_TYPES.add(type);
196 private final String name;
197 private final UnitGroup units;
198 private final int priority;
199 private final int hashCode;
202 private FlightDataType(String typeName, UnitGroup units, int priority) {
203 if (typeName == null)
204 throw new IllegalArgumentException("typeName is null");
206 throw new IllegalArgumentException("units is null");
207 this.name = typeName;
209 this.priority = priority;
210 this.hashCode = this.name.toLowerCase().hashCode();
216 public String getName() {
220 public UnitGroup getUnitGroup() {
225 public String toString() {
230 public boolean equals(Object other) {
231 if (!(other instanceof FlightDataType))
233 return this.name.equalsIgnoreCase(((FlightDataType) other).name);
237 public int hashCode() {
242 public int compareTo(FlightDataType o) {
243 if (this.priority != o.priority)
244 return this.priority - o.priority;
245 return this.name.compareTo(o.name);