Updates for 0.9.5
[debian/openrocket] / src / net / sf / openrocket / aerodynamics / AtmosphericConditions.java
1 package net.sf.openrocket.aerodynamics;
2
3 import net.sf.openrocket.util.BugException;
4
5 public class AtmosphericConditions implements Cloneable {
6
7         /** Specific gas constant of dry air. */
8         public static final double R = 287.053;
9         
10         /** Specific heat ratio of air. */
11         public static final double GAMMA = 1.4;
12         
13         /** The standard air pressure (1.01325 bar). */
14         public static final double STANDARD_PRESSURE = 101325.0;
15         
16         /** The standard air temperature (20 degrees Celcius). */
17         public static final double STANDARD_TEMPERATURE = 293.15;
18         
19         
20         
21         /** Air pressure, in Pascals. */
22         public double pressure = STANDARD_PRESSURE;
23         
24         /** Air temperature, in Kelvins. */
25         public double temperature = STANDARD_TEMPERATURE;
26         
27         
28         /**
29          * Construct standard atmospheric conditions.
30          */
31         public AtmosphericConditions() {
32                 
33         }
34         
35         /**
36          * Construct specified atmospheric conditions.
37          * 
38          * @param temperature   the temperature in Kelvins.
39          * @param pressure              the pressure in Pascals.
40          */
41         public AtmosphericConditions(double temperature, double pressure) {
42                 this.temperature = temperature;
43                 this.pressure = pressure;
44         }
45         
46         
47         
48         /**
49          * Return the current density of air for dry air.
50          * 
51          * @return   the current density of air.
52          */
53         public double getDensity() {
54                 return pressure / (R*temperature);
55         }
56         
57         
58         /**
59          * Return the current speed of sound for dry air.
60          * <p>
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.
65          * 
66          * @return   the current speed of sound.
67          */
68         public double getMachSpeed() {
69                 return 165.77 + 0.606 * temperature;
70         }
71         
72         
73         /**
74          * Return the current kinematic viscosity of the air.
75          * <p>
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.
81          * 
82          * @return      the current kinematic viscosity.
83          */
84         public double getKinematicViscosity() {
85                 double v = 3.7291e-06 + 4.9944e-08 * temperature;
86                 return v / getDensity();
87         }
88         
89         /**
90          * Return a copy of the atmospheric conditions.
91          */
92         @Override
93         public AtmosphericConditions clone() {
94                 try {
95                         return (AtmosphericConditions) super.clone();
96                 } catch (CloneNotSupportedException e) {
97                         throw new BugException("BUG:  CloneNotSupportedException encountered!");
98                 }
99         }
100         
101         
102         @Override
103         public String toString() {
104                 return String.format("AtmosphericConditions[T=%.2f,P=%.2f]", temperature, pressure);
105         }
106         
107 }