Initial commit
[debian/openrocket] / src / net / sf / openrocket / aerodynamics / ConeDragTest.java
1 package net.sf.openrocket.aerodynamics;
2
3 import net.sf.openrocket.util.PolyInterpolator;
4
5 public class ConeDragTest {
6
7         private static final double DELTA = 0.01;
8         private static final double SUBSONIC = 0.0;
9         private static final double SUPERSONIC = 1.3;
10         
11         
12         private static final PolyInterpolator polyInt2 = new PolyInterpolator(
13                         new double[] {1.0, SUPERSONIC}
14                         ,new double[] {1.0, SUPERSONIC}
15                         ,new double[] {SUPERSONIC}
16         );
17         
18         private final double angle;
19         private final double sin;
20         private final double ratio;
21         
22         private final double[] int2;
23
24         // Coefficients for subsonic interpolation  a * M^b + c
25         private final double a, b, c;
26         
27         
28         
29         public ConeDragTest(double angle) {
30                 this.angle = angle;
31                 this.sin = Math.sin(angle);
32                 this.ratio = 1.0 / (2*Math.tan(angle));
33                 
34                 double dsuper = (supersonic(SUPERSONIC+DELTA) - supersonic(SUPERSONIC))/DELTA;
35                 
36
37                 c = subsonic(0);
38                 a = sonic() - c;
39                 b = sonicDerivative() / a;
40                 
41                 
42                 int2 = polyInt2.interpolator(
43                                 sonic(), supersonic(SUPERSONIC)
44                                 , sonicDerivative(), dsuper
45                                 ,0
46                 );
47                 
48                 System.err.println("At mach1: CD="+sin+" dCD/dM="+(4.0/2.4*(1-0.5*sin)));
49                 
50         }
51         
52         private double subsonic(double m) {
53                 return 0.8*sin*sin/Math.sqrt(1-m*m);
54         }
55         
56         private double sonic() {
57                 return sin;
58         }
59         
60         private double sonicDerivative() {
61                 return 4.0/2.4*(1-0.5*sin);
62         }
63         
64         private double supersonic(double m) {
65                 return 2.1 * sin*sin + 0.5*sin/Math.sqrt(m*m-1);
66         }
67         
68         
69         
70         
71         public double getCD(double m) {
72                 if (m >= SUPERSONIC)
73                         return supersonic(m);
74
75                 if (m <= 1.0)
76                         return a * Math.pow(m,b) + c;
77                 return PolyInterpolator.eval(m, int2);
78                         
79 //              return PolyInterpolator.eval(m, interpolator);
80         }
81         
82         
83         
84         public static void main(String[] arg) {
85                 
86                 ConeDragTest cone10 = new ConeDragTest(10.0*Math.PI/180);
87                 ConeDragTest cone20 = new ConeDragTest(20.0*Math.PI/180);
88                 ConeDragTest cone30 = new ConeDragTest(30.0*Math.PI/180);
89                 
90                 ConeDragTest coneX = new ConeDragTest(5.0*Math.PI/180);
91
92                 for (double m=0; m < 4.0001; m+=0.02) {
93                         System.out.println(m + " " 
94                                         + cone10.getCD(m) + " "
95                                         + cone20.getCD(m) + " "
96                                         + cone30.getCD(m) + " "
97 //                                      + coneX.getCD(m)
98                         );
99                 }
100                 
101         }
102         
103 }