1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.sne.c3;
11
12 import java.rmi.RemoteException;
13
14 import nl.tudelft.simulation.dsol.ModelInterface;
15 import nl.tudelft.simulation.dsol.SimRuntimeException;
16 import nl.tudelft.simulation.dsol.simulators.DESSSimulatorInterface;
17 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
18 import nl.tudelft.simulation.dsol.statistics.Persistent;
19 import nl.tudelft.simulation.dsol.statistics.charts.XYChart;
20 import nl.tudelft.simulation.event.EventInterface;
21 import nl.tudelft.simulation.event.EventProducerInterface;
22 import nl.tudelft.simulation.event.EventType;
23
24 /***
25 * <p>
26 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
27 * University of Technology </a>, the Netherlands. <br>
28 * See for project information <a
29 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
30 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
31 * License (GPL) </a>, no warranty <br>
32 *
33 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
34 * Jacobs </a>
35 * @version 1.2 Sep 24, 2004
36 * @since 1.4
37 */
38 public class C3TaskC implements ModelInterface
39 {
40 /*** the initial value of the system */
41 private double[] initialValue = null;
42
43 /***
44 * @see nl.tudelft.simulation.dsol.ModelInterface#constructModel(nl.tudelft.simulation.dsol.simulators.SimulatorInterface)
45 */
46 public void constructModel(SimulatorInterface simulator)
47 throws SimRuntimeException, RemoteException
48 {
49 if (this.initialValue == null)
50 {
51 Amplifier amplifier = new Amplifier(
52 (DESSSimulatorInterface) simulator, 1E-15);
53
54
55 amplifier.initialize(0.0, new double[]{0, 0, 0, 0});
56 this.initialValue = amplifier.y(100E-6);
57
58
59 System.out.println(this.initialValue[0] + " "
60 + this.initialValue[1] + " " + this.initialValue[2] + " "
61 + this.initialValue[3]);
62 }
63
64 double trf = new Double(simulator.getReplication().getRunControl()
65 .getTreatment().getProperties().getProperty("TRF"))
66 .doubleValue();
67
68 Amplifier amplifier = new Amplifier((DESSSimulatorInterface) simulator,
69 trf);
70 amplifier.initialize(0.0, this.initialValue);
71 ((DESSSimulatorInterface) simulator).setTimeStep(Math.pow(10, -8));
72
73 XYChart xyChart = new XYChart(simulator, "IR(t) plot (TRF=" + trf + ")");
74 xyChart.add(new AggregatingPersistent("IR(t) (TRF=" + trf + ")",
75 simulator, amplifier, Amplifier.CURRENT_VALUE_CHANGED_EVENT));
76
77 xyChart = new XYChart(simulator, "VL(t) plot (TRF=" + trf + ")");
78 xyChart.add(new AggregatingPersistent("VL(t) (TRF=" + trf + ")",
79 simulator, amplifier, Amplifier.VOLTAGE_VALUE_CHANGED_EVENT));
80
81 xyChart = new XYChart(simulator, "Phase Plane plot dx3(x3) (TRF=" + trf
82 + ")");
83 xyChart
84 .add(new AggregatingPersistent("dX3(X3) (TRF=" + trf + ")",
85 simulator, amplifier,
86 Amplifier.PHASE_PLANE_VALUE_CHANGED_EVENT));
87 }
88
89
90 /***
91 * an aggregated persistent.
92 */
93 private class AggregatingPersistent extends Persistent
94 {
95 /*** the number */
96 private int number = 0;
97
98 /***
99 * constructs a new AggregatingPersistent
100 *
101 * @param description
102 * @param simulator
103 * @param target
104 * @param field
105 * @throws RemoteException
106 */
107 public AggregatingPersistent(String description,
108 SimulatorInterface simulator, EventProducerInterface target,
109 EventType field) throws RemoteException
110 {
111 super(description, simulator, target, field);
112 }
113
114 /***
115 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
116 */
117 public void notify(EventInterface event)
118 {
119 this.number++;
120 if (event.getSource() instanceof SimulatorInterface
121 || this.number % 10 == 0)
122 {
123 super.notify(event);
124 }
125 }
126 }
127 }