Skip to content

Commit

Permalink
Merged version v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagovla committed Apr 2, 2021
1 parent 77d4126 commit 7ae1d24
Show file tree
Hide file tree
Showing 13 changed files with 756 additions and 448 deletions.
10 changes: 8 additions & 2 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
version = 1

test_patterns = [
"tests/**",
"test_*.py"
]

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
[analyzers.meta]
runtime_version = "3.x.x"

182 changes: 112 additions & 70 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
|PyPI License| |PyPI PyVersions| |PyPI Version| |Build Status| |DeepSource| |Codecov| |Documentation Status|
|PyPI License| |PyPI PyVersions| |PyPI Version| |Build Status| |DeepSource| |Codecov| |Documentation Status| |DOI|

================
PWE Framework for 3D/2D/1D Photonic Crystal Analysis
Expand All @@ -10,51 +10,75 @@ Quick examples:

.. code-block:: python
"""2D example."""
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver2D
from morpho import SymmetryPoint as SPoint
"""2D example."""
import matplotlib.pyplot as plt
import numpy as np
Nx, Ny = 64, 64
P, Q = 5, 5
a = 1
eps_r = 9.8
mu_r = 1.0
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver
from morpho import SymmetryPoint as SPoint
# Define the symmetry points
G = SPoint((0, 0), "Γ")
X = SPoint((1 / 2, 0), "X")
M = SPoint((1 / 2, 1 / 2), "M")
# Input parameters
a = 1 # normalized lattice length
r = 0.2 * a # cylinder radius
N1, N2 = 64, 64 # discretization
P, Q = 7, 7 # number of fourier terms
EPS_R = 9.8 # permittivity
MU_R = 1.0 # permeability
t1, t2, t3 = (a, 0, 0), (0, a, 0), (0, 0, a)
# Define the symmetry points
G = SPoint((0.0, 0.0), "Γ")
X = SPoint((0.5, 0.0), "X")
M = SPoint((0.5, 0.5), "M")
# Construct the bloch wave path
bz_path = BZPath([G, X, M, G], t1, t2, n_points=100)
# Lattice vectors
a1, a2 = (a, 0), (0, a)
# Construct the geometry
geo = Geometry(t1, t2, None, Nx, Ny, 1)
# Construct the bloch wave path
bz_path = BZPath(a1, a2, [G, X, M, G], n_points=100)
# Construct the geometry
geo = Geometry(a1, a2, N1, N2)
# 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 permitivity profile
@geo.overwrite
def eps_rf(eps_r, x, y):
"""Define eps_r profile function."""
mask = x**2 + y**2 <= 0.2**2
eps_r[mask] = EPS_R
# Define the permeability profile
@geo.set_mur_f
def mur_f():
"""Define mu_r profile function."""
# Solve
solver_tm = Solver(geo, bz_path, P=P, Q=Q, pol="TM")
solver_te = Solver(geo, bz_path, P=P, Q=Q, pol="TE")
# Solve
solver_tm = Solver2D(geometry=geo, path=bz_path, P=P, Q=Q, pol="TM")
solver_tm.run()
solver_tm.run()
solver_te.run()
solver_te = Solver2D(geometry=geo, path=bz_path, P=P, Q=Q, pol="TE")
solver_te.run()
# Results:
beta_len = bz_path.betas.cumsum
wn_tm = np.vstack(solver_tm.wn)
wn_te = np.vstack(solver_te.wn)
_, ax = plt.subplots(figsize=(5, 4))
ax.set_xticklabels(bz_path.point_names)
ax.set_xticks(bz_path.point_locations)
ax.set_xlim(0, bz_path.point_locations[-1])
ax.set_ylim(0, 0.8)
ax.set_xlabel(r"Bloch Wave Vector $k$")
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")
ax.grid(True)
handles, labels = ax.get_legend_handles_labels()
labels, ids = np.unique(labels, return_index=True)
handles = [handles[i] for i in ids]
ax.legend(handles, labels, loc="best")
plt.tight_layout()
plt.show()
Results:
Expand All @@ -64,54 +88,69 @@ Results:

