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