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,
    pml_layers=(pml, pml, pml)
)
[3]:
print(f'simulation grid is shaped {sim.grid.num_cells} for {int(np.prod(sim.grid.num_cells)/1e6)} million cells.')
[15:16:04] INFO     Auto meshing using wavelength 1.0000 defined from        grid_spec.py:466
                    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
[15:16:07] INFO     Uploaded task 'quickstart' with task_id                     webapi.py:120
                    'd29b5a96-3852-4295-acd5-8d1f4044bd33'.                                  
[15:16:11] INFO     Maximum flex unit cost: 0.20                                webapi.py:253
           INFO     status = queued                                             webapi.py:262
[15:16:24] INFO     status = preprocess                                         webapi.py:274
[15:16:36] INFO     starting up solver                                          webapi.py:278
[15:16:56] INFO     running solver                                              webapi.py:284
[15:17:11] INFO     early shutoff detected, exiting.                            webapi.py:295
           INFO     status = postprocess                                        webapi.py:301
[15:17:22] INFO     status = success                                            webapi.py:307
[15:17:24] INFO     downloading file "monitor_data.hdf5" to "data/data.hdf5"    webapi.py:537
[15:17:25] INFO     loading SimulationData from data/data.hdf5                  webapi.py:369
[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.0779e+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.0109
Compute monitor modes time (s):    0.0173
Rest of setup time (s):            2.8832

Starting solver...
- 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.04e-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.24e-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.71e-05
- Time step  10582 / time 3.04e-13s ( 76 % done), field decay: 4.01e-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.43e-06
Field decay smaller than shutoff factor, exiting solver.

Solver time (s):                   7.7760
Post-processing time (s):          0.0402

[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)')
<Figure size 432x288 with 2 Axes>
../_images/notebooks_StartHere_6_1.png
[ ]: