1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.simulators;
11
12 import java.rmi.RemoteException;
13
14 import nl.tudelft.simulation.dsol.SimRuntimeException;
15 import nl.tudelft.simulation.dsol.experiment.Replication;
16 import nl.tudelft.simulation.logger.Logger;
17
18 /***
19 * The DESS defines the interface of the DESS simulator. DESS stands for the
20 * Differential Equation System Specification. More information on Modeling &
21 * Simulation can be found in "Theory of Modeling and Simulation" by Bernard
22 * Zeigler et. al. <br>
23 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
24 * University of Technology </a>, the Netherlands. <br>
25 * See for project information <a
26 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
27 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
28 * License (GPL) </a>, no warranty <br>
29 *
30 * @version 2.0 21.09.2003 <br>
31 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
32 * Jacobs </a>, <a
33 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
34 * Verbraeck </a>
35 */
36 public class DESSSimulator extends Simulator implements DESSSimulatorInterface
37 {
38
39 /***
40 * timeStep represents the timestep of the DESS simulator
41 *
42 * @uml.property name="timeStep"
43 */
44 protected double timeStep = DEFAULT_TIME_STEP;
45
46
47 /***
48 * @see nl.tudelft.simulation.dsol.simulators.SimulatorInterface
49 * #initialize(nl.tudelft.simulation.dsol.experiment.Replication)
50 */
51 public void initialize(final Replication replication)
52 throws RemoteException, SimRuntimeException
53 {
54 super.initialize(replication);
55 this.replication.getRunControl().getTreatment().getExperiment()
56 .getModel().constructModel(this);
57 }
58
59 /***
60 * @see nl.tudelft.simulation.dsol.simulators.DESSSimulatorInterface
61 * #getTimeStep()
62 *
63 * @uml.property name="timeStep"
64 */
65 public double getTimeStep()
66 {
67 return this.timeStep;
68 }
69
70
71 /***
72 * @see nl.tudelft.simulation.dsol.simulators.Simulator#run()
73 */
74 public void run()
75 {
76 while (this.simulatorTime <= this.replication.getRunControl()
77 .getRunLength()
78 && isRunning())
79 {
80 synchronized (super.semaphore)
81 {
82 this.simulatorTime = this.simulatorTime + this.timeStep;
83 if (this.simulatorTime > this.replication.getRunControl()
84 .getRunLength())
85 {
86 this.simulatorTime = this.replication.getRunControl()
87 .getRunLength();
88 this.stop();
89 }
90 this.fireEvent(SimulatorInterface.TIME_CHANGED_EVENT,
91 this.simulatorTime, this.simulatorTime);
92 }
93 }
94 }
95
96 /***
97 * @see nl.tudelft.simulation.dsol.simulators.DESSSimulatorInterface
98 * #setTimeStep(double)
99 *
100 * @uml.property name="timeStep"
101 */
102 public void setTimeStep(final double timeStep)
103 {
104 synchronized (super.semaphore)
105 {
106 if (timeStep < 0)
107 {
108 throw new IllegalArgumentException("timeStep <0 ?");
109 }
110 this.timeStep = timeStep;
111 Logger
112 .finer(this, "setTimeStep", "set the timeStep to "
113 + timeStep);
114 this.fireEvent(TIME_STEP_CHANGED_EVENT, timeStep);
115 }
116 }
117
118 }