Calculator.py
def assemble_analytical_H_field(self, n, side):
        """Create analytical expression of H field at either side of the n,n+1 interface; store as a class variable. 
        
        IMPORTANT: The H field calculated in this method is specified for the problem when there is no incident field at entrance or exit, 
        and there is a oscillating charge (and corresponding surface current) source at the n,n+1 interface. 
        
        Args:
            n (int): n means that a test charge is placed at the n,n+1 interface. Each layer is indexed; 
                the entrance material has n = 1. Therefore, for a material with N layers, the index goes from 1 to N+2.
            side (str): the side of the n,n+1 interface can be either "before" or "after". The H field
                on the corresponding side is then calculated.
            
        Return:
            void
        
        """
        matrixDictionary = self.transferMatrix.matrixDictionary
        
        #check for parameter inputs
        if n > (self.numLayers+1):
            Logger.raiseException('Index exceed number of layers. n cannot be greater than {0}'.format(self.numLayers+1),exception=ValueError)
        elif n < 1:
            Logger.raiseException('Invalid index. n cannot be less than 1',exception=ValueError)
        elif side!='before' and side!='after':
            Logger.raiseException('The input to side has to either be \'before\' or \'after\'', exception=ValueError)
        
        #begin assembling matrices
        M_1_to_n = sympy.Matrix([[1,0],[0,1]])
        for x in range(2, n+1):
            M_1_to_n *= matrixDictionary["T{0}{1}".format(x-1,x)].get_matrix()
            M_1_to_n *= matrixDictionary["P{0}".format(x)].get_matrix()
            
        M_1_to_n_inv = sympy.Matrix([[M_1_to_n[1,1],-M_1_to_n[0,1]],[-M_1_to_n[1,0],M_1_to_n[0,0]]])
        
        M_n_to_end = mb.TransmissionMatrix(self.transferMatrix.polarization,n,surfaceCurrent='self').get_matrix()
        for x in range(n+1, self.numLayers+2):
            M_n_to_end *= matrixDictionary["P{0}".format(x)].get_matrix()
            M_n_to_end *= matrixDictionary["T{0}{1}".format(x,x+1)].get_matrix()
        
        beta1 = M_1_to_n_inv[0,1]
        delta1 = M_1_to_n_inv[1,1]
        alpha2 = M_n_to_end[0,0]
        gamma2 = M_n_to_end[1,0]
        
        c = sympy.symbols('c')
        
        J = mb.CurrentDensityVector().get_vector()
        inhomogeneousTerm = 4*sympy.pi/c*J/2
        b1 = 1/(beta1*gamma2-alpha2*delta1)*(gamma2*inhomogeneousTerm[0]-alpha2*inhomogeneousTerm[1])
        HfieldBefore = M_1_to_n_inv*sympy.Matrix([[0],[b1]])
        
        if side=='before':
            self.analyticalHField = HfieldBefore
            
        elif side=='after':
            M_nplus1_to_end = sympy.Matrix([[1,0],[0,1]])
            for x in range(n+1,self.numLayers+2):
                M_nplus1_to_end *= matrixDictionary["P{0}".format(x)].get_matrix()
                M_nplus1_to_end *= matrixDictionary["T{0}{1}".format(x,x+1)].get_matrix()
            a_end = 1/(beta1*gamma2-alpha2*delta1)*(delta1*inhomogeneousTerm[0]-beta1*inhomogeneousTerm[1])
            self.analyticalHField = M_nplus1_to_end*sympy.Matrix([[a_end],[0]])
        
        else:
            Logger.raiseException('Invalid input for parameter side. Only accept\'before\' or \'after\'.',Exception=ValueError)
Create analytical expression of H field at either side of the n,n+1 interface; store as a class variable. 
        
        IMPORTANT: The H field calculated in this method is specified for the problem when there is no incident field at entrance or exit, 
        and there is a oscillating charge (and corresponding surface current) source at the n,n+1 interface. 
        
        Args:
            n (int): n means that a test charge is placed at the n,n+1 interface. Each layer is indexed; 
                the entrance material has n = 1. Therefore, for a material with N layers, the index goes from 1 to N+2.
            side (str): the side of the n,n+1 interface can be either "before" or "after". The H field
                on the corresponding side is then calculated.
            
        Return:
            void
        
        
