Skip to content

Commit

Permalink
Updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagovla committed Mar 30, 2021
1 parent 4ba6328 commit 77d4126
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 106 deletions.
48 changes: 48 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
API Reference
==============


Geometry Module
---------------------------

.. autoclass:: morpho.geometry.Geometry
:members:
:show-inheritance:

BrillouinZone Module
---------------------------

.. autoclass:: morpho.brillouinzone.SymmetryPoint
:members:
:show-inheritance:

.. autoclass:: morpho.brillouinzone.BrillouinZonePath
:members:
:show-inheritance:

Solver Module
---------------------------
.. autoclass:: morpho.solver.Solver
:members: run
:show-inheritance:

.. autoclass:: morpho.solver.Solver2D
:members: run
:show-inheritance:


Utils Module
---------------------------
.. autofunction:: morpho.utils.convmat


Exceptions Module
------------------------

.. automodule:: morpho.exceptions
:members:
:undoc-members:
:show-inheritance:
==============


14 changes: 5 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
contain the root `toctree` directive.
Welcome to morpho.py's documentation!
==================================
======================================

.. toctree::
:maxdepth: 2
:caption: Contents:

quickstart
introduction
api
references


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
3 changes: 3 additions & 0 deletions docs/introduction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Introduction
==============

66 changes: 66 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
QuickStart
==============


Installation
---------------------------
The package can be installed by:

.. code-block:: bash
pip install morpho.py
Examples
---------------------------

.. code-block:: python
"""2D example."""
import matplotlib.pyplot as plt
import numpy as np
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver2D
from morpho import SymmetryPoint as SPoint
Nx, Ny = 64, 64
P, Q = 5, 5
a = 1
eps_r = 9.8
mu_r = 1.0
# Define the symmetry points
G = SPoint((0, 0), "Γ")
X = SPoint((1 / 2, 0), "X")
M = SPoint((1 / 2, 1 / 2), "M")
t1, t2, t3 = (a, 0, 0), (0, a, 0), (0, 0, a)
# Construct the bloch wave path
bz_path = BZPath([G, X, M, G], t1, t2, n_points=100)
# Construct the geometry
geo = Geometry(t1, t2, None, Nx, Ny, 1)
# Define the permitivity profile
@geo.set_epsr_f
def epsr_f():
"""Define eps_r profile function."""
mask = geo.x**2 + geo.y**2 <= 0.2**2
geo.eps_r[mask] = eps_r
# Define the permeability profile
@geo.set_mur_f
def mur_f():
"""Define mu_r profile function."""
# Solve
solver_tm = Solver2D(geometry=geo, path=bz_path, P=P, Q=Q, pol="TM")
solver_tm.run()
solver_te = Solver2D(geometry=geo, path=bz_path, P=P, Q=Q, pol="TE")
solver_te.run()
4 changes: 4 additions & 0 deletions docs/references.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
References
==============

[1] J. D. Joannopoulos, Ed., Photonic crystals: molding the flow of light, 2nd ed. Princeton: Princeton University Press, 2008.
30 changes: 17 additions & 13 deletions examples/example_2d.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
"""3D example."""
"""2D example."""
import matplotlib.pyplot as plt
import numpy as np
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver2D
from morpho import SymmetryPoint as SPoint

Nx, Ny = 64, 64
P, Q = 5, 5
a = 1
eps_r = 9.8
mu_r = 1.0
# Input parameters
N1, N2 = 64, 64 # discretization
P, Q = 7, 7 # number of fourier terms
a = 1 # normalized lattice length
r = 0.2 * a # cylinder radius
eps_r = 9.8 # permittivity
mu_r = 1.0 # permeability

# Define the symmetry points
G = SPoint((0, 0), "Γ")
X = SPoint((1 / 2, 0), "X")
M = SPoint((1 / 2, 1 / 2), "M")

t1, t2, t3 = (a, 0, 0), (0, a, 0), (0, 0, a)
# Lattice vectors
t1, t2 = (a, 0), (0, a)

# Construct the bloch wave path
bz_path = BZPath([G, X, M, G], t1, t2, n_points=100)

# Construct the geometry
geo = Geometry(t1, t2, None, Nx, Ny, 1)
geo = Geometry(t1=t1, t2=t2, N1=N1, N2=N2)


# Define the permitivity profile
@geo.set_epsr_f
@geo.set_eps_rf
def epsr_f():
"""Define eps_r profile function."""
mask = geo.x**2 + geo.y**2 <= 0.2**2
geo.eps_r[mask] = eps_r


# Define the permeability profile
@geo.set_mur_f
@geo.set_mu_rf
def mur_f():
"""Define mu_r profile function."""

