c36c525f2920ef206e8203ff5739f81ceadf7c4f
[debian/openrocket] / src / net / sf / openrocket / aerodynamics / AtmosphericConditions.java
1 package net.sf.openrocket.aerodynamics;
2
3 public class AtmosphericConditions implements Cloneable {
4
5         /** Specific gas constant of dry air. */
6         public static final double R = 287.053;
7         
8         /** Specific heat ratio of air. */
9         public static final double GAMMA = 1.4;
10         
11         /** The standard air pressure (1.01325 bar). */
12         public static final double STANDARD_PRESSURE = 101325.0;
13         
14         /** The standard air temperature (20 degrees Celcius). */
15         public static final double STANDARD_TEMPERATURE = 293.15;
16         
17         
18         
19         /** Air pressure, in Pascals. */
20         public double pressure = STANDARD_PRESSURE;
21         
22         /** Air temperature, in Kelvins. */
23         public double temperature = STANDARD_TEMPERATURE;
24         
25         
26         /**
27          * Construct standard atmospheric conditions.
28          */
29         public AtmosphericConditions() {
30                 
31         }
32         
33         /**
34          * Construct specified atmospheric conditions.
35          * 
36          * @param temperature   the temperature in Kelvins.
37          * @param pressure              the pressure in Pascals.
38          */
39         public AtmosphericConditions(double temperature, double pressure) {
40                 this.temperature = temperature;
41                 this.pressure = pressure;
42         }
43         
44         
45         
46         /**
47          * Return the current density of air for dry air.
48          * 
49          * @return   the current density of air.
50          */
51         public double getDensity() {
52                 return pressure / (R*temperature);
53         }
54         
55         
56         /**
57          * Return the current speed of sound for dry air.
58          * <p>
59          * The speed of sound is calculated using the expansion around the temperature 0 C
60          * <code> c = 331.3 + 0.606*T </code> where T is in Celcius.  The result is accurate
61          * to about 0.5 m/s for temperatures between -30 and 30 C, and within 2 m/s
62          * for temperatures between -55 and 30 C.
63          * 
64          * @return   the current speed of sound.
65          */
66         public double getMachSpeed() {
67                 return 165.77 + 0.606 * temperature;
68         }
69         
70         
71         /**
72          * Return the current kinematic viscosity of the air.
73          * <p>
74          * The effect of temperature on the viscosity of a gas can be computed using
75          * Sutherland's formula.  In the region of -40 ... 40 degrees Celcius the effect
76          * is highly linear, and thus a linear approximation is used in its stead.
77          * This is divided by the result of {@link #getDensity()} to achieve the
78          * kinematic viscosity.
79          * 
80          * @return      the current kinematic viscosity.
81          */
82         public double getKinematicViscosity() {
83                 double v = 3.7291e-06 + 4.9944e-08 * temperature;
84                 return v / getDensity();
85         }
86         
87         /**
88          * Return a copy of the atmospheric conditions.
89          */
90         @Override
91         public AtmosphericConditions clone() {
92                 try {
93                         return (AtmosphericConditions) super.clone();
94                 } catch (CloneNotSupportedException e) {
95                         throw new RuntimeException("BUG:  CloneNotSupportedException encountered!");
96                 }
97         }
98         
99         
100         @Override
101         public String toString() {
102                 return String.format("AtmosphericConditions[T=%.2f,P=%.2f]", temperature, pressure);
103         }
104         
105 }