Create analytical expression of H field at either side of the n,n+1 interface; store as a class variable.
IMPORTANT: The H field calculated in this method is specified for the problem when there is no incident field at entrance or exit,
and there is a oscillating charge (and corresponding surface current) source at the n,n+1 interface.
Create analytical expression of H field at either side of the n n + 1 interface ; store as a class variable . IMPORTANT : The H field calculated in this method is specified for the problem when there is no incident field at entrance or exit and there is a oscillating charge ( and corresponding surface current ) source at the n n + 1 interface .
def assemble_analytical_H_field(self, n, side):
        matrixDictionary = self.transferMatrix.matrixDictionary
        if n > (self.numLayers+1):
            Logger.raiseException('Index exceed number of layers. n cannot be greater than {0}'.format(self.numLayers+1),exception=ValueError)
        elif n < 1:
            Logger.raiseException('Invalid index. n cannot be less than 1',exception=ValueError)
        elif side!='before' and side!='after':
            Logger.raiseException('The input to side has to either be \'before\' or \'after\'', exception=ValueError)
        M_1_to_n = sympy.Matrix([[1,0],[0,1]])
        for x in range(2, n+1):
            M_1_to_n *= matrixDictionary["T{0}{1}".format(x-1,x)].get_matrix()
            M_1_to_n *= matrixDictionary["P{0}".format(x)].get_matrix()
        M_1_to_n_inv = sympy.Matrix([[M_1_to_n[1,1],-M_1_to_n[0,1]],[-M_1_to_n[1,0],M_1_to_n[0,0]]])
        M_n_to_end = mb.TransmissionMatrix(self.transferMatrix.polarization,n,surfaceCurrent='self').get_matrix()
        for x in range(n+1, self.numLayers+2):
            M_n_to_end *= matrixDictionary["P{0}".format(x)].get_matrix()
            M_n_to_end *= matrixDictionary["T{0}{1}".format(x,x+1)].get_matrix()
        beta1 = M_1_to_n_inv[0,1]
        delta1 = M_1_to_n_inv[1,1]
        alpha2 = M_n_to_end[0,0]
        gamma2 = M_n_to_end[1,0]
        c = sympy.symbols('c')
        J = mb.CurrentDensityVector().get_vector()
        inhomogeneousTerm = 4*sympy.pi/c*J/2
        b1 = 1/(beta1*gamma2-alpha2*delta1)*(gamma2*inhomogeneousTerm[0]-alpha2*inhomogeneousTerm[1])
        HfieldBefore = M_1_to_n_inv*sympy.Matrix([[0],[b1]])
        if side=='before':
            self.analyticalHField = HfieldBefore
        elif side=='after':
            M_nplus1_to_end = sympy.Matrix([[1,0],[0,1]])
            for x in range(n+1,self.numLayers+2):
                M_nplus1_to_end *= matrixDictionary["P{0}".format(x)].get_matrix()
                M_nplus1_to_end *= matrixDictionary["T{0}{1}".format(x,x+1)].get_matrix()
            a_end = 1/(beta1*gamma2-alpha2*delta1)*(delta1*inhomogeneousTerm[0]-beta1*inhomogeneousTerm[1])
            self.analyticalHField = M_nplus1_to_end*sympy.Matrix([[a_end],[0]])
        else:
            Logger.raiseException('Invalid input for parameter side. Only accept\'before\' or \'after\'.',Exception=ValueError)
