sim, kvm: make KvmVM a System parameter
[gem5.git] / ext / dsent / model / optical / GatedLaserSource.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/GatedLaserSource.h"
23
24 #include "model/optical_graph/OpticalWaveguide.h"
25 #include "model/optical_graph/OpticalWavelength.h"
26 #include "model/optical_graph/OpticalLaser.h"
27 #include "model/optical_graph/OpticalGraph.h"
28
29 namespace DSENT
30 {
31 GatedLaserSource::GatedLaserSource(const String& instance_name_, const TechModel* tech_model_)
32 : OpticalModel(instance_name_, tech_model_)
33 {
34 initParameters();
35 initProperties();
36 }
37
38 GatedLaserSource::~GatedLaserSource()
39 {}
40
41 void GatedLaserSource::initParameters()
42 {
43 addParameterName("OutStart");
44 addParameterName("OutEnd");
45 addParameterName("MaxDetectors");
46 return;
47 }
48
49 void GatedLaserSource::initProperties()
50 {
51 addPropertyName("OptUtil", 1.0);
52 addPropertyName("LaserEventTime");
53 return;
54 }
55
56 void GatedLaserSource::constructModel()
57 {
58 // Create Area result
59 Result* area_result = new AtomicResult("Photonic");
60 addAreaResult(area_result);
61 // Create NDD power result
62 Result* energy_result = new AtomicResult("Laser");
63 addEventResult(energy_result);
64
65 // Get parameters
66 WavelengthGroup laser_wavelengths = makeWavelengthGroup(getParameter("OutStart"), getParameter("OutEnd"));
67
68 // Create optical ports
69 createOpticalOutputPort( "Out", laser_wavelengths);
70 // Create the filter
71 createLaser( "Laser", laser_wavelengths);
72 OpticalLaser* laser = getLaser("Laser");
73 // Connect the laser to the output
74 laser->addDownstreamNode(getWaveguide("Out"));
75 }
76
77 void GatedLaserSource::updateModel()
78 {
79 // Get properties
80 double laser_efficiency = getTechModel()->get("Laser->CW->Efficiency");
81 double laser_area = getTechModel()->get("Laser->CW->Area");
82 double laser_diode_loss = getTechModel()->get("Laser->CW->LaserDiodeLoss");
83
84 // Get parameters
85 WavelengthGroup laser_wavelengths = makeWavelengthGroup(getParameter("OutStart"), getParameter("OutEnd"));
86 unsigned int number_wavelengths = laser_wavelengths.second - laser_wavelengths.first + 1;
87 // Update losses
88 OpticalLaser* laser = getLaser("Laser");
89 laser->setLoss(laser_diode_loss);
90 laser->setEfficiency(laser_efficiency);
91 // Update area
92 getAreaResult("Photonic")->setValue(laser_area * number_wavelengths);
93 }
94
95 void GatedLaserSource::evaluateModel()
96 {
97 // Get parameters
98 unsigned int max_detectors = getParameter("MaxDetectors");
99 double laser_event_time = getProperty("LaserEventTime");
100 WavelengthGroup laser_wavelengths = makeWavelengthGroup(getParameter("OutStart"), getParameter("OutEnd"));
101
102 // Get properties
103 double opt_util = getProperty("OptUtil");
104
105 // Create optical graph object
106 OpticalGraph* optical_graph = new OpticalGraph("LaserTrace", this);
107 // Ask optical graph object to perform power optimization
108 bool success = optical_graph->performPowerOpt(getLaser("Laser"), laser_wavelengths, max_detectors, opt_util);
109 if (!success)
110 {
111 Log::printLine(std::cerr, "[Warning] " + getInstanceName() +
112 " -> Wavelengths contains data paths with no possible modulator configurations!");
113 }
114 // Trace the wavelengths the laser is outputting to find the output
115 // power needed by the laser
116 OpticalWavelength* wavelength = optical_graph->traceWavelength(laser_wavelengths, getLaser("Laser"));
117 // Calculate the power needed by the wavelength
118 double laser_power = wavelength->getLaserPower(max_detectors);
119 // Calculate NDD power
120 getEventResult("Laser")->setValue(laser_power * laser_event_time);
121
122 delete wavelength;
123 delete optical_graph;
124 }
125
126 } // namespace DSENT
127