1 package net.sf.openrocket.simulation;
3 import java.util.ArrayList;
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.Monitorable;
17 * A holder class for the simulation conditions. These include conditions that do not change
18 * during the flight of a rocket, for example launch rod parameters, atmospheric models,
19 * aerodynamic calculators etc.
21 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
23 public class SimulationConditions implements Monitorable, Cloneable {
25 private Rocket rocket;
26 private String motorID = null;
29 private double launchRodLength = 1;
31 /** Launch rod angle >= 0, radians from vertical */
32 private double launchRodAngle = 0;
34 /** Launch rod direction, 0 = upwind, PI = downwind. */
35 private double launchRodDirection = 0;
38 private double launchAltitude = 0;
39 private double launchLatitude = 45;
42 private WindModel windModel;
43 private AtmosphericModel atmosphericModel;
44 private GravityModel gravityModel;
46 private AerodynamicCalculator aerodynamicCalculator;
47 private MassCalculator massCalculator;
50 private double timeStep = RK4SimulationStepper.RECOMMENDED_TIME_STEP;
51 private double maximumAngleStep = RK4SimulationStepper.RECOMMENDED_ANGLE_STEP;
53 /* Whether to calculate additional data or only primary simulation figures */
54 private boolean calculateExtras = true;
57 private List<SimulationListener> simulationListeners = new ArrayList<SimulationListener>();
60 private int modID = 0;
61 private int modIDadd = 0;
66 public AerodynamicCalculator getAerodynamicCalculator() {
67 return aerodynamicCalculator;
71 public void setAerodynamicCalculator(AerodynamicCalculator aerodynamicCalculator) {
72 if (this.aerodynamicCalculator != null)
73 this.modIDadd += this.aerodynamicCalculator.getModID();
75 this.aerodynamicCalculator = aerodynamicCalculator;
79 public MassCalculator getMassCalculator() {
80 return massCalculator;
84 public void setMassCalculator(MassCalculator massCalculator) {
85 if (this.massCalculator != null)
86 this.modIDadd += this.massCalculator.getModID();
88 this.massCalculator = massCalculator;
92 public Rocket getRocket() {
97 public void setRocket(Rocket rocket) {
98 if (this.rocket != null)
99 this.modIDadd += this.rocket.getModID();
101 this.rocket = rocket;
105 public String getMotorConfigurationID() {
110 public void setMotorConfigurationID(String motorID) {
111 this.motorID = motorID;
116 public double getLaunchRodLength() {
117 return launchRodLength;
121 public void setLaunchRodLength(double launchRodLength) {
122 this.launchRodLength = launchRodLength;
127 public double getLaunchRodAngle() {
128 return launchRodAngle;
132 public void setLaunchRodAngle(double launchRodAngle) {
133 this.launchRodAngle = launchRodAngle;
138 public double getLaunchRodDirection() {
139 return launchRodDirection;
143 public void setLaunchRodDirection(double launchRodDirection) {
144 this.launchRodDirection = launchRodDirection;
149 public double getLaunchAltitude() {
150 return launchAltitude;
154 public void setLaunchAltitude(double launchAltitude) {
155 this.launchAltitude = launchAltitude;
160 public double getLaunchLatitude() {
161 return launchLatitude;
165 public void setLaunchLatitude(double launchLatitude) {
166 this.launchLatitude = launchLatitude;
171 public WindModel getWindModel() {
176 public void setWindModel(WindModel windModel) {
177 if (this.windModel != null)
178 this.modIDadd += this.windModel.getModID();
180 this.windModel = windModel;
184 public AtmosphericModel getAtmosphericModel() {
185 return atmosphericModel;
189 public void setAtmosphericModel(AtmosphericModel atmosphericModel) {
190 if (this.atmosphericModel != null)
191 this.modIDadd += this.atmosphericModel.getModID();
193 this.atmosphericModel = atmosphericModel;
197 public GravityModel getGravityModel() {
202 public void setGravityModel(GravityModel gravityModel) {
203 if (this.gravityModel != null)
204 this.modIDadd += this.gravityModel.getModID();
206 this.gravityModel = gravityModel;
210 public double getTimeStep() {
215 public void setTimeStep(double timeStep) {
216 this.timeStep = timeStep;
221 public double getMaximumAngleStep() {
222 return maximumAngleStep;
226 public void setMaximumAngleStep(double maximumAngle) {
227 this.maximumAngleStep = maximumAngle;
232 public boolean isCalculateExtras() {
233 return calculateExtras;
237 public void setCalculateExtras(boolean calculateExtras) {
238 this.calculateExtras = calculateExtras;
243 // TODO: HIGH: Make cleaner
244 public List<SimulationListener> getSimulationListenerList() {
245 return simulationListeners;
250 public int getModID() {
251 return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() +
252 gravityModel.getModID() + aerodynamicCalculator.getModID() + massCalculator.getModID());
257 public SimulationConditions clone() {
259 // TODO: HIGH: Deep clone models
260 return (SimulationConditions) super.clone();
261 } catch (CloneNotSupportedException e) {
262 throw new BugException(e);