Skip to content
Snippets Groups Projects
Commit fb673e49 authored by Bernabeu Lou's avatar Bernabeu Lou
Browse files

Added basic classes of PLate and BeamSplitter

parent a20ead4e
No related branches found
No related tags found
No related merge requests found
File moved
File moved
import numpy as np
import cmath
class Source:
def __init__(self, initial_vector=np.array([0., 0.+0j])):
self.photon = initial_vector
self.next = None
class Screen:
def __init__(self, previous=(None, None)):
self.previous = previous
class Element:
def __init__(self, previous): ## previous is either a single (previous_object, output) tuple, or a 2-dictionary of tuples
self.previous = previous ## (as in {"left": (Object 1, "label of chosen output of object 1"), "right": (obj2, "label2")})
self.next = None
class Plate(Element):
def __init__(self, jones_matrix = np.eye((2, 2), dtype='complex')):
self.jones_matrix = jones_matrix
self.output_vector = None
def out(self, side):
previous_element = self.previous[0]
previous_element_output_side = self.previous[1]
self.output_vector = self.jones_matrix @ previous_element(previous_element_output_side) # matrix-vector product : jones matrix times state vector given by the out(side) method of the previous component
return self.output_vector
class BeamSplitter(Element):
"""matrix is a 4x4 complex ndarray, two first dimensions regard left input, two next are right. So it's blockwise defined."""
def __init__(self, matrix = np.eye((4, 4), dtype='complex')):
self.matrix = matrix
self.output_vector = None
def out(self, side):
if self.previous["left"] is None:
left_input_state = np.zeros((2,), dtype="complex") # if no input on the left, then |\psi> = 0
else:
left_input_element = self.previous["left"][0]
left_input_element_output_side = self.previous["left"][1]
left_input_state = left_input_element.out(left_input_element_output_side)
if self.previous["right"] is None:
left_input_state = np.zeros((2,), dtype="complex") # if no input on the right, then |\psi> = 0
else:
right_input_element = self.previous["right"][0]
right_input_element_output_side = self.previous["right"][1]
right_input_state = right_input_element.out(right_input_element_output_side)
input_state = np.concatenate((left_input_state, right_input_state))
self.output_vector = self.matrix @ input_state
if side == "left":
ans, _ = np.split(self.output_vector)
elif side == "right":
_, ans = np.split(self.output_vector)
return ans
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment