aboutsummaryrefslogtreecommitdiff
path: root/src/devices/generic_waveguide.h
blob: d70467838854af4ab6351098313a0bdb9ba1214e (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
#pragma once

#include "devices/generic_transmission_device.h"

using std::isfinite;

class GenericWaveguide : public GenericTransmissionDevice {
public:
    GenericWaveguide(sc_module_name name
                    , const double &length = 0
                    , const double &loss = 0
                    , const double &neff = 1
                    , const double &ng = 1
                    , const double &D = 0
                    , const double &lambda0 = 1.55e-6)
    : GenericTransmissionDevice(name, 2)
    {
        cerr << "GenericWaveguide is disabled (not working)." << endl;
        exit(1);

        setLength(length);
        setLoss(loss);
        setEffectiveIndex(neff);
        setGroupIndex(ng);
        setDispersion(D);
        setLambda0(lambda0);
    }

    void setLength(const double &length)
    {
        assert(isfinite(length) && length >= 0);
        m_length = length;
    }

    void setLoss(const double &loss)
    {
        cout << loss << endl;
        assert(isfinite(loss));
        m_loss = loss;
    }

    void setEffectiveIndex(const double &neff)
    {
        assert(isfinite(neff) && neff >= 0);
        m_neff = neff;
    }

    void setGroupIndex(const double &ng)
    {
        assert(isfinite(ng) && ng >= 0);
        m_ng = ng;
    }

    void setDispersion(const double &D)
    {
        assert(isfinite(D));
        m_D = D;
    }

    void setLambda0(const double &lambda0)
    {
        assert(isfinite(lambda0) && lambda0 > 0);
        m_lambda0 = lambda0;
    }


private:

    virtual void prepareTM()
    {
        TM.clear();
        TM.resize(nports);

        const double c = 299792458.0;
        double lambda0 = m_lambda0;
        double transmission = pow(10.0, -(m_loss * m_length)/20.0);
        double two_pi_L = 2 * M_PI * m_length;
        double dphi_0 = fmod(two_pi_L * m_neff, 2 * M_PI);

        // The following 2 lines are wrong...
        double dphi_1 = - two_pi_L * m_ng / lambda0 / lambda0; // Here it should be -2pi*L*ng/(lambda*lambda0) (instead of lambda0^2)
        double dphi_2 = two_pi_L * 2 * m_ng / lambda0 / lambda0 / lambda0;

        double group_delay_0 = m_length * m_ng / c;
        double group_delay_1 = m_length * m_D;

        TM.lambda0 = lambda0;
        TM.Mactive = {false, true, true, false};
        TM.Malpha = {
            {0},
            {transmission},
            {transmission},
            {0}};
        TM.Mphi = {
            {0},
            {dphi_0, dphi_1, dphi_2},
            {dphi_0, dphi_1, dphi_2},
            {0}};
        TM.Mtau = {
            {0},
            {group_delay_0, group_delay_1},
            {group_delay_0, group_delay_1},
            {0}};

        // cout << "----------- " << name() << " -----------" << endl;
        // cout << "- alpha:        " << TM.Malpha[1][0] << " (V/m)/(V/m)" << endl;
        // cout << "- transmission: " << pow(TM.Malpha[1][0],2.0) << " W/W" << endl;
        // cout << "- phi:          " << TM.Mphi[1][0] << " rad" << endl;
        // cout << "- dphi/dlambda: " << TM.Mphi[1][1] << " rad/m" << endl;
        // cout << "- group delay:  " << TM.Mtau[1][0] << " s" << endl;
    }

    double m_loss; // loss in dB/m
    double m_neff; // real part of neff
    double m_ng; // (real part of) ng
    double m_D; // dispersion
    double m_lambda0; // dispersion
    double m_length; // waveguide length
};