summaryrefslogtreecommitdiff
path: root/ext/dsent/model/OpticalModel.cc
blob: 7236d6bdae6668c0e56f1441c90dcc9899a2216b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#include "model/OpticalModel.h"

#include "model/PortInfo.h"
#include "model/EventInfo.h"
#include "model/optical_graph/OpticalWaveguide.h"
#include "model/optical_graph/OpticalNode.h"
#include "model/optical_graph/OpticalLaser.h"
#include "model/optical_graph/OpticalModulator.h"
#include "model/optical_graph/OpticalFilter.h"
#include "model/optical_graph/OpticalDetector.h"
#include "model/optical_graph/OpticalWavelength.h"

namespace DSENT
{
    OpticalModel::OpticalModel(const String& instance_name_, const TechModel* tech_model_)
        : ElectricalModel(instance_name_, tech_model_)
    {
        m_optical_input_ports_ = new Map<PortInfo*>;
        m_optical_output_ports_ = new Map<PortInfo*>;

        m_waveguides_ = new Map<OpticalWaveguide*>;
        m_lasers_ = new Map<OpticalLaser*>;
        m_modulators_ = new Map<OpticalModulator*>;
        m_filters_ = new Map<OpticalFilter*>;
        m_detectors_ = new Map<OpticalDetector*>;
    }

    OpticalModel::~OpticalModel()
    {
        delete m_optical_input_ports_;
        delete m_optical_output_ports_;
        deletePtrMap<OpticalWaveguide>(m_waveguides_);
        deletePtrMap<OpticalLaser>(m_lasers_);
        deletePtrMap<OpticalModulator>(m_modulators_);
        deletePtrMap<OpticalFilter>(m_filters_);
        deletePtrMap<OpticalDetector>(m_detectors_);
        m_optical_input_ports_ = NULL;
        m_optical_output_ports_ = NULL;
        m_waveguides_ = NULL;
        m_lasers_ = NULL;
        m_modulators_ = NULL;
        m_filters_ = NULL;
        m_detectors_ = NULL;
    }

    // Connect an optical port (input or output) to some OpticalWaveguide
    void OpticalModel::opticalPortConnect(OpticalModel* connect_model_, const String& port_name_, const String& waveguide_name_)
    {
        // Check that the connecting waveguide exists
        ASSERT(m_waveguides_->keyExist(waveguide_name_), "[Error] " + getInstanceName() +
            " -> Waveguide '" + waveguide_name_ + "' does not exist!");
            
        // Check whether the port name is an input or output, assertion error if neither
        bool is_input = connect_model_->getOpticalInputs()->keyExist(port_name_);
        bool is_output = connect_model_->getOpticalOutputs()->keyExist(port_name_);                        
        ASSERT(is_input || is_output, "[Error] " + getInstanceName() + " -> Model '" + connect_model_->getInstanceName() + 
            "' does not have a port named '" + port_name_ + "'!");
        
        // Get the two waveguides
        OpticalWaveguide* port_waveguide = connect_model_->getWaveguide(port_name_);
        OpticalWaveguide* connect_waveguide = getWaveguide(waveguide_name_);
        
        // Check that the two waveguides expect the same wavelengths
        ASSERT((port_waveguide->getWavelengths().first == connect_waveguide->getWavelengths().first) &&
            (port_waveguide->getWavelengths().second == connect_waveguide->getWavelengths().second),
            "[Error] " + getInstanceName() + " -> Optical port expects different wavelengths for Model '" + 
            connect_model_->getInstanceName() + "." + port_name_ + "' and waveguide '" + waveguide_name_ + "'!");
        
        if(is_input)
        {
            connect_waveguide->addDownstreamNode(port_waveguide);
        }
        else if(is_output)
        {
            port_waveguide->addDownstreamNode(connect_waveguide);
        }
    }
        
