Big documentation and structure updates
- Split math into fdmath package - Rename waveguide into _2d _3d and _cyl variants - pdoc-based documentation
This commit is contained in:
parent
f0ef31c25d
commit
d6e7e3dee1
25 changed files with 2590 additions and 1349 deletions
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Basic FDTD functionality
|
||||
Utilities for running finite-difference time-domain (FDTD) simulations
|
||||
"""
|
||||
|
||||
from .base import maxwell_e, maxwell_h
|
||||
|
|
|
|||
|
|
@ -5,70 +5,14 @@ from typing import List, Callable, Tuple, Dict
|
|||
import numpy
|
||||
|
||||
from .. import dx_lists_t, field_t, field_updater
|
||||
from ..fdmath.functional import curl_forward, curl_back
|
||||
|
||||
|
||||
__author__ = 'Jan Petykiewicz'
|
||||
|
||||
|
||||
def curl_h(dxes: dx_lists_t = None) -> field_updater:
|
||||
"""
|
||||
Curl operator for use with the H field.
|
||||
|
||||
:param dxes: Grid parameters [dx_e, dx_h] as described in meanas.types
|
||||
:return: Function for taking the discretized curl of the H-field, F(H) -> curlH
|
||||
"""
|
||||
if dxes:
|
||||
dxyz_b = numpy.meshgrid(*dxes[1], indexing='ij')
|
||||
|
||||
def dh(f, ax):
|
||||
return (f - numpy.roll(f, 1, axis=ax)) / dxyz_b[ax]
|
||||
else:
|
||||
def dh(f, ax):
|
||||
return f - numpy.roll(f, 1, axis=ax)
|
||||
|
||||
def ch_fun(h: field_t) -> field_t:
|
||||
output = numpy.empty_like(h)
|
||||
output[0] = dh(h[2], 1)
|
||||
output[1] = dh(h[0], 2)
|
||||
output[2] = dh(h[1], 0)
|
||||
output[0] -= dh(h[1], 2)
|
||||
output[1] -= dh(h[2], 0)
|
||||
output[2] -= dh(h[0], 1)
|
||||
return output
|
||||
|
||||
return ch_fun
|
||||
|
||||
|
||||
def curl_e(dxes: dx_lists_t = None) -> field_updater:
|
||||
"""
|
||||
Curl operator for use with the E field.
|
||||
|
||||
:param dxes: Grid parameters [dx_e, dx_h] as described in meanas.types
|
||||
:return: Function for taking the discretized curl of the E-field, F(E) -> curlE
|
||||
"""
|
||||
if dxes is not None:
|
||||
dxyz_a = numpy.meshgrid(*dxes[0], indexing='ij')
|
||||
|
||||
def de(f, ax):
|
||||
return (numpy.roll(f, -1, axis=ax) - f) / dxyz_a[ax]
|
||||
else:
|
||||
def de(f, ax):
|
||||
return numpy.roll(f, -1, axis=ax) - f
|
||||
|
||||
def ce_fun(e: field_t) -> field_t:
|
||||
output = numpy.empty_like(e)
|
||||
output[0] = de(e[2], 1)
|
||||
output[1] = de(e[0], 2)
|
||||
output[2] = de(e[1], 0)
|
||||
output[0] -= de(e[1], 2)
|
||||
output[1] -= de(e[2], 0)
|
||||
output[2] -= de(e[0], 1)
|
||||
return output
|
||||
|
||||
return ce_fun
|
||||
|
||||
|
||||
def maxwell_e(dt: float, dxes: dx_lists_t = None) -> field_updater:
|
||||
curl_h_fun = curl_h(dxes)
|
||||
curl_h_fun = curl_back(dxes[1])
|
||||
|
||||
def me_fun(e: field_t, h: field_t, epsilon: field_t):
|
||||
e += dt * curl_h_fun(h) / epsilon
|
||||
|
|
@ -78,7 +22,7 @@ def maxwell_e(dt: float, dxes: dx_lists_t = None) -> field_updater:
|
|||
|
||||
|
||||
def maxwell_h(dt: float, dxes: dx_lists_t = None) -> field_updater:
|
||||
curl_e_fun = curl_e(dxes)
|
||||
curl_e_fun = curl_forward(dxes[0])
|
||||
|
||||
def mh_fun(e: field_t, h: field_t):
|
||||
h -= dt * curl_e_fun(e)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ def poynting_divergence(s: field_t = None,
|
|||
if s is None:
|
||||
s = poynting(e, h, dxes=dxes)
|
||||
|
||||
#TODO use deriv operators
|
||||
ds = ((s[0] - numpy.roll(s[0], 1, axis=0)) +
|
||||
(s[1] - numpy.roll(s[1], 1, axis=1)) +
|
||||
(s[2] - numpy.roll(s[2], 1, axis=2)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue