View Javadoc

1   /*
2    * @(#) Amplifier.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.formalisms.dess.DifferentialEquation;
15  import nl.tudelft.simulation.dsol.simulators.DESSSimulatorInterface;
16  import nl.tudelft.simulation.event.EventInterface;
17  import nl.tudelft.simulation.event.EventListenerInterface;
18  import nl.tudelft.simulation.event.EventType;
19  import nl.tudelft.simulation.event.TimedEvent;
20  import nl.tudelft.simulation.jstats.ode.integrators.NumericalIntegrator;
21  import cern.colt.matrix.impl.DenseDoubleMatrix2D;
22  import cern.colt.matrix.linalg.EigenvalueDecomposition;
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 Amplifier extends DifferentialEquation implements
39  		EventListenerInterface
40  {
41  	/*** event fired whenever the current changes */
42  	public static final EventType CURRENT_VALUE_CHANGED_EVENT = new EventType(
43  			"CURRENT_VALUE_CHANGED_EVENT");
44  
45  	/*** event fired whenever the voltage changes */
46  	public static final EventType VOLTAGE_VALUE_CHANGED_EVENT = new EventType(
47  			"VOLTAGE_VALUE_CHANGED_EVENT");
48  
49  	/***
50  	 * the PHASE_PLANE_VALUE_CHANGED_EVENT is fired whenever the phase value
51  	 * changes
52  	 */
53  	public static final EventType PHASE_PLANE_VALUE_CHANGED_EVENT = new EventType(
54  			"PHASE_PLANE_VALUE_CHANGED_EVENT");
55  
56  	/*** the L1 constant */
57  	private double l1 = 79.9 * Math.pow(10, -6);
58  
59  	/*** the L3 constant */
60  	private double l3 = 232.0 * Math.pow(10, -6);
61  
62  	/*** the C2 constant */
63  	private double c2 = 17.9 * Math.pow(10, -9);
64  
65  	/*** the C4 constant */
66  	private double c4 = 9.66 * Math.pow(10, -9);
67  
68  	/*** the resistor */
69  	private Resistor r = null;
70  
71  	/*** the RL constant */
72  	private double rl = 52.4;
73  
74  	/*** the voltage */
75  	private double vdc = 5;
76  
77  	/***
78  	 * constructs a new Amplifier
79  	 * 
80  	 * @param simulator the simulator to use
81  	 * @param trf the rise fall time
82  	 */
83  	public Amplifier(DESSSimulatorInterface simulator, double trf)
84  	{
85  		super(simulator, Math.pow(10, -12), NumericalIntegrator.RUNGEKUTTA4);
86  		this.r = new Resistor(trf);
87  		this.addListener(this, VALUE_CHANGED_EVENT[1]);
88  		this.addListener(this, VALUE_CHANGED_EVENT[2]);
89  	}
90  
91  	/***
92  	 * @see nl.tudelft.simulation.jstats.ode.DifferentialEquationInterface#dy(double,
93  	 *      double[])
94  	 */
95  	public double[] dy(double x, double[] y)
96  	{
97  		double[] dy = new double[4];
98  		dy[0] = (-y[1] + this.vdc) / this.l1;
99  		dy[1] = (y[0] - y[1] / this.r.getValue(x) - y[2]) / this.c2;
100 		dy[2] = (y[1] - this.rl * y[2] - y[3]) / this.l3;
101 		dy[3] = y[2] / this.c4;
102 		return dy;
103 	}
104 
105 	/***
106 	 * returns the eigenValue decomposition of the amplifier
107 	 * 
108 	 * @param time the time
109 	 * @return the eigenValueDecomposition
110 	 */
111 	public EigenvalueDecomposition getEigenValues(double time)
112 	{
113 		double[][] matrix = {{0, -1 / l1, 0, 0},
114 				{1 / c2, -1 / (c2 * this.r.getValue(time)), -1 / c2, 0},
115 				{1 / l3, 0, -rl / l3, -1 / l3}, {0, 0, 1 / c4, 0}};
116 		return new EigenvalueDecomposition(new DenseDoubleMatrix2D(matrix));
117 	}
118 
119 	/***
120 	 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
121 	 */
122 	public synchronized void notify(EventInterface event)
123 			throws RemoteException
124 	{
125 		super.notify(event);
126 		if (event.getSource().equals(this))
127 		{
128 			double time = ((TimedEvent) event).getTimeStamp();
129 			if (event.getType().equals(VALUE_CHANGED_EVENT[1]))
130 			{
131 				this.fireEvent(CURRENT_VALUE_CHANGED_EVENT, ((Number) event
132 						.getContent()).doubleValue()
133 						/ this.r.getValue(time), time);
134 			}
135 			if (event.getType().equals(VALUE_CHANGED_EVENT[2]))
136 			{
137 				this.fireEvent(VOLTAGE_VALUE_CHANGED_EVENT, ((Number) event
138 						.getContent()).doubleValue()
139 						* this.rl, time);
140 				this.fireEvent(PHASE_PLANE_VALUE_CHANGED_EVENT, new Double(this
141 						.dy(super.previousX, super.previousY)[2]),
142 						((Number) event.getContent()).doubleValue());
143 			}
144 			return;
145 		}
146 	}
147 
148 	/***
149 	 * The resistor class specifies the modulus function.
150 	 */
151 	public static class Resistor
152 	{
153 		/*** the lower minimal on value */
154 		private double on = 5.0 * Math.pow(10, -2);
155 
156 		/*** the highest off value of the resistor */
157 		private double off = 5.0 * Math.pow(10, 6);
158 
159 		/*** the time rise fall constant */
160 		private double trf = 1 * Math.pow(10, -15);
161 
162 		/*** the period of the resistor */
163 		private double period = 10 * Math.pow(10, -6);
164 
165 		/***
166 		 * constructs a new Resistor
167 		 */
168 		public Resistor()
169 		{
170 			super();
171 		}
172 
173 		/***
174 		 * constructs a new Resistor
175 		 * 
176 		 * @param trf the specific trf to use
177 		 */
178 		public Resistor(double trf)
179 		{
180 			super();
181 			this.trf = trf;
182 		}
183 
184 		/***
185 		 * returns the value of the resistor
186 		 * 
187 		 * @param time the current time
188 		 * @return the value the value
189 		 */
190 		public double getValue(double time)
191 		{
192 			time = time % this.period;
193 			if (time < this.trf)
194 			{
195 				return on + time / this.trf * (off - on);
196 			}
197 			if (time < 0.5 * this.period)
198 			{
199 				return this.off;
200 			}
201 			if (time < 0.5 * this.period + this.trf)
202 			{
203 				return this.off - (time - 0.5 * period) / this.trf * (off - on);
204 			}
205 			return on;
206 		}
207 	}
208 }