1 package net.sf.openrocket.simulation;
3 import java.util.HashMap;
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), a unit group and a priority. The type is identified
15 * purely by its name case-insensitively. The unit group provides the units for the type.
16 * The priority is used to order the types. The pre-existing types are defined specific priority
17 * numbers, and other types have a default priority number that is after all other types.
19 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
21 public class FlightDataType implements Comparable<FlightDataType> {
23 /** Priority of custom-created variables */
24 private static final int DEFAULT_PRIORITY = 999;
26 /** List of existing types. MUST BE DEFINED BEFORE ANY TYPES!! */
27 private static final Map<String, FlightDataType> EXISTING_TYPES = new HashMap<String, FlightDataType>();
32 public static final FlightDataType TYPE_TIME = newType("Time", UnitGroup.UNITS_FLIGHT_TIME, 1);
35 //// Vertical position and motion
36 public static final FlightDataType TYPE_ALTITUDE = newType("Altitude", UnitGroup.UNITS_DISTANCE, 10);
37 public static final FlightDataType TYPE_VELOCITY_Z = newType("Vertical velocity", UnitGroup.UNITS_VELOCITY, 11);
38 public static final FlightDataType TYPE_ACCELERATION_Z = newType("Vertical acceleration", UnitGroup.UNITS_ACCELERATION, 12);
42 public static final FlightDataType TYPE_VELOCITY_TOTAL = newType("Total velocity", UnitGroup.UNITS_VELOCITY, 20);
43 public static final FlightDataType TYPE_ACCELERATION_TOTAL = newType("Total acceleration", UnitGroup.UNITS_ACCELERATION, 21);
46 //// Lateral position and motion
48 public static final FlightDataType TYPE_POSITION_X = newType("Position upwind", UnitGroup.UNITS_DISTANCE, 30);
49 public static final FlightDataType TYPE_POSITION_Y = newType("Position parallel to wind", UnitGroup.UNITS_DISTANCE, 31);
50 public static final FlightDataType TYPE_POSITION_XY = newType("Lateral distance", UnitGroup.UNITS_DISTANCE, 32);
51 public static final FlightDataType TYPE_POSITION_DIRECTION = newType("Lateral direction", UnitGroup.UNITS_ANGLE, 33);
53 public static final FlightDataType TYPE_VELOCITY_XY = newType("Lateral velocity", UnitGroup.UNITS_VELOCITY, 34);
54 public static final FlightDataType TYPE_ACCELERATION_XY = newType("Lateral acceleration", UnitGroup.UNITS_ACCELERATION, 35);
58 public static final FlightDataType TYPE_AOA = newType("Angle of attack", UnitGroup.UNITS_ANGLE, 40);
59 public static final FlightDataType TYPE_ROLL_RATE = newType("Roll rate", UnitGroup.UNITS_ROLL, 41);
60 public static final FlightDataType TYPE_PITCH_RATE = newType("Pitch rate", UnitGroup.UNITS_ROLL, 42);
61 public static final FlightDataType TYPE_YAW_RATE = newType("Yaw rate", UnitGroup.UNITS_ROLL, 43);
64 //// Stability information
65 public static final FlightDataType TYPE_MASS = newType("Mass", UnitGroup.UNITS_MASS, 50);
66 public static final FlightDataType TYPE_LONGITUDINAL_INERTIA = newType("Longitudinal moment of inertia", UnitGroup.UNITS_INERTIA, 51);
67 public static final FlightDataType TYPE_ROTATIONAL_INERTIA = newType("Rotational moment of inertia", UnitGroup.UNITS_INERTIA, 52);
68 public static final FlightDataType TYPE_CP_LOCATION = newType("CP location", UnitGroup.UNITS_LENGTH, 53);
69 public static final FlightDataType TYPE_CG_LOCATION = newType("CG location", UnitGroup.UNITS_LENGTH, 54);
70 public static final FlightDataType TYPE_STABILITY = newType("Stability margin calibers", UnitGroup.UNITS_COEFFICIENT, 55);
73 //// Characteristic numbers
74 public static final FlightDataType TYPE_MACH_NUMBER = newType("Mach number", UnitGroup.UNITS_COEFFICIENT, 60);
75 public static final FlightDataType TYPE_REYNOLDS_NUMBER = newType("Reynolds number", UnitGroup.UNITS_COEFFICIENT, 61);
79 public static final FlightDataType TYPE_THRUST_FORCE = newType("Thrust", UnitGroup.UNITS_FORCE, 70);
80 public static final FlightDataType TYPE_DRAG_FORCE = newType("Drag force", UnitGroup.UNITS_FORCE, 71);
81 public static final FlightDataType TYPE_DRAG_COEFF = newType("Drag coefficient", UnitGroup.UNITS_COEFFICIENT, 72);
82 public static final FlightDataType TYPE_AXIAL_DRAG_COEFF = newType("Axial drag coefficient", UnitGroup.UNITS_COEFFICIENT, 73);
85 //// Component drag coefficients
86 public static final FlightDataType TYPE_FRICTION_DRAG_COEFF = newType("Friction drag coefficient", UnitGroup.UNITS_COEFFICIENT, 80);
87 public static final FlightDataType TYPE_PRESSURE_DRAG_COEFF = newType("Pressure drag coefficient", UnitGroup.UNITS_COEFFICIENT, 81);
88 public static final FlightDataType TYPE_BASE_DRAG_COEFF = newType("Base drag coefficient", UnitGroup.UNITS_COEFFICIENT, 82);
91 //// Other coefficients
92 public static final FlightDataType TYPE_NORMAL_FORCE_COEFF = newType("Normal force coefficient", UnitGroup.UNITS_COEFFICIENT, 90);
93 public static final FlightDataType TYPE_PITCH_MOMENT_COEFF = newType("Pitch moment coefficient", UnitGroup.UNITS_COEFFICIENT, 91);
94 public static final FlightDataType TYPE_YAW_MOMENT_COEFF = newType("Yaw moment coefficient", UnitGroup.UNITS_COEFFICIENT, 92);
95 public static final FlightDataType TYPE_SIDE_FORCE_COEFF = newType("Side force coefficient", UnitGroup.UNITS_COEFFICIENT, 93);
96 public static final FlightDataType TYPE_ROLL_MOMENT_COEFF = newType("Roll moment coefficient", UnitGroup.UNITS_COEFFICIENT, 94);
97 public static final FlightDataType TYPE_ROLL_FORCING_COEFF = newType("Roll forcing coefficient", UnitGroup.UNITS_COEFFICIENT, 95);
98 public static final FlightDataType TYPE_ROLL_DAMPING_COEFF = newType("Roll damping coefficient", UnitGroup.UNITS_COEFFICIENT, 96);
100 public static final FlightDataType TYPE_PITCH_DAMPING_MOMENT_COEFF = newType("Pitch damping coefficient", UnitGroup.UNITS_COEFFICIENT, 97);
101 public static final FlightDataType TYPE_YAW_DAMPING_MOMENT_COEFF = newType("Yaw damping coefficient", UnitGroup.UNITS_COEFFICIENT, 98);
104 //// Reference length + area
105 public static final FlightDataType TYPE_REFERENCE_LENGTH = newType("Reference length", UnitGroup.UNITS_LENGTH, 100);
106 public static final FlightDataType TYPE_REFERENCE_AREA = newType("Reference area", UnitGroup.UNITS_AREA, 101);
110 public static final FlightDataType TYPE_ORIENTATION_THETA = newType("Vertical orientation (zenith)", UnitGroup.UNITS_ANGLE, 106);
111 public static final FlightDataType TYPE_ORIENTATION_PHI = newType("Lateral orientation (azimuth)", UnitGroup.UNITS_ANGLE, 107);
114 //// Atmospheric conditions
115 public static final FlightDataType TYPE_WIND_VELOCITY = newType("Wind velocity", UnitGroup.UNITS_VELOCITY, 110);
116 public static final FlightDataType TYPE_AIR_TEMPERATURE = newType("Air temperature", UnitGroup.UNITS_TEMPERATURE, 111);
117 public static final FlightDataType TYPE_AIR_PRESSURE = newType("Air pressure", UnitGroup.UNITS_PRESSURE, 112);
118 public static final FlightDataType TYPE_SPEED_OF_SOUND = newType("Speed of sound", UnitGroup.UNITS_VELOCITY, 113);
121 //// Simulation information
122 public static final FlightDataType TYPE_TIME_STEP = newType("Simulation time step", UnitGroup.UNITS_TIME_STEP, 200);
123 public static final FlightDataType TYPE_COMPUTATION_TIME = newType("Computation time", UnitGroup.UNITS_SHORT_TIME, 201);
128 * Return a {@link FlightDataType} based on a string description. This returns known data types
129 * if possible, or a new type otherwise.
131 * @param s the string description of the type.
132 * @param u the unit group the new type should belong to if a new group is created.
133 * @return a data type.
135 public static synchronized FlightDataType getType(String s, UnitGroup u) {
136 FlightDataType type = EXISTING_TYPES.get(s.toLowerCase());
140 type = newType(s, u, DEFAULT_PRIORITY);
145 * Used while initializing the class.
147 private static synchronized FlightDataType newType(String s, UnitGroup u, int priority) {
148 FlightDataType type = new FlightDataType(s, u, priority);
149 EXISTING_TYPES.put(s.toLowerCase(), type);
154 private final String name;
155 private final UnitGroup units;
156 private final int priority;
157 private final int hashCode;
160 private FlightDataType(String typeName, UnitGroup units, int priority) {
161 if (typeName == null)
162 throw new IllegalArgumentException("typeName is null");
164 throw new IllegalArgumentException("units is null");
165 this.name = typeName;
167 this.priority = priority;
168 this.hashCode = this.name.toLowerCase().hashCode();
174 public String getName() {
178 public UnitGroup getUnitGroup() {
183 public String toString() {
188 public boolean equals(Object other) {
189 if (!(other instanceof FlightDataType))
191 return this.name.equalsIgnoreCase(((FlightDataType) other).name);
195 public int hashCode() {
200 public int compareTo(FlightDataType o) {
201 if (this.priority != o.priority)
202 return this.priority - o.priority;
203 return this.name.compareToIgnoreCase(o.name);