sim, kvm: make KvmVM a System parameter
[gem5.git] / ext / dsent / model / optical / ThrottledLaserSource.cc
1 /* Copyright (c) 2012 Massachusetts Institute of Technology
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
22 #include "model/optical/ThrottledLaserSource.h"
23
24 #include "model/PortInfo.h"
25 #include "model/TransitionInfo.h"
26 #include "model/EventInfo.h"
27 #include "model/optical_graph/OpticalWaveguide.h"
28 #include "model/optical_graph/OpticalWavelength.h"
29 #include "model/optical_graph/OpticalLaser.h"
30 #include "model/optical_graph/OpticalGraph.h"
31
32 namespace DSENT
33 {
34 ThrottledLaserSource::ThrottledLaserSource(const String& instance_name_, const TechModel* tech_model_)
35 : OpticalModel(instance_name_, tech_model_), m_wavelength_(NULL)
36 {
37 initParameters();
38 initProperties();
39 }
40
41 ThrottledLaserSource::~ThrottledLaserSource()
42 {
43 if (m_wavelength_ != NULL) delete m_wavelength_;
44 }
45
46 void ThrottledLaserSource::initParameters()
47 {
48 addParameterName("OutStart");
49 addParameterName("OutEnd");
50 addParameterName("MaxDetectors");
51 addParameterName("MinDetectors");
52 return;
53 }
54
55 void ThrottledLaserSource::initProperties()
56 {
57 addPropertyName("OptUtil", 1.0);
58 addPropertyName("LaserEventTime");
59 return;
60 }
61
62 void ThrottledLaserSource::constructModel()
63 {
64 // Get parameters
65 WavelengthGroup laser_wavelengths = makeWavelengthGroup(getParameter("OutStart"), getParameter("OutEnd"));
66 unsigned int max_detectors = getParameter("MaxDetectors").toUInt();
67 unsigned int min_detectors = getParameter("MinDetectors").toUInt();
68
69 // Create electrical input port for laser control
70 createInputPort( "LaserEnable");
71
72 // Create Area result
73 addAreaResult(new AtomicResult("Photonic"));
74 // Create event result for each detector number possibility
75 for (unsigned int i = min_detectors; i <= max_detectors; ++i)
76 {
77 createElectricalEventAtomicResult("Laser" + (String) i);
78 getEventInfo("Laser" + (String) i)->setTransitionInfo("LaserEnable", TransitionInfo(0.0, 1.0, 0.0));
79 }
80
81 // Create optical ports
82 createOpticalOutputPort( "Out", laser_wavelengths);
83 // Create the filter
84 createLaser( "Laser", laser_wavelengths);
85 OpticalLaser* laser = getLaser("Laser");
86 // Connect the laser to the output
87 laser->addDownstreamNode(getWaveguide("Out"));
88 }
89
90 void ThrottledLaserSource::updateModel()
91 {
92 // Get properties
93 double laser_efficiency = getTechModel()->get("Laser->CW->Efficiency").toDouble();
94 double laser_area = getTechModel()->get("Laser->CW->Area").toDouble();
95 double laser_diode_loss = getTechModel()->get("Laser->CW->LaserDiodeLoss");
96
97 // Get parameters
98 WavelengthGroup laser_wavelengths = makeWavelengthGroup(getParameter("OutStart"), getParameter("OutEnd"));
99 unsigned int number_wavelengths = laser_wavelengths.second - laser_wavelengths.first + 1;
100 // Update losses
101 OpticalLaser* laser = getLaser("Laser");
102 laser->setLoss(laser_diode_loss);
103 laser->setEfficiency(laser_efficiency);
104 // Update area
105 getAreaResult("Photonic")->setValue(laser_area * number_wavelengths);
106 }
107
108 void ThrottledLaserSource::evaluateModel()
109 {
110 // Get parameters
111 unsigned int max_detectors = getParameter("MaxDetectors");
112 WavelengthGroup laser_wavelengths = makeWavelengthGroup(getParameter("OutStart"), getParameter("OutEnd"));
113
114 // Get properties
115 double opt_util = getProperty("OptUtil");
116
117 // Create optical graph object
118 OpticalGraph* optical_graph = new OpticalGraph("LaserTrace", this);
119 // Ask optical graph object to perform power optimization
120 bool success = optical_graph->performPowerOpt(getLaser("Laser"), laser_wavelengths, max_detectors, opt_util);
121 if (!success)
122 {
123 Log::printLine(std::cerr, "[Warning] " + getInstanceName() +
124 " -> Wavelengths contains data paths with no possible modulator configurations!");
125 }
126
127 // Trace the wavelengths the laser is outputting to find the output
128 // power needed by the laser
129 if (m_wavelength_ != NULL) delete m_wavelength_;
130 m_wavelength_ = optical_graph->traceWavelength(laser_wavelengths, getLaser("Laser"));
131
132 delete optical_graph;
133 }
134
135 void ThrottledLaserSource::useModel()
136 {
137 // Get parameters
138 unsigned int max_detectors = getParameter("MaxDetectors");
139 unsigned int min_detectors = getParameter("MinDetectors");
140
141 // Get properties
142 double laser_event_time = getProperty("LaserEventTime");
143 // Get laser enable information
144 const TransitionInfo& enable_info = getInputPort("LaserEnable")->getTransitionInfo();
145
146 for (unsigned int i = min_detectors; i <= max_detectors; ++i)
147 {
148 // Calculate the power needed by the wavelength
149 double laser_power = m_wavelength_->getLaserPower(i);
150 // Calculate the laser event power by calculating the amount
151 // of time the laser is on
152 getEventResult("Laser" + (String) i)->setValue(laser_power * laser_event_time *
153 enable_info.getFrequencyMultiplier() * enable_info.getProbability1());
154 }
155 }
156
157 } // namespace DSENT
158