1 package net.sf.openrocket.models.atmosphere;
3 import net.sf.openrocket.util.BugException;
4 import net.sf.openrocket.util.MathUtil;
5 import net.sf.openrocket.util.Monitorable;
6 import net.sf.openrocket.util.UniqueID;
8 public class AtmosphericConditions implements Cloneable, Monitorable {
10 /** Specific gas constant of dry air. */
11 public static final double R = 287.053;
13 /** Specific heat ratio of air. */
14 public static final double GAMMA = 1.4;
16 /** The standard air pressure (1.01325 bar). */
17 public static final double STANDARD_PRESSURE = 101325.0;
19 /** The standard air temperature (20 degrees Celcius). */
20 public static final double STANDARD_TEMPERATURE = 293.15;
24 /** Air pressure, in Pascals. */
25 private double pressure;
27 /** Air temperature, in Kelvins. */
28 private double temperature;
34 * Construct standard atmospheric conditions.
36 public AtmosphericConditions() {
37 this(STANDARD_TEMPERATURE, STANDARD_PRESSURE);
41 * Construct specified atmospheric conditions.
43 * @param temperature the temperature in Kelvins.
44 * @param pressure the pressure in Pascals.
46 public AtmosphericConditions(double temperature, double pressure) {
47 this.setTemperature(temperature);
48 this.setPressure(pressure);
49 this.modID = UniqueID.next();
54 public double getPressure() {
58 public void setPressure(double pressure) {
59 this.pressure = pressure;
60 this.modID = UniqueID.next();
63 public double getTemperature() {
67 public void setTemperature(double temperature) {
68 this.temperature = temperature;
69 this.modID = UniqueID.next();
73 * Return the current density of air for dry air.
75 * @return the current density of air.
77 public double getDensity() {
78 return getPressure() / (R*getTemperature());
83 * Return the current speed of sound for dry air.
85 * The speed of sound is calculated using the expansion around the temperature 0 C
86 * <code> c = 331.3 + 0.606*T </code> where T is in Celcius. The result is accurate
87 * to about 0.5 m/s for temperatures between -30 and 30 C, and within 2 m/s
88 * for temperatures between -55 and 30 C.
90 * @return the current speed of sound.
92 public double getMachSpeed() {
93 return 165.77 + 0.606 * getTemperature();
98 * Return the current kinematic viscosity of the air.
100 * The effect of temperature on the viscosity of a gas can be computed using
101 * Sutherland's formula. In the region of -40 ... 40 degrees Celcius the effect
102 * is highly linear, and thus a linear approximation is used in its stead.
103 * This is divided by the result of {@link #getDensity()} to achieve the
104 * kinematic viscosity.
106 * @return the current kinematic viscosity.
108 public double getKinematicViscosity() {
109 double v = 3.7291e-06 + 4.9944e-08 * getTemperature();
110 return v / getDensity();
115 * Return a copy of the atmospheric conditions.
118 public AtmosphericConditions clone() {
120 return (AtmosphericConditions) super.clone();
121 } catch (CloneNotSupportedException e) {
122 throw new BugException("CloneNotSupportedException encountered!");
127 public boolean equals(Object other) {
130 if (!(other instanceof AtmosphericConditions))
132 AtmosphericConditions o = (AtmosphericConditions) other;
133 return MathUtil.equals(this.pressure, o.pressure) && MathUtil.equals(this.temperature, o.temperature);
137 public int hashCode() {
138 return (int) (this.pressure + this.temperature*1000);
142 public int getModID() {
147 public String toString() {
148 return String.format("AtmosphericConditions[T=%.2f,P=%.2f]", getTemperature(), getPressure());