Skip to content

tiagovla/fdtd.py

Repository files navigation

PyPI license PyPI pyversions PyPI version shields.io Build Status DeepSource codecov Documentation Status DOI

FDTD Framework for Electromagnetic Simulations

Installation:

pip install fdtd.py

Example:

"""Voltage source + resistor example."""

from fdtd import Brick, Grid, Material, Resistor, SineWaveform
from fdtd import VoltageSource as VSource
from fdtd import VoltageDetector as VDetector

print("Loading materials...")
Material.load("materials.json")

print("Creating grid...")
grid = Grid(shape=(10, 10, 10), spacing=1e-3, courant_factor=0.9)

print("Creating objects...")
brick1 = Brick(*(4e-3, 2e-3, 8e-3), *(6e-3, 8e-3, 8e-3), "PEC")
brick2 = Brick(*(4e-3, 2e-3, 4e-3), *(6e-3, 8e-3, 4e-3), "PEC")
v_source = VSource(*(4e-3, 2e-3, 4e-3),
                   *(6e-3, 2e-3, 8e-3),
                   waveform=SineWaveform(frequency=1e9),
                   resistance=50)
resistor = Resistor(*(4e-3, 8e-3, 4e-3), *(6e-3, 8e-3, 8e-3), 50)
v_detector = VDetector(*(4e-3, 5e-3, 4e-3),
                             *(6e-3, 5e-3, 8e-3),
                             plot=True)

print("Adding components to grid...")
components = [brick1, brick2, v_source, resistor, v_detector]
for comp in components:
    grid.add(comp)

print("Running simulation...")
grid.run(n_steps=5000)
grid.plot_3d()

References

[1] A. Z. Elsherbeni and V. Demir, The finite-difference time-domain: method for electromagnetics with MATLAB simulations, 2nd Edition. Edison, NJ: SciTech Publishing, an imprint of the IET, 2016.