Start Here#

Run this notebook in your browser using Binder.

This is a basic Tidy3D script showing the FDTD simulation of a delectric cube in the presence of a point dipole.

[1]:
import numpy as np

# import the package and the web API
import tidy3d as td
import tidy3d.web as web
[2]:
# set up parameters of simulation (length scales are micrometers)
grid_cells_per_wvl = 30
pml = td.PML()
sim_size = (4, 4, 4)
lambda0 = 1.0
freq0 = td.C_0 / lambda0
fwidth = freq0 / 10.0
run_time = 12.0 / fwidth

# create structure
dielectric = td.Medium.from_nk(n=2, k=0, freq=freq0)
square = td.Structure(
    geometry=td.Box(center=(0, 0, 0), size=(1.5, 1.5, 1.5)),
    medium=dielectric)

# create source
source = td.UniformCurrentSource(
    center=(-1.5, 0, 0),
    size=(0, 0.4, 0.4),
    source_time = td.GaussianPulse(
        freq0=freq0,
        fwidth=fwidth),
    polarization='Ey')

# create monitor
monitor = td.FieldMonitor(
    fields=['Ex', 'Ey', 'Hz'],
    center=(0, 0, 0),
    size=(td.inf, td.inf, 0),
    freqs=[freq0],
    name='fields_on_plane')

# Initialize simulation
sim = td.Simulation(size=sim_size,
    grid_spec = td.GridSpec.auto(min_steps_per_wvl=grid_cells_per_wvl),
    structures=[square],
    sources=[source],
    monitors=[monitor],
    run_time=run_time,
    boundary_spec=td.BoundarySpec.all_sides(boundary=td.PML())
)
[3]:
print(f'simulation grid is shaped {sim.grid.num_cells} for {int(np.prod(sim.grid.num_cells)/1e6)} million cells.')
[16:34:15] INFO     Auto meshing using wavelength 1.0000 defined from        grid_spec.py:472
                    sources.                                                                 
simulation grid is shaped [192, 192, 192] for 7 million cells.
[4]:
# run the simulation, download the data.
data = web.run(sim, task_name='quickstart', path='data/data.hdf5')
           INFO     Using Tidy3D credentials from stored file                      auth.py:74
[16:34:17] INFO     Uploaded task 'quickstart' with task_id                     webapi.py:120
                    '873f64e9-3ccc-431f-8c9d-da84a2abf053'.                                  
[16:34:20] INFO     status = queued                                             webapi.py:253
[16:34:23] INFO     Maximum flex unit cost: 0.20                                webapi.py:244
[16:34:27] INFO     status = preprocess                                         webapi.py:265
[16:34:35] INFO     starting up solver                                          webapi.py:269
[16:34:47] INFO     running solver                                              webapi.py:275
[16:34:53] INFO     early shutoff detected, exiting.                            webapi.py:286
           INFO     status = postprocess                                        webapi.py:292
[16:34:56] INFO     status = success                                            webapi.py:298
[16:34:57] INFO     downloading file "output/monitor_data.hdf5" to              webapi.py:574
                    "data/data.hdf5"                                                         
[16:34:59] INFO     loading SimulationData from data/data.hdf5                  webapi.py:398
           INFO     Auto meshing using wavelength 1.0000 defined from        grid_spec.py:472
                    sources.                                                                 
[5]:
# see the log
print(data.log)
Simulation domain Nx, Ny, Nz: [192, 192, 192]
Applied symmetries: (0, 0, 0)
Number of computational grid points: 7.3014e+06.
Using subpixel averaging: True
Number of time steps: 1.3924e+04
Automatic shutoff factor: 1.00e-05
Time step (s): 2.8750e-17


Compute source modes time (s):     0.0085
Compute monitor modes time (s):    0.0174
Rest of setup time (s):            3.4423

Running solver for 13924 time steps...
- Time step    556 / time 1.60e-14s (  4 % done), field decay: 1.00e+00
- Time step    923 / time 2.65e-14s (  6 % done), field decay: 1.00e+00
- Time step   1113 / time 3.20e-14s (  8 % done), field decay: 9.57e-01
- Time step   1670 / time 4.80e-14s ( 12 % done), field decay: 1.71e-01
- Time step   2227 / time 6.40e-14s ( 16 % done), field decay: 4.05e-02
- Time step   2784 / time 8.00e-14s ( 20 % done), field decay: 1.84e-02
- Time step   3341 / time 9.61e-14s ( 24 % done), field decay: 8.94e-03
- Time step   3898 / time 1.12e-13s ( 28 % done), field decay: 4.25e-03
- Time step   4455 / time 1.28e-13s ( 32 % done), field decay: 3.17e-03
- Time step   5012 / time 1.44e-13s ( 36 % done), field decay: 2.33e-03
- Time step   5569 / time 1.60e-13s ( 40 % done), field decay: 1.80e-03
- Time step   6126 / time 1.76e-13s ( 44 % done), field decay: 1.09e-03
- Time step   6683 / time 1.92e-13s ( 48 % done), field decay: 7.57e-04
- Time step   7240 / time 2.08e-13s ( 52 % done), field decay: 3.30e-04
- Time step   7797 / time 2.24e-13s ( 56 % done), field decay: 2.27e-04
- Time step   8354 / time 2.40e-13s ( 60 % done), field decay: 8.50e-05
- Time step   8911 / time 2.56e-13s ( 64 % done), field decay: 1.18e-04
- Time step   9468 / time 2.72e-13s ( 68 % done), field decay: 6.03e-05
- Time step  10025 / time 2.88e-13s ( 72 % done), field decay: 9.70e-05
- Time step  10582 / time 3.04e-13s ( 76 % done), field decay: 4.02e-05
- Time step  11139 / time 3.20e-13s ( 80 % done), field decay: 5.61e-05
- Time step  11696 / time 3.36e-13s ( 84 % done), field decay: 2.18e-05
- Time step  12253 / time 3.52e-13s ( 88 % done), field decay: 3.46e-05
- Time step  12810 / time 3.68e-13s ( 92 % done), field decay: 8.46e-06
Field decay smaller than shutoff factor, exiting solver.

Solver time (s):                   6.1692
Post-processing time (s):          0.1168


[6]:
# plot the fields stored in the monitor
ax = data.plot_field('fields_on_plane', 'Ey', freq=freq0, z=0)
_ = ax.set_title('Ey(x,y)')
           INFO     Auto meshing using wavelength 1.0000 defined from        grid_spec.py:472
                    sources.                                                                 
<Figure size 432x288 with 2 Axes>
../_images/notebooks_StartHere_6_2.png
[ ]: