OpticalModel.cc revision 10447
1#include "model/OpticalModel.h"
2
3#include "model/PortInfo.h"
4#include "model/EventInfo.h"
5#include "model/optical_graph/OpticalWaveguide.h"
6#include "model/optical_graph/OpticalNode.h"
7#include "model/optical_graph/OpticalLaser.h"
8#include "model/optical_graph/OpticalModulator.h"
9#include "model/optical_graph/OpticalFilter.h"
10#include "model/optical_graph/OpticalDetector.h"
11#include "model/optical_graph/OpticalWavelength.h"
12
13namespace DSENT
14{
15    OpticalModel::OpticalModel(const String& instance_name_, const TechModel* tech_model_)
16        : ElectricalModel(instance_name_, tech_model_)
17    {
18        m_optical_input_ports_ = new Map<PortInfo*>;
19        m_optical_output_ports_ = new Map<PortInfo*>;
20
21        m_waveguides_ = new Map<OpticalWaveguide*>;
22        m_lasers_ = new Map<OpticalLaser*>;
23        m_modulators_ = new Map<OpticalModulator*>;
24        m_filters_ = new Map<OpticalFilter*>;
25        m_detectors_ = new Map<OpticalDetector*>;
26    }
27
28    OpticalModel::~OpticalModel()
29    {
30        delete m_optical_input_ports_;
31        delete m_optical_output_ports_;
32        deletePtrMap<OpticalWaveguide>(m_waveguides_);
33        deletePtrMap<OpticalLaser>(m_lasers_);
34        deletePtrMap<OpticalModulator>(m_modulators_);
35        deletePtrMap<OpticalFilter>(m_filters_);
36        deletePtrMap<OpticalDetector>(m_detectors_);
37        m_optical_input_ports_ = NULL;
38        m_optical_output_ports_ = NULL;
39        m_waveguides_ = NULL;
40        m_lasers_ = NULL;
41        m_modulators_ = NULL;
42        m_filters_ = NULL;
43        m_detectors_ = NULL;
44    }
45
46    // Connect an optical port (input or output) to some OpticalWaveguide
47    void OpticalModel::opticalPortConnect(OpticalModel* connect_model_, const String& port_name_, const String& waveguide_name_)
48    {
49        // Check that the connecting waveguide exists
50        ASSERT(m_waveguides_->keyExist(waveguide_name_), "[Error] " + getInstanceName() +
51            " -> Waveguide '" + waveguide_name_ + "' does not exist!");
52
53        // Check whether the port name is an input or output, assertion error if neither
54        bool is_input = connect_model_->getOpticalInputs()->keyExist(port_name_);
55        bool is_output = connect_model_->getOpticalOutputs()->keyExist(port_name_);
56        ASSERT(is_input || is_output, "[Error] " + getInstanceName() + " -> Model '" + connect_model_->getInstanceName() +
57            "' does not have a port named '" + port_name_ + "'!");
58
59        // Get the two waveguides
60        OpticalWaveguide* port_waveguide = connect_model_->getWaveguide(port_name_);
61        OpticalWaveguide* connect_waveguide = getWaveguide(waveguide_name_);
62
63        // Check that the two waveguides expect the same wavelengths
64        ASSERT((port_waveguide->getWavelengths().first == connect_waveguide->getWavelengths().first) &&
65            (port_waveguide->getWavelengths().second == connect_waveguide->getWavelengths().second),
66            "[Error] " + getInstanceName() + " -> Optical port expects different wavelengths for Model '" +
67            connect_model_->getInstanceName() + "." + port_name_ + "' and waveguide '" + waveguide_name_ + "'!");
68
69        if(is_input)
70        {
71            connect_waveguide->addDownstreamNode(port_waveguide);
72        }
73        else if(is_output)
74        {
75            port_waveguide->addDownstreamNode(connect_waveguide);
76        }
77    }
78
79    //Get Waveguides
80    const Map<OpticalWaveguide*>* OpticalModel::getWaveguides() const
81    {
82        return m_waveguides_;
83    }
84
85    OpticalWaveguide* OpticalModel::getWaveguide(const String& name_)
86    {
87        return m_waveguides_->get(name_);
88    }
89
90    //Get Lasers
91    const Map<OpticalLaser*>* OpticalModel::getLasers() const
92    {
93        return m_lasers_;
94    }
95
96    OpticalLaser* OpticalModel::getLaser(const String& name_)
97    {
98        return m_lasers_->get(name_);
99    }
100
101    //Get Modulators
102    const Map<OpticalModulator*>* OpticalModel::getModulators() const
103    {
104        return m_modulators_;
105    }
106
107    OpticalModulator* OpticalModel::getModulator(const String& name_)
108    {
109        return m_modulators_->get(name_);
110    }
111
112    //Get Filters
113    const Map<OpticalFilter*>* OpticalModel::getFilters() const
114    {
115        return m_filters_;
116    }
117
118    OpticalFilter* OpticalModel::getFilter(const String& name_)
119    {
120        return m_filters_->get(name_);
121    }
122
123    //Get Detectors
124    const Map<OpticalDetector*>* OpticalModel::getDetectors() const
125    {
126        return m_detectors_;
127    }
128
129    OpticalDetector* OpticalModel::getDetector(const String& name_)
130    {
131        return m_detectors_->get(name_);
132    }
133
134    //Get Inputs
135    const Map<PortInfo*>* OpticalModel::getOpticalInputs() const
136    {
137        return m_optical_input_ports_;
138    }
139
140    PortInfo* OpticalModel::getOpticalInputPort(const String& name_)
141    {
142        ASSERT(m_optical_input_ports_->keyExist(name_), "[Error] " + getInstanceName() +
143                " -> Input port (" + name_ + ") does not exist");
144
145        return m_optical_input_ports_->get(name_);
146    }
147
148    const PortInfo* OpticalModel::getOpticalInputPort(const String& name_) const
149    {
150        ASSERT(m_optical_input_ports_->keyExist(name_), "[Error] " + getInstanceName() +
151                " -> Input port (" + name_ + ") does not exist");
152
153        return m_optical_input_ports_->get(name_);
154    }
155
156    //Get Outputs
157    const Map<PortInfo*>* OpticalModel::getOpticalOutputs() const
158    {
159        return m_optical_output_ports_;
160    }
161
162    PortInfo* OpticalModel::getOpticalOutputPort(const String& name_)
163    {
164        ASSERT(m_optical_output_ports_->keyExist(name_), "[Error] " + getInstanceName() +
165                " -> Input port (" + name_ + ") does not exist");
166
167        return m_optical_output_ports_->get(name_);
168    }
169
170    const PortInfo* OpticalModel::getOpticalOutputPort(const String& name_) const
171    {
172        ASSERT(m_optical_output_ports_->keyExist(name_), "[Error] " + getInstanceName() +
173                " -> Input port (" + name_ + ") does not exist");
174
175        return m_optical_output_ports_->get(name_);
176    }
177
178    //-------------------------------------------------------------------------
179    //  Optical Connectivity Creation Functions
180    //-------------------------------------------------------------------------
181    void OpticalModel::createOpticalInputPort(const String& name_, const WavelengthGroup& wavelength_group_)
182    {
183        // Create the new waveguides
184        // This should already check that it has not been previously declared
185        createWaveguide(name_, wavelength_group_);
186        // Add the waveguide name to list of input ports
187        m_optical_input_ports_->set(name_, new PortInfo(name_, wavelength_group_));
188        return;
189    }
190
191    void OpticalModel::createOpticalOutputPort(const String& name_, const WavelengthGroup& wavelength_group_)
192    {
193        // Create the new waveguides (including its waveguide reference)
194        // This should already check that it has not been previously declared
195        createWaveguide(name_, wavelength_group_);
196        // Add the waveguide name to list of output ports
197        m_optical_output_ports_->set(name_, new PortInfo(name_, wavelength_group_));
198        return;
199    }
200
201    // Waveguide creation
202    void OpticalModel::createWaveguide(const String& name_, const WavelengthGroup& wavelengths_)
203    {
204        // Check that the waveguide hasn't been previously declared
205        ASSERT( !m_waveguides_->keyExist(name_), "[Error] " + getInstanceName() +
206            " -> Redeclaration of waveguide " + name_);
207        m_waveguides_->set(name_, new OpticalWaveguide(name_, this, wavelengths_));
208        return;
209    }
210
211    // Laser creation
212    void OpticalModel::createLaser(const String& name_, const WavelengthGroup& wavelengths_)
213    {
214        // Check that the laser hasn't been previously declared
215        ASSERT( !m_lasers_->keyExist(name_), "[Error] " + getInstanceName() +
216            " -> Redeclaration of laser " + name_);
217        m_lasers_->set(name_, new OpticalLaser(name_, this, wavelengths_));
218        return;
219    }
220
221    // Modulator creation
222    void OpticalModel::createModulator(const String& name_, const WavelengthGroup& wavelengths_, bool opt_loss_, OpticalTransmitter* transmitter_)
223    {
224        // Check that the modulator hasn't been previously declared
225        ASSERT( !m_modulators_->keyExist(name_), "[Error] " + getInstanceName() +
226            " -> Redeclaration of modulator " + name_);
227        m_modulators_->set(name_, new OpticalModulator(name_, this, wavelengths_, opt_loss_, transmitter_));
228        return;
229    }
230
231    // Modulator Multiplier creation
232    void OpticalModel::createFilter(const String& name_, const WavelengthGroup& wavelengths_, bool drop_all_, const WavelengthGroup& drop_wavelengths_)
233    {
234        // Check that the filter hasn't been previously declared
235        ASSERT( !m_filters_->keyExist(name_), "[Error] " + getInstanceName() +
236            " -> Redeclaration of filter " + name_);
237        m_filters_->set(name_, new OpticalFilter(name_, this, wavelengths_, drop_all_, drop_wavelengths_));
238        return;
239    }
240
241    // Detector creation
242    void OpticalModel::createDetector(const String& name_, const WavelengthGroup& wavelengths_, OpticalReceiver* receiver_)
243    {
244        // Check that the detector hasn't been previously declared
245        ASSERT( !m_detectors_->keyExist(name_), "[Error] " + getInstanceName() +
246            " -> Redeclaration of detector " + name_);
247        m_detectors_->set(name_, new OpticalDetector(name_, this, wavelengths_, receiver_));
248        return;
249    }
250
251    //-------------------------------------------------------------------------
252
253    // Assign a waveguide to be downstream from another waveguide
254    // assign downtream_waveguide_name_ = upstream_waveguide_name_
255    void OpticalModel::opticalAssign(const String& downstream_waveguide_name_, const String& upstream_waveguide_name_)
256    {
257        ASSERT(getWaveguides()->keyExist(downstream_waveguide_name_), "[Error] " + getInstanceName() + " -> Waveguide '" +
258            downstream_waveguide_name_ + "' does not exist!");
259
260        ASSERT(getWaveguides()->keyExist(upstream_waveguide_name_), "[Error] " + getInstanceName() + " -> Waveguide '" +
261            upstream_waveguide_name_ + "' does not exist!");
262
263        // Get the two waveguides
264        OpticalWaveguide* upstream_waveguide = getWaveguide(upstream_waveguide_name_);
265        OpticalWaveguide* downstream_waveguide = getWaveguide(downstream_waveguide_name_);
266
267        // Check that the two waveguides expect the same wavelengths
268        ASSERT((upstream_waveguide->getWavelengths().first == downstream_waveguide->getWavelengths().first) &&
269            (upstream_waveguide->getWavelengths().second == downstream_waveguide->getWavelengths().second),
270            "[Error] " + getInstanceName() + " -> Assignment expects different wavelengths for waveguide '" +
271                upstream_waveguide_name_ + "' and waveguide '" + downstream_waveguide_name_ + "'!");
272
273        // Connect the downstream waveguide and the upstream waveguide
274        upstream_waveguide->addDownstreamNode(downstream_waveguide);
275        return;
276    }
277} // namespace DSENT
278