1 /* Copyright (c) 2012 Massachusetts Institute of Technology
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
22 #include "model/optical/ThrottledLaserSource.h"
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"
34 ThrottledLaserSource::ThrottledLaserSource(const String
& instance_name_
, const TechModel
* tech_model_
)
35 : OpticalModel(instance_name_
, tech_model_
), m_wavelength_(NULL
)
41 ThrottledLaserSource::~ThrottledLaserSource()
43 if (m_wavelength_
!= NULL
) delete m_wavelength_
;
46 void ThrottledLaserSource::initParameters()
48 addParameterName("OutStart");
49 addParameterName("OutEnd");
50 addParameterName("MaxDetectors");
51 addParameterName("MinDetectors");
55 void ThrottledLaserSource::initProperties()
57 addPropertyName("OptUtil", 1.0);
58 addPropertyName("LaserEventTime");
62 void ThrottledLaserSource::constructModel()
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();
69 // Create electrical input port for laser control
70 createInputPort( "LaserEnable");
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
)
77 createElectricalEventAtomicResult("Laser" + (String
) i
);
78 getEventInfo("Laser" + (String
) i
)->setTransitionInfo("LaserEnable", TransitionInfo(0.0, 1.0, 0.0));
81 // Create optical ports
82 createOpticalOutputPort( "Out", laser_wavelengths
);
84 createLaser( "Laser", laser_wavelengths
);
85 OpticalLaser
* laser
= getLaser("Laser");
86 // Connect the laser to the output
87 laser
->addDownstreamNode(getWaveguide("Out"));
90 void ThrottledLaserSource::updateModel()
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");
98 WavelengthGroup laser_wavelengths
= makeWavelengthGroup(getParameter("OutStart"), getParameter("OutEnd"));
99 unsigned int number_wavelengths
= laser_wavelengths
.second
- laser_wavelengths
.first
+ 1;
101 OpticalLaser
* laser
= getLaser("Laser");
102 laser
->setLoss(laser_diode_loss
);
103 laser
->setEfficiency(laser_efficiency
);
105 getAreaResult("Photonic")->setValue(laser_area
* number_wavelengths
);
108 void ThrottledLaserSource::evaluateModel()
111 unsigned int max_detectors
= getParameter("MaxDetectors");
112 WavelengthGroup laser_wavelengths
= makeWavelengthGroup(getParameter("OutStart"), getParameter("OutEnd"));
115 double opt_util
= getProperty("OptUtil");
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
);
123 Log::printLine(std::cerr
, "[Warning] " + getInstanceName() +
124 " -> Wavelengths contains data paths with no possible modulator configurations!");
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"));
132 delete optical_graph
;
135 void ThrottledLaserSource::useModel()
138 unsigned int max_detectors
= getParameter("MaxDetectors");
139 unsigned int min_detectors
= getParameter("MinDetectors");
142 double laser_event_time
= getProperty("LaserEventTime");
143 // Get laser enable information
144 const TransitionInfo
& enable_info
= getInputPort("LaserEnable")->getTransitionInfo();
146 for (unsigned int i
= min_detectors
; i
<= max_detectors
; ++i
)
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());