def assemble_analytical_H_field ( self , n , side ) : matrixDictionary = self . transferMatrix . matrixDictionary if n > ( self . numLayers + 1 ) : Logger . raiseException ( 'Index exceed number of layers. n cannot be greater than {0}' . format ( self . numLayers + 1 ) , exception = ValueError ) elif n < 1 : Logger . raiseException ( 'Invalid index. n cannot be less than 1' , exception = ValueError ) elif side != 'before' and side != 'after' : Logger . raiseException ( 'The input to side has to either be \'before\' or \'after\'' , exception = ValueError ) M_1_to_n = sympy . Matrix ( [ [ 1 , 0 ] , [ 0 , 1 ] ] ) for x in range ( 2 , n + 1 ) : M_1_to_n *= matrixDictionary [ "T{0}{1}" . format ( x - 1 , x ) ] . get_matrix ( ) M_1_to_n *= matrixDictionary [ "P{0}" . format ( x ) ] . get_matrix ( ) M_1_to_n_inv = sympy . Matrix ( [ [ M_1_to_n [ 1 , 1 ] , - M_1_to_n [ 0 , 1 ] ] , [ - M_1_to_n [ 1 , 0 ] , M_1_to_n [ 0 , 0 ] ] ] ) M_n_to_end = mb . TransmissionMatrix ( self . transferMatrix . polarization , n , surfaceCurrent = 'self' ) . get_matrix ( ) for x in range ( n + 1 , self . numLayers + 2 ) : M_n_to_end *= matrixDictionary [ "P{0}" . format ( x ) ] . get_matrix ( ) M_n_to_end *= matrixDictionary [ "T{0}{1}" . format ( x , x + 1 ) ] . get_matrix ( ) beta1 = M_1_to_n_inv [ 0 , 1 ] delta1 = M_1_to_n_inv [ 1 , 1 ] alpha2 = M_n_to_end [ 0 , 0 ] gamma2 = M_n_to_end [ 1 , 0 ] c = sympy . symbols ( 'c' ) J = mb . CurrentDensityVector ( ) . get_vector ( ) inhomogeneousTerm = 4 * sympy . pi / c * J / 2 b1 = 1 / ( beta1 * gamma2 - alpha2 * delta1 ) * ( gamma2 * inhomogeneousTerm [ 0 ] - alpha2 * inhomogeneousTerm [ 1 ] ) HfieldBefore = M_1_to_n_inv * sympy . Matrix ( [ [ 0 ] , [ b1 ] ] ) if side == 'before' : self . analyticalHField = HfieldBefore elif side == 'after' : M_nplus1_to_end = sympy . Matrix ( [ [ 1 , 0 ] , [ 0 , 1 ] ] ) for x in range ( n + 1 , self . numLayers + 2 ) : M_nplus1_to_end *= matrixDictionary [ "P{0}" . format ( x ) ] . get_matrix ( ) M_nplus1_to_end *= matrixDictionary [ "T{0}{1}" . format ( x , x + 1 ) ] . get_matrix ( ) a_end = 1 / ( beta1 * gamma2 - alpha2 * delta1 ) * ( delta1 * inhomogeneousTerm [ 0 ] - beta1 * inhomogeneousTerm [ 1 ] ) self . analyticalHField = M_nplus1_to_end * sympy . Matrix ( [ [ a_end ] , [ 0 ] ] ) else : Logger . raiseException ( 'Invalid input for parameter side. Only accept\'before\' or \'after\'.' , Exception = ValueError )
Create analytical expression of H field at either side of the n,n+1 interface; store as a class variable.
Create analytical expression of H field at either side of the n n + 1 interface ; store as a class variable .
"""Create analytical expression of H field at either side of the n,n+1 interface; store as a class variable. 
        
        IMPORTANT: The H field calculated in this method is specified for the problem when there is no incident field at entrance or exit, 
        and there is a oscillating charge (and corresponding surface current) source at the n,n+1 interface. 
        
        Args:
            n (int): n means that a test charge is placed at the n,n+1 interface. Each layer is indexed; 
                the entrance material has n = 1. Therefore, for a material with N layers, the index goes from 1 to N+2.
            side (str): the side of the n,n+1 interface can be either "before" or "after". The H field
                on the corresponding side is then calculated.
            
        Return:
            void
        
        """ #check for parameter inputs #begin assembling matrices
self
n
n means that a test charge is placed at the n,n+1 interface. Each layer is indexed;
the entrance material has n = 1. Therefore, for a material with N layers, the index goes from 1 to N+2.
n means that a test charge is placed at the n n + 1 interface . Each layer is indexed ; the entrance material has n = 1 . Therefore for a material with N layers the index goes from 1 to N + 2 .
side
the side of the n,n+1 interface can be either "before" or "after". The H field
on the corresponding side is then calculated.
the side of the n n + 1 interface can be either " before " or " after " . The H field on the corresponding side is then calculated .