Expand All @@ -50,13 +53,14 @@ def mur_f():
beta_len = bz_path.beta_vec_len
wn_tm = np.vstack(solver_tm.wn)
wn_te = np.vstack(solver_te.wn)
fig, ax = plt.subplots()

fig, ax = plt.subplots(figsize=(5, 4))
ax.set_xticklabels(bz_path.symmetry_names)
ax.set_xticks(bz_path.symmetry_locations)
ax.set_xlim(0, bz_path.symmetry_locations[-1])
ax.set_ylim(0, 1)
ax.set_ylim(0, 0.8)
ax.set_xlabel(r"Bloch Wave Vector $\beta$")
ax.set_ylabel(r"Frequency $\frac{\omega a}{2\pi c}$")
ax.set_ylabel(r"Frequency ${\omega a}/{2\pi c}$")
ax.plot(beta_len, wn_tm * a / (2 * np.pi), "b-", label="TM")
ax.plot(beta_len, wn_te * a / (2 * np.pi), "r-", label="TE")
handles, labels = ax.get_legend_handles_labels()
Expand Down
8 changes: 4 additions & 4 deletions examples/example_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from morpho import Geometry, Solver
from morpho import SymmetryPoint as SPoint

Nx, Ny, Nz = 128, 128, 128
N1, N2, N3 = 128, 128, 128
P, Q, R = 3, 3, 3

a = 1
Expand All @@ -24,11 +24,11 @@
bz_path = BZPath([D, Z, G, Z, T, X], t1, t2, t3, 200)

# Construct the geometry
geo = Geometry(t1, t2, t3, Nx, Ny, Nz)
geo = Geometry(t1, t2, t3, N1, N2, N3)


# Define the permitivity profile
@geo.set_epsr_f
@geo.set_eps_rf
def epsr_f():
"""Define eps_r profile function."""
mask1 = (abs(geo.x) >= a/2 - w/2) & (abs(geo.y) >= a/2 - w/2)
Expand All @@ -38,7 +38,7 @@ def epsr_f():


# Define the permeability profile
@geo.set_mur_f
@geo.set_mu_rf
def mur_f():
"""Define mu_r profile function."""

Expand Down
40 changes: 31 additions & 9 deletions morpho/brillouinzone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@


class SymmetryPoint:
"""Model of a symmetry point at the brillouinzone."""
"""Model of a symmetry point at the brillouinzone.
Parameters
----------
point : Tuple[float, ...]
A point in the reciprocal domain.
name : str
A label to describe the point.
"""

def __init__(self, point: Tuple[float, ...], name: str):
"""Initialize a SymmetryPoint."""
Expand All @@ -16,15 +24,29 @@ def __init__(self, point: Tuple[float, ...], name: str):


class BrillouinZonePath:
"""Model of a path at the brillouinzone."""
"""Model of a path at the brillouinzone.
Parameters
----------
path : List[SymmetryPoint]
A List of symmetry points.
t1 : Tuple[float, ...]
Direct vector t1. Ex: (0.5, 0.5, 0.5) | (0.5, 0.5) | (0.5,)
t2 : Optional[Tuple[float, ...]]
Direct vector t2. Ex: (0.5, 0.5, 0.5) | (0.5, 0.5)
t3 : Optional[Tuple[float, ...]]
Direct vector t3. Ex: (0.5, 0.5, 0.5)
n_points : int
Number of points in the path.
"""

def __init__(
self,
path: List[SymmetryPoint],
t1: Tuple[float, ...],
t2: Optional[Tuple[float, ...]] = None,
t3: Optional[Tuple[float, ...]] = None,
n_points: int = 5,
n_points: int = 50,
):
"""Initialize a BrillouinZonePath."""
self.path_points = path
Expand Down Expand Up @@ -53,32 +75,32 @@ def __init__(

@property
def t1(self):
"""Return vector t1."""
"""Return the direct vector t1."""
return self._t1[:self.dim]

@property
def t2(self):
"""Return vector t2."""
"""Return the direct vector t2."""
return self._t2[:self.dim]

@property
def t3(self):
"""Return vector t3."""
"""Return the direct vector t3."""
return self._t3[:self.dim]

@property
def T1(self):
"""Return vector T1."""
"""Return the reciprocal vector T1."""
return self._T1[:self.dim]

@property
def T2(self):
"""Return vector T2."""
"""Return the reciprocal vector T2."""
return self._T2[:self.dim]

@property
def T3(self):
"""Return vector T3."""
"""Return the reciprocal vector T3."""
return self._T3[:self.dim]

def _calculate_beta(self):
Expand Down
Loading

0 comments on commit 77d4126

Please sign in to comment.