create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / aerodynamics / AerodynamicForces.java
1 package net.sf.openrocket.aerodynamics;
2
3 import net.sf.openrocket.rocketcomponent.RocketComponent;
4 import net.sf.openrocket.util.BugException;
5 import net.sf.openrocket.util.Coordinate;
6 import net.sf.openrocket.util.MathUtil;
7 import net.sf.openrocket.util.Monitorable;
8
9 public class AerodynamicForces implements Cloneable, Monitorable {
10         
11         /** 
12          * The component this data is referring to.  Used in analysis methods.
13          * A total value is indicated by the component being the Rocket component. 
14          */
15         private RocketComponent component = null;
16         
17
18         /** CP and CNa. */
19         private Coordinate cp = null;
20         
21         
22         /**
23          * Normal force coefficient derivative.  At values close to zero angle of attack
24          * this value may be poorly defined or NaN if the calculation method does not
25          * compute CNa directly.
26          */
27         private double CNa = Double.NaN;
28
29         
30         /** Normal force coefficient. */
31         private double CN = Double.NaN;
32
33         /** Pitching moment coefficient, relative to the coordinate origin. */
34         private double Cm = Double.NaN;
35         
36         /** Side force coefficient, Cy */
37         private double Cside = Double.NaN;
38         
39         /** Yaw moment coefficient, Cn, relative to the coordinate origin. */
40         private double Cyaw = Double.NaN;
41         
42         /** Roll moment coefficient, Cl, relative to the coordinate origin. */
43         private double Croll = Double.NaN;
44         
45         /** Roll moment damping coefficient */
46         private double CrollDamp = Double.NaN;
47         
48         /** Roll moment forcing coefficient */
49         private double CrollForce = Double.NaN;
50         
51
52         
53         /** Axial drag coefficient, CA */
54         private double Caxial = Double.NaN;
55         
56         /** Total drag force coefficient, parallel to the airflow. */
57         private double CD = Double.NaN;
58         
59         /** Drag coefficient due to fore pressure drag. */
60         private double pressureCD = Double.NaN;
61         
62         /** Drag coefficient due to base drag. */
63         private double baseCD = Double.NaN;
64         
65         /** Drag coefficient due to friction drag. */
66         private double frictionCD = Double.NaN;
67         
68         
69         private double pitchDampingMoment = Double.NaN;
70         private double yawDampingMoment = Double.NaN;
71         
72         private int modID = 0;
73         
74         
75         public void setComponent(RocketComponent component) {
76                 this.component = component;
77                 modID++;
78         }
79
80         public RocketComponent getComponent() {
81                 return component;
82         }
83
84         public void setCP(Coordinate cp) {
85                 this.cp = cp;
86                 modID++;
87         }
88
89         public Coordinate getCP() {
90                 return cp;
91         }
92
93         public void setCNa(double cNa) {
94                 CNa = cNa;
95                 modID++;
96         }
97
98         public double getCNa() {
99                 return CNa;
100         }
101
102         public void setCN(double cN) {
103                 CN = cN;
104                 modID++;
105         }
106
107         public double getCN() {
108                 return CN;
109         }
110
111         public void setCm(double cm) {
112                 Cm = cm;
113                 modID++;
114         }
115
116         public double getCm() {
117                 return Cm;
118         }
119
120         public void setCside(double cside) {
121                 Cside = cside;
122                 modID++;
123         }
124
125         public double getCside() {
126                 return Cside;
127         }
128
129         public void setCyaw(double cyaw) {
130                 Cyaw = cyaw;
131                 modID++;
132         }
133
134         public double getCyaw() {
135                 return Cyaw;
136         }
137
138         public void setCroll(double croll) {
139                 Croll = croll;
140                 modID++;
141         }
142
143         public double getCroll() {
144                 return Croll;
145         }
146
147         public void setCrollDamp(double crollDamp) {
148                 CrollDamp = crollDamp;
149                 modID++;
150         }
151
152         public double getCrollDamp() {
153                 return CrollDamp;
154         }
155
156         public void setCrollForce(double crollForce) {
157                 CrollForce = crollForce;
158                 modID++;
159         }
160
161         public double getCrollForce() {
162                 return CrollForce;
163         }
164
165         public void setCaxial(double caxial) {
166                 Caxial = caxial;
167                 modID++;
168         }
169
170         public double getCaxial() {
171                 return Caxial;
172         }
173
174         public void setCD(double cD) {
175                 CD = cD;
176                 modID++;
177         }
178
179         public double getCD() {
180                 return CD;
181         }
182
183         public void setPressureCD(double pressureCD) {
184                 this.pressureCD = pressureCD;
185                 modID++;
186         }
187
188         public double getPressureCD() {
189                 return pressureCD;
190         }
191
192         public void setBaseCD(double baseCD) {
193                 this.baseCD = baseCD;
194                 modID++;
195         }
196
197         public double getBaseCD() {
198                 return baseCD;
199         }
200
201         public void setFrictionCD(double frictionCD) {
202                 this.frictionCD = frictionCD;
203                 modID++;
204         }
205
206         public double getFrictionCD() {
207                 return frictionCD;
208         }
209
210         public void setPitchDampingMoment(double pitchDampingMoment) {
211                 this.pitchDampingMoment = pitchDampingMoment;
212                 modID++;
213         }
214
215         public double getPitchDampingMoment() {
216                 return pitchDampingMoment;
217         }
218
219         public void setYawDampingMoment(double yawDampingMoment) {
220                 this.yawDampingMoment = yawDampingMoment;
221                 modID++;
222         }
223
224         public double getYawDampingMoment() {
225                 return yawDampingMoment;
226         }
227
228         
229         
230         /**
231          * Reset all values to null/NaN.
232          */
233         public void reset() {
234                 setComponent(null);
235
236                 setCP(null);
237                 setCNa(Double.NaN);
238                 setCN(Double.NaN);
239                 setCm(Double.NaN);
240                 setCside(Double.NaN);
241                 setCyaw(Double.NaN);
242                 setCroll(Double.NaN);
243                 setCrollDamp(Double.NaN);
244                 setCrollForce(Double.NaN);
245                 setCaxial(Double.NaN);
246                 setCD(Double.NaN);
247                 setPitchDampingMoment(Double.NaN);
248                 setYawDampingMoment(Double.NaN);
249         }
250         
251         /**
252          * Zero all values to 0 / Coordinate.NUL.  Component is left as it was.
253          */
254         public void zero() {
255                 // component untouched
256
257                 setCP(Coordinate.NUL);
258                 setCNa(0);
259                 setCN(0);
260                 setCm(0);
261                 setCside(0);
262                 setCyaw(0);
263                 setCroll(0);
264                 setCrollDamp(0);
265                 setCrollForce(0);
266                 setCaxial(0);
267                 setCD(0);
268                 setPitchDampingMoment(0);
269                 setYawDampingMoment(0);
270         }
271
272         
273         @Override
274         public AerodynamicForces clone() {
275                 try {
276                         return (AerodynamicForces)super.clone();
277                 } catch (CloneNotSupportedException e) {
278                         throw new BugException("CloneNotSupportedException?!?");
279                 }
280         }
281         
282         
283         @Override
284         public boolean equals(Object obj) {
285                 if (this == obj)
286                         return true;
287                 if (!(obj instanceof AerodynamicForces))
288                         return false;
289                 AerodynamicForces other = (AerodynamicForces) obj;
290                 
291                 return (MathUtil.equals(this.getCNa(), other.getCNa()) &&
292                                 MathUtil.equals(this.getCN(), other.getCN()) &&
293                                 MathUtil.equals(this.getCm(), other.getCm()) &&
294                                 MathUtil.equals(this.getCside(), other.getCside()) &&
295                                 MathUtil.equals(this.getCyaw(), other.getCyaw()) &&
296                                 MathUtil.equals(this.getCroll(), other.getCroll()) &&
297                                 MathUtil.equals(this.getCrollDamp(), other.getCrollDamp()) &&
298                                 MathUtil.equals(this.getCrollForce(), other.getCrollForce()) &&
299                                 MathUtil.equals(this.getCaxial(), other.getCaxial()) &&
300                                 MathUtil.equals(this.getCD(), other.getCD()) &&
301                                 MathUtil.equals(this.getPressureCD(), other.getPressureCD()) &&
302                                 MathUtil.equals(this.getBaseCD(), other.getBaseCD()) &&
303                                 MathUtil.equals(this.getFrictionCD(), other.getFrictionCD()) &&
304                                 MathUtil.equals(this.getPitchDampingMoment(), other.getPitchDampingMoment()) &&
305                                 MathUtil.equals(this.getYawDampingMoment(), other.getYawDampingMoment()) &&
306                                 this.getCP().equals(other.getCP()));
307         }
308         
309         @Override
310         public int hashCode() {
311                 return (int) (1000*(this.getCD()+this.getCaxial()+this.getCNa())) + this.getCP().hashCode();
312         }
313         
314         
315         @Override
316         public String toString() {
317                 String text="AerodynamicForces[";
318                 
319                 if (getComponent() != null)
320                         text += "component:" + getComponent() + ",";
321                 if (getCP() != null)
322                         text += "cp:" + getCP() + ",";
323                 
324                 if (!Double.isNaN(getCNa()))
325                         text += "CNa:" + getCNa() + ",";
326                 if (!Double.isNaN(getCN()))
327                         text += "CN:" + getCN() + ",";
328                 if (!Double.isNaN(getCm()))
329                         text += "Cm:" + getCm() + ",";
330                 
331                 if (!Double.isNaN(getCside()))
332                         text += "Cside:" + getCside() + ",";
333                 if (!Double.isNaN(getCyaw()))
334                         text += "Cyaw:" + getCyaw() + ",";
335                 
336                 if (!Double.isNaN(getCroll()))
337                         text += "Croll:" + getCroll() + ",";
338                 if (!Double.isNaN(getCaxial()))
339                         text += "Caxial:" + getCaxial() + ",";
340                 
341                 if (!Double.isNaN(getCD()))
342                         text += "CD:" + getCD() + ",";
343
344                 if (text.charAt(text.length()-1) == ',')
345                         text = text.substring(0, text.length()-1);
346                 
347                 text += "]";
348                 return text;
349         }
350
351         @Override
352         public int getModID() {
353                 return modID;
354         }
355 }