geodetic computations
[debian/openrocket] / src / net / sf / openrocket / simulation / SimulationConditions.java
1 package net.sf.openrocket.simulation;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import net.sf.openrocket.aerodynamics.AerodynamicCalculator;
7 import net.sf.openrocket.masscalc.MassCalculator;
8 import net.sf.openrocket.models.atmosphere.AtmosphericModel;
9 import net.sf.openrocket.models.gravity.GravityModel;
10 import net.sf.openrocket.models.wind.WindModel;
11 import net.sf.openrocket.rocketcomponent.Rocket;
12 import net.sf.openrocket.simulation.listeners.SimulationListener;
13 import net.sf.openrocket.util.BugException;
14 import net.sf.openrocket.util.GeodeticComputationStrategy;
15 import net.sf.openrocket.util.Monitorable;
16 import net.sf.openrocket.util.WorldCoordinate;
17
18 /**
19  * A holder class for the simulation conditions.  These include conditions that do not change
20  * during the flight of a rocket, for example launch rod parameters, atmospheric models,
21  * aerodynamic calculators etc.
22  * 
23  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
24  */
25 public class SimulationConditions implements Monitorable, Cloneable {
26         
27         private Rocket rocket;
28         private String motorID = null;
29         
30
31         private double launchRodLength = 1;
32         
33         /** Launch rod angle >= 0, radians from vertical */
34         private double launchRodAngle = 0;
35         
36         /** Launch rod direction, 0 = upwind, PI = downwind. */
37         private double launchRodDirection = 0;
38         
39         // TODO: Depreciate these and use worldCoordinate only.
40         //private double launchAltitude = 0;
41         //private double launchLatitude = 45;
42         //private double launchLongitude = 0;
43         private WorldCoordinate launchSite = new WorldCoordinate(0, 0, 0);
44         private GeodeticComputationStrategy geodeticComputation = GeodeticComputationStrategy.SPHERICAL;
45         
46
47         private WindModel windModel;
48         private AtmosphericModel atmosphericModel;
49         private GravityModel gravityModel;
50         
51         private AerodynamicCalculator aerodynamicCalculator;
52         private MassCalculator massCalculator;
53         
54
55         private double timeStep = RK4SimulationStepper.RECOMMENDED_TIME_STEP;
56         private double maximumAngleStep = RK4SimulationStepper.RECOMMENDED_ANGLE_STEP;
57         
58         /* Whether to calculate additional data or only primary simulation figures */
59         private boolean calculateExtras = true;
60         
61
62         private List<SimulationListener> simulationListeners = new ArrayList<SimulationListener>();
63         
64
65         private int randomSeed = 0;
66         
67         private int modID = 0;
68         private int modIDadd = 0;
69         
70         
71
72
73         public AerodynamicCalculator getAerodynamicCalculator() {
74                 return aerodynamicCalculator;
75         }
76         
77         
78         public void setAerodynamicCalculator(AerodynamicCalculator aerodynamicCalculator) {
79                 if (this.aerodynamicCalculator != null)
80                         this.modIDadd += this.aerodynamicCalculator.getModID();
81                 this.modID++;
82                 this.aerodynamicCalculator = aerodynamicCalculator;
83         }
84         
85         public MassCalculator getMassCalculator() {
86                 return massCalculator;
87         }
88         
89         
90         public void setMassCalculator(MassCalculator massCalculator) {
91                 if (this.massCalculator != null)
92                         this.modIDadd += this.massCalculator.getModID();
93                 this.modID++;
94                 this.massCalculator = massCalculator;
95         }
96         
97         
98         public Rocket getRocket() {
99                 return rocket;
100         }
101         
102         
103         public void setRocket(Rocket rocket) {
104                 if (this.rocket != null)
105                         this.modIDadd += this.rocket.getModID();
106                 this.modID++;
107                 this.rocket = rocket;
108         }
109         
110         
111         public String getMotorConfigurationID() {
112                 return motorID;
113         }
114         
115         
116         public void setMotorConfigurationID(String motorID) {
117                 this.motorID = motorID;
118                 this.modID++;
119         }
120         
121         
122         public double getLaunchRodLength() {
123                 return launchRodLength;
124         }
125         
126         
127         public void setLaunchRodLength(double launchRodLength) {
128                 this.launchRodLength = launchRodLength;
129                 this.modID++;
130         }
131         
132         
133         public double getLaunchRodAngle() {
134                 return launchRodAngle;
135         }
136         
137         
138         public void setLaunchRodAngle(double launchRodAngle) {
139                 this.launchRodAngle = launchRodAngle;
140                 this.modID++;
141         }
142         
143         
144         public double getLaunchRodDirection() {
145                 return launchRodDirection;
146         }
147         
148         
149         public void setLaunchRodDirection(double launchRodDirection) {
150                 this.launchRodDirection = launchRodDirection;
151                 this.modID++;
152         }
153         
154         
155         public WorldCoordinate getLaunchSite() {
156                 return this.launchSite;
157         }
158         
159         public void setLaunchSite(WorldCoordinate site) {
160                 if (this.launchSite.equals(site))
161                         return;
162                 this.launchSite = site;
163                 this.modID++;
164         }
165         
166         
167         public GeodeticComputationStrategy getGeodeticComputation() {
168                 return geodeticComputation;
169         }
170         
171         public void setGeodeticComputation(GeodeticComputationStrategy geodeticComputation) {
172                 if (this.geodeticComputation == geodeticComputation)
173                         return;
174                 if (geodeticComputation == null) {
175                         throw new IllegalArgumentException("strategy cannot be null");
176                 }
177                 this.geodeticComputation = geodeticComputation;
178                 this.modID++;
179         }
180         
181         
182         public WindModel getWindModel() {
183                 return windModel;
184         }
185         
186         
187         public void setWindModel(WindModel windModel) {
188                 if (this.windModel != null)
189                         this.modIDadd += this.windModel.getModID();
190                 this.modID++;
191                 this.windModel = windModel;
192         }
193         
194         
195         public AtmosphericModel getAtmosphericModel() {
196                 return atmosphericModel;
197         }
198         
199         
200         public void setAtmosphericModel(AtmosphericModel atmosphericModel) {
201                 if (this.atmosphericModel != null)
202                         this.modIDadd += this.atmosphericModel.getModID();
203                 this.modID++;
204                 this.atmosphericModel = atmosphericModel;
205         }
206         
207         
208         public GravityModel getGravityModel() {
209                 return gravityModel;
210         }
211         
212         
213         public void setGravityModel(GravityModel gravityModel) {
214                 //if (this.gravityModel != null)
215                 //      this.modIDadd += this.gravityModel.getModID();
216                 this.modID++;
217                 this.gravityModel = gravityModel;
218         }
219         
220         
221         public double getTimeStep() {
222                 return timeStep;
223         }
224         
225         
226         public void setTimeStep(double timeStep) {
227                 this.timeStep = timeStep;
228                 this.modID++;
229         }
230         
231         
232         public double getMaximumAngleStep() {
233                 return maximumAngleStep;
234         }
235         
236         
237         public void setMaximumAngleStep(double maximumAngle) {
238                 this.maximumAngleStep = maximumAngle;
239                 this.modID++;
240         }
241         
242         
243         public boolean isCalculateExtras() {
244                 return calculateExtras;
245         }
246         
247         
248         public void setCalculateExtras(boolean calculateExtras) {
249                 this.calculateExtras = calculateExtras;
250                 this.modID++;
251         }
252         
253         
254
255         public int getRandomSeed() {
256                 return randomSeed;
257         }
258         
259         
260         public void setRandomSeed(int randomSeed) {
261                 this.randomSeed = randomSeed;
262                 this.modID++;
263         }
264         
265         
266
267
268         // TODO: HIGH: Make cleaner
269         public List<SimulationListener> getSimulationListenerList() {
270                 return simulationListeners;
271         }
272         
273         
274         @Override
275         public int getModID() {
276                 //return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() +
277                 //              gravityModel.getModID() + aerodynamicCalculator.getModID() + massCalculator.getModID());
278                 return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() +
279                                 aerodynamicCalculator.getModID() + massCalculator.getModID());
280         }
281         
282         
283         @Override
284         public SimulationConditions clone() {
285                 try {
286                         // TODO: HIGH: Deep clone models
287                         return (SimulationConditions) super.clone();
288                 } catch (CloneNotSupportedException e) {
289                         throw new BugException(e);
290                 }
291         }
292         
293 }