tidy3d.SimulationData#

class SimulationData[source]#

Bases: AbstractYeeGridSimulationData

Stores data from a collection of Monitor objects in a Simulation.

Parameters:

Notes

The SimulationData objects store a copy of the original Simulation:, so it can be recovered if the SimulationData is loaded in a new session and the Simulation is no longer in memory.

More importantly, the SimulationData contains a reference to the data for each of the monitors within the original Simulation. This data can be accessed directly using the name given to the monitors initially.

Examples

Standalone example:

>>> import tidy3d as td
>>> num_modes = 5
>>> x = [-1,1,3]
>>> y = [-2,0,2,4]
>>> z = [-3,-1,1,3,5]
>>> f = [2e14, 3e14]
>>> coords = dict(x=x[:-1], y=y[:-1], z=z[:-1], f=f)
>>> grid = td.Grid(boundaries=td.Coords(x=x, y=y, z=z))
>>> scalar_field = td.ScalarFieldDataArray((1+1j) * np.random.random((2,3,4,2)), coords=coords)
>>> field_monitor = td.FieldMonitor(
...     size=(2,4,6),
...     freqs=[2e14, 3e14],
...     name='field',
...     fields=['Ex'],
...     colocate=True,
... )
>>> sim = td.Simulation(
...     size=(2, 4, 6),
...     grid_spec=td.GridSpec(wavelength=1.0),
...     monitors=[field_monitor],
...     run_time=2e-12,
...     sources=[
...         td.UniformCurrentSource(
...             size=(0, 0, 0),
...             center=(0, 0.5, 0),
...             polarization="Hx",
...             source_time=td.GaussianPulse(
...                 freq0=2e14,
...                 fwidth=4e13,
...             ),
...         )
...     ],
... )
>>> field_data = td.FieldData(monitor=field_monitor, Ex=scalar_field, grid_expanded=grid)
>>> sim_data = td.SimulationData(simulation=sim, data=(field_data,))

To save and load the SimulationData object.

sim_data.to_file(fname='path/to/file.hdf5') # Save a SimulationData object to a HDF5 file
sim_data = SimulationData.from_file(fname='path/to/file.hdf5') # Load a SimulationData object from a HDF5 file.

Attributes

final_decay_value

Returns value of the field decay at the final time step.

fwidth_adj

data

log

Custom logger to avoid the complexities of the logging module

attrs

Methods

correct_adjoint_sources(src, fwidth, ...)

Corret a set of spectrally overlapping adjoint sources to give correct E_adj.

get_adjoint_data(structure_index, data_type)

Grab the field or permittivity data for a given structure index.

make_adjoint_sim(data_vjp_paths, ...)

Make the adjoint simulation from the original simulation and the VJP-containing data.

make_adjoint_sources(data_vjp_paths)

Generate all of the non-zero sources for the adjoint simulation given the VJP data.

process_adjoint_sources(adj_srcs)

Compute list of final sources along with a post run normalization for adj fields.

process_adjoint_sources_broadband(adj_srcs)

Process adjoint sources for the case of several sources at the same freq.

process_adjoint_sources_fit(adj_srcs, ...)

Process the adjoint sources using a least squared fit to the derivative data.

renormalize(normalize_index)

Return a copy of the SimulationData with a different source used for the normalization.

source_spectrum(source_index)

Get a spectrum normalization function for a given source index.

split_adjoint_data(num_mnts_original)

Split data list into original, adjoint field, and adjoint permittivity.

split_original_fwd(num_mnts_original)

Split this simulation data into original and fwd data from number of original mnts.

to_mat_file(fname, **kwargs)

Output the SimulationData object as .mat MATLAB file.

Inherited Common Usage

tidy3d.components.base.Tidy3dBaseModel.from_file(fname)

Loads a Tidy3dBaseModel from .yaml, .json, .hdf5, or .hdf5.gz file.

simulation#
data#
diverged#
property final_decay_value#

Returns value of the field decay at the final time step.

source_spectrum(source_index)[source]#

Get a spectrum normalization function for a given source index.

renormalize(normalize_index)[source]#

Return a copy of the SimulationData with a different source used for the normalization.

split_adjoint_data(num_mnts_original)[source]#

Split data list into original, adjoint field, and adjoint permittivity.

split_original_fwd(num_mnts_original)[source]#

Split this simulation data into original and fwd data from number of original mnts.

make_adjoint_sim(data_vjp_paths, adjoint_monitors)[source]#

Make the adjoint simulation from the original simulation and the VJP-containing data.

make_adjoint_sources(data_vjp_paths)[source]#

Generate all of the non-zero sources for the adjoint simulation given the VJP data.

property fwidth_adj#
process_adjoint_sources(adj_srcs)[source]#

Compute list of final sources along with a post run normalization for adj fields.

process_adjoint_sources_broadband(adj_srcs)[source]#

Process adjoint sources for the case of several sources at the same freq.

process_adjoint_sources_fit(adj_srcs, hashes_to_src_times, hashes_to_sources)[source]#

Process the adjoint sources using a least squared fit to the derivative data.

correct_adjoint_sources(src, fwidth, source_times)[source]#

Corret a set of spectrally overlapping adjoint sources to give correct E_adj.

get_adjoint_data(structure_index, data_type)[source]#

Grab the field or permittivity data for a given structure index.

to_mat_file(fname, **kwargs)[source]#

Output the SimulationData object as .mat MATLAB file.

Parameters:
  • fname (str) – Full path to the output file. Should include .mat file extension.

  • **kwargs (dict, optional) – Extra arguments to scipy.io.savemat: see scipy documentation for more detail.

Example

>>> simData.to_mat_file('/path/to/file/data.mat') 
__hash__()#

Hash method.