View Javadoc

1   /*
2    * @(#) C3TaskB.java Sep 24, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
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 C3TaskB implements ModelInterface
39  {
40  	/***
41  	 * @see nl.tudelft.simulation.dsol.ModelInterface#constructModel(nl.tudelft.simulation.dsol.simulators.SimulatorInterface)
42  	 */
43  	public void constructModel(SimulatorInterface simulator)
44  			throws SimRuntimeException, RemoteException
45  	{
46  		double trf = new Double(simulator.getReplication().getRunControl()
47  				.getTreatment().getProperties().getProperty("TRF"))
48  				.doubleValue();
49  
50  		Amplifier amplifier = new Amplifier((DESSSimulatorInterface) simulator,
51  				trf);
52  		amplifier.initialize(0.0, new double[]{0, 0, 0, 0});
53  		((DESSSimulatorInterface) simulator).setTimeStep(Math.pow(10, -8));
54  
55  		XYChart xyChart = new XYChart(simulator, "IR(t) plot");
56  		xyChart.add(new AggregatingPersistent("IR(t)", simulator, amplifier,
57  				Amplifier.CURRENT_VALUE_CHANGED_EVENT));
58  
59  		xyChart = new XYChart(simulator, "VL(t) plot");
60  		xyChart.add(new AggregatingPersistent("VL(t)", simulator, amplifier,
61  				Amplifier.VOLTAGE_VALUE_CHANGED_EVENT));
62  	}
63  
64  	/***
65  	 * an aggregated persistent.
66  	 */
67  	private class AggregatingPersistent extends Persistent
68  	{
69  		/*** the number */
70  		private int number = 0;
71  
72  		/***
73  		 * constructs a new AggregatingPersistent
74  		 * 
75  		 * @param description
76  		 * @param simulator
77  		 * @param target
78  		 * @param field
79  		 * @throws RemoteException
80  		 */
81  		public AggregatingPersistent(String description,
82  				SimulatorInterface simulator, EventProducerInterface target,
83  				EventType field) throws RemoteException
84  		{
85  			super(description, simulator, target, field);
86  		}
87  
88  		/***
89  		 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
90  		 */
91  		public void notify(EventInterface event)
92  		{
93  			this.number++;
94  			if (event.getSource() instanceof SimulatorInterface
95  					|| this.number % 100 == 0)
96  			{
97  				super.notify(event);
98  			}
99  		}
100 	}
101 }