    //Get Waveguides
    const Map<OpticalWaveguide*>* OpticalModel::getWaveguides() const
    {
        return m_waveguides_;
    }
    
    OpticalWaveguide* OpticalModel::getWaveguide(const String& name_)
    {
        return m_waveguides_->get(name_);
    }

    //Get Lasers
    const Map<OpticalLaser*>* OpticalModel::getLasers() const
    {
        return m_lasers_;
    }

    OpticalLaser* OpticalModel::getLaser(const String& name_)
    {
        return m_lasers_->get(name_);
    }

    //Get Modulators
    const Map<OpticalModulator*>* OpticalModel::getModulators() const
    {
        return m_modulators_;
    }
    
    OpticalModulator* OpticalModel::getModulator(const String& name_)
    {
        return m_modulators_->get(name_);
    }

    //Get Filters
    const Map<OpticalFilter*>* OpticalModel::getFilters() const
    {
        return m_filters_;
    }
    
    OpticalFilter* OpticalModel::getFilter(const String& name_)
    {
        return m_filters_->get(name_);
    }

    //Get Detectors
    const Map<OpticalDetector*>* OpticalModel::getDetectors() const
    {
        return m_detectors_;
    }

    OpticalDetector* OpticalModel::getDetector(const String& name_)
    {
        return m_detectors_->get(name_);
    }
        
    //Get Inputs
    const Map<PortInfo*>* OpticalModel::getOpticalInputs() const
    {
        return m_optical_input_ports_;
    }
    
    PortInfo* OpticalModel::getOpticalInputPort(const String& name_)
    {
        ASSERT(m_optical_input_ports_->keyExist(name_), "[Error] " + getInstanceName() +
                " -> Input port (" + name_ + ") does not exist");

        return m_optical_input_ports_->get(name_);
    }

    const PortInfo* OpticalModel::getOpticalInputPort(const String& name_) const
    {
        ASSERT(m_optical_input_ports_->keyExist(name_), "[Error] " + getInstanceName() +
                " -> Input port (" + name_ + ") does not exist");

        return m_optical_input_ports_->get(name_);
    }
    
    //Get Outputs
    const Map<PortInfo*>* OpticalModel::getOpticalOutputs() const
    {
        return m_optical_output_ports_;
    }

    PortInfo* OpticalModel::getOpticalOutputPort(const String& name_)
    {
        ASSERT(m_optical_output_ports_->keyExist(name_), "[Error] " + getInstanceName() +
                " -> Input port (" + name_ + ") does not exist");

        return m_optical_output_ports_->get(name_);
    }

    const PortInfo* OpticalModel::getOpticalOutputPort(const String& name_) const
    {
        ASSERT(m_optical_output_ports_->keyExist(name_), "[Error] " + getInstanceName() +
                " -> Input port (" + name_ + ") does not exist");

        return m_optical_output_ports_->get(name_);
    }

    //-------------------------------------------------------------------------
    //  Optical Connectivity Creation Functions
    //-------------------------------------------------------------------------
    void OpticalModel::createOpticalInputPort(const String& name_, const WavelengthGroup& wavelength_group_)
    {
        // Create the new waveguides
        // This should already check that it has not been previously declared
        createWaveguide(name_, wavelength_group_);
        // Add the waveguide name to list of input ports
        m_optical_input_ports_->set(name_, new PortInfo(name_, wavelength_group_));
        return;
    }

    void OpticalModel::createOpticalOutputPort(const String& name_, const WavelengthGroup& wavelength_group_)
    {
        // Create the new waveguides (including its waveguide reference)
        // This should already check that it has not been previously declared
        createWaveguide(name_, wavelength_group_);
        // Add the waveguide name to list of output ports
        m_optical_output_ports_->set(name_, new PortInfo(name_, wavelength_group_));
        return;
    }

