1 package net.sf.openrocket.aerodynamics;
3 import net.sf.openrocket.util.BugException;
5 public class AtmosphericConditions implements Cloneable {
7 /** Specific gas constant of dry air. */
8 public static final double R = 287.053;
10 /** Specific heat ratio of air. */
11 public static final double GAMMA = 1.4;
13 /** The standard air pressure (1.01325 bar). */
14 public static final double STANDARD_PRESSURE = 101325.0;
16 /** The standard air temperature (20 degrees Celcius). */
17 public static final double STANDARD_TEMPERATURE = 293.15;
21 /** Air pressure, in Pascals. */
22 public double pressure = STANDARD_PRESSURE;
24 /** Air temperature, in Kelvins. */
25 public double temperature = STANDARD_TEMPERATURE;
29 * Construct standard atmospheric conditions.
31 public AtmosphericConditions() {
36 * Construct specified atmospheric conditions.
38 * @param temperature the temperature in Kelvins.
39 * @param pressure the pressure in Pascals.
41 public AtmosphericConditions(double temperature, double pressure) {
42 this.temperature = temperature;
43 this.pressure = pressure;
49 * Return the current density of air for dry air.
51 * @return the current density of air.
53 public double getDensity() {
54 return pressure / (R*temperature);
59 * Return the current speed of sound for dry air.
61 * The speed of sound is calculated using the expansion around the temperature 0 C
62 * <code> c = 331.3 + 0.606*T </code> where T is in Celcius. The result is accurate
63 * to about 0.5 m/s for temperatures between -30 and 30 C, and within 2 m/s
64 * for temperatures between -55 and 30 C.
66 * @return the current speed of sound.
68 public double getMachSpeed() {
69 return 165.77 + 0.606 * temperature;
74 * Return the current kinematic viscosity of the air.
76 * The effect of temperature on the viscosity of a gas can be computed using
77 * Sutherland's formula. In the region of -40 ... 40 degrees Celcius the effect
78 * is highly linear, and thus a linear approximation is used in its stead.
79 * This is divided by the result of {@link #getDensity()} to achieve the
80 * kinematic viscosity.
82 * @return the current kinematic viscosity.
84 public double getKinematicViscosity() {
85 double v = 3.7291e-06 + 4.9944e-08 * temperature;
86 return v / getDensity();
90 * Return a copy of the atmospheric conditions.
93 public AtmosphericConditions clone() {
95 return (AtmosphericConditions) super.clone();
96 } catch (CloneNotSupportedException e) {
97 throw new BugException("BUG: CloneNotSupportedException encountered!");
103 public String toString() {
104 return String.format("AtmosphericConditions[T=%.2f,P=%.2f]", temperature, pressure);