11.3.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

pypho_cfiber.py 6.96 KB
Newer Older
Arne Striegler's avatar
v1.0.0  
Arne Striegler committed
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
#!/usr/bin/env python
#
#  Copyright 2018 Arne Striegler (arne.striegler@hm.edu)
#
#
#
# Simulates a fiber ...fast!
#
#
########################################################################

import numpy as np
import sys
from pypho_functions import *
from pypho_fiber_birefringence import pypho_fiber_birefringence
import time

import copy
from speedfiber import *
#from speedtest import *

########################################################################

class pypho_cfiber(object):
    def __init__(self, glova = None, fibertype = None, D = None, S = None, gamma = None, alpha = None, l = None, birefarray = None, phi_max = None):

        if glova == None:
            print ("ERROR: You must define the global variables")
            sys.exit("PyPho stopped!")

        self.glova     = glova
        self.D         = None
        self.S         = None
        self.l         = None
        self.gamma     = None
        self.alpha     = None
        self.birefarray = None
        self.nos        = None
        self.phi_max     = None

        self.set(fibertype, D, S, gamma, alpha, l, birefarray, phi_max)


########################################################################

    def __call__(self, E = None, fibertype = None, D = None, S = None, gamma = None, alpha = None, l = None, birefarray = None, phi_max = None):

        self.set(fibertype, D, S, gamma, alpha, l, birefarray, phi_max)

        if self.glova.cloud :
            E.append(self.get_parameters())
            return E
        else :
            return self.transmit(E, fibertype, D, S, gamma, alpha, l, phi_max)

########################################################################

    def transmit(self, E = None, fibertype = None, D = None, S = None, gamma = None, alpha = None, l = None, phi_max = None):
        """Transmit the signal"""

        if E == None:
            print ("ERROR: You must define an optical signal")
            sys.exit("PyPho stopped!")

        if type(E) != list:
            E = [E]

        self.set(fibertype, D, S, gamma, alpha, l, phi_max)

        self.E = E

        self.gamma_intern = self.gamma * 1e-3
        self.max_step = 200

        z = 0

        #for Ei in E:
        self.fibtrans(z)
        #z += 1

        return self.E


 ########################################################################

    def fibtrans(self, zsep):
        """Calculate step"""

        print('Start!')  

        tic0 = time.time()   
        n = self.glova.sps*self.glova.nos
        #Ef_out = np.zeros((1,n)) + 1j*np.ones((1,n))
        Ex_out = np.zeros(n) + 1j*np.ones(n)
        Ey_out = np.zeros(n) + 1j*np.ones(n)
        birefarraydoubles = np.zeros((len(self.birefarray), 3))
        for i in range (0, len(self.birefarray)):
            birefarraydoubles[i,0] = self.birefarray[i].angle
            birefarraydoubles[i,1] = self.birefarray[i].z_point
            birefarraydoubles[i,2] = self.birefarray[i].delta_beta
            
        cyfiber(self.glova.sps*self.glova.nos, self.l, np.asarray(self.E[zsep]['E'][0]), np.asarray(self.E[zsep]['E'][1]),
                self.alpha, self.gamma_intern, self.phi_max, birefarraydoubles, len(self.birefarray), self.max_step, self.beta_fac,
                np.asarray(1j * scipy.fftpack.fftshift( self.Domega )), Ex_out, Ey_out)
           
        self.E[zsep]['E'][0] = Ex_out
        self.E[zsep]['E'][1] = Ey_out
 
        print ('Fertig: ', time.time() - tic0 )


########################################################################
    def get_parameters(self):
        """Get all fiber parameters set by the user"""
        biref_angle = []
        biref_zpoint = []
        biref_delta_beta = []
        for x in self.birefarray:
            biref_angle.append(x.angle)
            biref_zpoint.append(x.z_point)
            biref_delta_beta.append(x.delta_beta)

        params = {'type' : 'fiber', 'D':  self.D, 'S' : self.S,'l' : self.l, 'gamma' : self.gamma, 'alpha' : 4.343e3*self.alpha, 'biref_delta_beta' : biref_delta_beta, 'biref_zpoint' : biref_zpoint, 'biref_angle' : biref_angle, 'useYPol' : True}
        return params

########################################################################
    def set(self, fibertype = None, D = None, S = None, gamma = None, alpha = None, l = None, birefarray = None, phi_max = None):
        """Set fibre properties"""


        if fibertype ==  'SSMF':
            self.D         = 17.0                   # [ps/(nm km)]
            self.S         = 0.0                         # [ps/(nm2 km)]
            self.gamma     = 1.14                   # [1/(W m)]
            self.alpha     = db2neper(0.20)  / 1.0e3     # [1/m]


        if fibertype == 'DCF':
            self.D         = -100.0                    # [ps/(nm km)]
            self.S         = 0.0                        # [ps/(nm2 km)]
            self.gamma     = 1.7                        # [1/(W m)]
            self.alpha     = db2neper(0.20)  / 1.0e3   # [1/m]


        if D == None and fibertype == None and self.D == None:
            print ("Warning: D and fibertype not specified, so I set D = 16.8 ps/nm/km")
            self.D             = 17.0
        elif D != None:
            self.D = D

        if S == None and fibertype == None and self.S == None:
            print ("Warning: S and fibertype not specified, so I set S = 0.68 ps/nm**2/km")
            self.S             = 0.68
        elif S != None:
            self.S = S

        if gamma == None and fibertype == None and self.gamma == None:
            print ("Warning: gamma and fibertype not specified, so I set gamma = 1.14 1/W/km")
            self.gamma            = 1.14
        elif gamma != None:
            self.gamma = gamma

        if alpha == None and fibertype == None and self.alpha == None:
            print ("Warning: alpha and fibertype not specified, so I set alpha = 0.25 dB/km")
            self.alpha         = db2neper(0.25)  / 1.0e3
        elif alpha != None:
            self.alpha = db2neper(alpha) / 1.0e3

        if l == None and fibertype == None and self.l == None:
            print ("Warning: L and fibertype not specified, so I set L = 80 km")
            self.l         = 80e3
        elif l != None:
            self.l = l
            
        if phi_max == None and self.phi_max == None:
            print ("Warning: phi_max not specified, so I set phi_max = 1e-3")
            self.phi_max         = 1e-3
        elif phi_max != None:
            self.phi_max = phi_max

        if birefarray == None and self.birefarray == None:
            nosiref = pypho_fiber_birefringence (0.0, 0.0, 0.0)
            self.birefarray = [nosiref]
        elif birefarray != None:
            self.birefarray = birefarray

        (self.beta_2, self.beta_3) =  DS2beta(self.D, self.S, self.glova.lambda0)

        self.Domega     = 2.0 * np.pi * (self.glova.freqax - 1*self.glova.f0) / 1.0e12
        self.beta_fac   = -1j * fftshift  ( self.beta_2*0.5e24 * self.Domega**2.0 + self.beta_3*1.0e36 / 6.0  * self.Domega**3.0)


########################################################################