    // Waveguide creation
    void OpticalModel::createWaveguide(const String& name_, const WavelengthGroup& wavelengths_)
    {
        // Check that the waveguide hasn't been previously declared
        ASSERT( !m_waveguides_->keyExist(name_), "[Error] " + getInstanceName() +
            " -> Redeclaration of waveguide " + name_);
        m_waveguides_->set(name_, new OpticalWaveguide(name_, this, wavelengths_));
        return;
    }

    // Laser creation
    void OpticalModel::createLaser(const String& name_, const WavelengthGroup& wavelengths_)
    {
        // Check that the laser hasn't been previously declared
        ASSERT( !m_lasers_->keyExist(name_), "[Error] " + getInstanceName() +
            " -> Redeclaration of laser " + name_);
        m_lasers_->set(name_, new OpticalLaser(name_, this, wavelengths_));
        return;
    }

    // Modulator creation
    void OpticalModel::createModulator(const String& name_, const WavelengthGroup& wavelengths_, bool opt_loss_, OpticalTransmitter* transmitter_)
    {
        // Check that the modulator hasn't been previously declared
        ASSERT( !m_modulators_->keyExist(name_), "[Error] " + getInstanceName() +
            " -> Redeclaration of modulator " + name_);
        m_modulators_->set(name_, new OpticalModulator(name_, this, wavelengths_, opt_loss_, transmitter_));
        return;
    }

    // Modulator Multiplier creation
    void OpticalModel::createFilter(const String& name_, const WavelengthGroup& wavelengths_, bool drop_all_, const WavelengthGroup& drop_wavelengths_)
    {
        // Check that the filter hasn't been previously declared
        ASSERT( !m_filters_->keyExist(name_), "[Error] " + getInstanceName() +
            " -> Redeclaration of filter " + name_);
        m_filters_->set(name_, new OpticalFilter(name_, this, wavelengths_, drop_all_, drop_wavelengths_));
        return;
    }

    // Detector creation    
    void OpticalModel::createDetector(const String& name_, const WavelengthGroup& wavelengths_, OpticalReceiver* receiver_)
    {
        // Check that the detector hasn't been previously declared
        ASSERT( !m_detectors_->keyExist(name_), "[Error] " + getInstanceName() +
            " -> Redeclaration of detector " + name_);
        m_detectors_->set(name_, new OpticalDetector(name_, this, wavelengths_, receiver_));
        return;
    }
    
    //-------------------------------------------------------------------------    

    // Assign a waveguide to be downstream from another waveguide
    // assign downtream_waveguide_name_ = upstream_waveguide_name_
    void OpticalModel::opticalAssign(const String& downstream_waveguide_name_, const String& upstream_waveguide_name_)
    {
        ASSERT(getWaveguides()->keyExist(downstream_waveguide_name_), "[Error] " + getInstanceName() + " -> Waveguide '" +
            downstream_waveguide_name_ + "' does not exist!");

        ASSERT(getWaveguides()->keyExist(upstream_waveguide_name_), "[Error] " + getInstanceName() + " -> Waveguide '" +
            upstream_waveguide_name_ + "' does not exist!");
        
        // Get the two waveguides
        OpticalWaveguide* upstream_waveguide = getWaveguide(upstream_waveguide_name_);
        OpticalWaveguide* downstream_waveguide = getWaveguide(downstream_waveguide_name_);        
        
        // Check that the two waveguides expect the same wavelengths
        ASSERT((upstream_waveguide->getWavelengths().first == downstream_waveguide->getWavelengths().first) &&
            (upstream_waveguide->getWavelengths().second == downstream_waveguide->getWavelengths().second),
            "[Error] " + getInstanceName() + " -> Assignment expects different wavelengths for waveguide '" +
                upstream_waveguide_name_ + "' and waveguide '" + downstream_waveguide_name_ + "'!");

        // Connect the downstream waveguide and the upstream waveguide
        upstream_waveguide->addDownstreamNode(downstream_waveguide);
        return;
    }
} // namespace DSENT