.. code-block:: python
"""3D example."""
from pwe import BrillouinZonePath as BZPath
from pwe import Geometry, Solver
from pwe import SymmetryPoint as SPoint
"""3D example."""
import matplotlib.pyplot as plt
import numpy as np
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver
from morpho import SymmetryPoint as SPoint
Nx, Ny, Nz = 128, 128, 128
P, Q, R = 3, 3, 3
N1, N2, N3 = 64, 64, 64
P, Q, R = 3, 3, 3
a = 1
w = 0.2 * a
eps_r = 2.34
mu_r = 1.0
a = 1
w = 0.2 * a
EPS_R = 2.34
MU_R = 1.0
# Define the symmetry points
G = SPoint((0, 0, 0), "Γ")
Z = SPoint((0, 0, 1 / 2), "Z")
X = SPoint((1 / 2, 0, 0), "X")
D = SPoint((1 / 2, 1 / 2, 1 / 2), "D")
T = SPoint((1 / 2, 0, 1 / 2), "T")
# Define the symmetry points
G = SPoint((0, 0, 0), "Γ")
Z = SPoint((0, 0, 1 / 2), "Z")
X = SPoint((1 / 2, 0, 0), "X")
D = SPoint((1 / 2, 1 / 2, 1 / 2), "D")
T = SPoint((1 / 2, 0, 1 / 2), "T")
t1, t2, t3 = (a, 0, 0), (0, a, 0), (0, 0, a)
a1, a2, a3 = (a, 0, 0), (0, a, 0), (0, 0, a)
# Construct the bloch wave path
bz_path = BZPath([D, Z, G, Z, T, X], t1, t2, t3, 200)
# Construct the bloch wave path
bz_path = BZPath(a1, a2, a3, [D, Z, G, Z, T, X], 200)
# Construct the geometry
geo = Geometry(t1, t2, t3, Nx, Ny, Nz)
# Construct the geometry
geo = Geometry(a1, a2, a3, N1, N2, N3)
# Define the permitivity profile
@geo.set_epsr_f
def epsr_f():
"""Define eps_r profile function."""
mask1 = (abs(geo.x) >= a/2 - w/2) & (abs(geo.y) >= a/2 - w/2)
mask2 = (abs(geo.x) >= a/2 - w/2) & (abs(geo.z) >= a/2 - w/2)
mask3 = (abs(geo.y) >= a/2 - w/2) & (abs(geo.z) >= a/2 - w/2)
geo.eps_r[mask1 | mask2 | mask3] = eps_r
# Define the permitivity profile
@geo.overwrite
def eps_rf(eps_r, x, y, z):
"""Define eps_r profile function."""
mask1 = (abs(x) >= a/2 - w/2) & (abs(y) >= a/2 - w/2)
mask2 = (abs(x) >= a/2 - w/2) & (abs(z) >= a/2 - w/2)
mask3 = (abs(y) >= a/2 - w/2) & (abs(z) >= a/2 - w/2)
eps_r[mask1 | mask2 | mask3] = EPS_R
# Define the permeability profile
@geo.set_mur_f
def mur_f():
"""Define mu_r profile function."""
# Solve
solver = Solver(geo, bz_path, P=P, Q=Q, R=R)
solver.run()
# Results:
beta_len = bz_path.betas.cumsum
wn = np.vstack(solver.wn)
# Solve
solver = Solver(geometry=geo, path=bz_path, P=P, Q=Q, R=R)
solver.run()
_, ax = plt.subplots(figsize=(5, 4))
ax.set_xticklabels(bz_path.point_names)
ax.set_xticks(bz_path.point_locations)
ax.set_xlim(0, bz_path.point_locations[-1])
ax.set_ylim(0, 1.6)
ax.set_xlabel(r"Bloch Wave Vector $k$")
ax.set_ylabel(r"Frequency ${\omega a}/{2\pi c}$")
ax.plot(beta_len, wn * a / (2 * np.pi), "k-")
ax.grid(True)
plt.tight_layout()
plt.show()
Results:
**********
Expand Down Expand Up @@ -144,3 +183,6 @@ References:

.. |Documentation Status| image:: https://readthedocs.org/projects/morpho-py/badge/?version=latest
:target: https://morpho-py.readthedocs.io/en/latest/?badge=latest

.. |DOI| image:: https://zenodo.org/badge/341691173.svg
:target: https://zenodo.org/badge/latestdoi/341691173
43 changes: 37 additions & 6 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ API Reference
Geometry Module
---------------------------

.. autoclass:: morpho.geometry.Geometry
.. autofunction:: morpho.geometry.Geometry


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

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

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

Expand All @@ -16,17 +27,30 @@ BrillouinZone Module
:members:
:show-inheritance:

.. autoclass:: morpho.brillouinzone.BrillouinZonePath
.. autofunction:: morpho.brillouinzone.BrillouinZonePath

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

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

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

Solver Module
---------------------------
.. autoclass:: morpho.solver.Solver
.. autofunction:: morpho.solver.Solver


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

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

Expand All @@ -35,6 +59,15 @@ Utils Module
---------------------------
.. autofunction:: morpho.utils.convmat

Base Classes
---------------------------
.. autoclass:: morpho.geometry.GeometryBase
:members:
:show-inheritance:

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

Exceptions Module
------------------------
Expand All @@ -43,6 +76,4 @@ Exceptions Module
:members:
:undoc-members:
:show-inheritance:
==============


Loading

0 comments on commit 7ae1d24

Please sign in to comment.