tidy3d.CustomFieldSource#

class CustomFieldSource[source]#

Bases: FieldSource, PlanarSource

Implements a source corresponding to an input dataset containing E and H fields, using the equivalence principle to define the actual injected currents.

Parameters:
  • attrs (dict = {}) – Dictionary storing arbitrary metadata for a Tidy3D object. This dictionary can be freely used by the user for storing data without affecting the operation of Tidy3D as it is not used internally. Note that, unlike regular Tidy3D fields, attrs are mutable. For example, the following is allowed for setting an attr obj.attrs['foo'] = bar. Also note that Tidy3D` will raise a TypeError if attrs contain objects that can not be serialized. One can check if attrs are serializable by calling obj.json().

  • name (Optional[str] = None) – Optional name for the source.

  • center (Union[tuple[Union[float, autograd.tracer.Box], Union[float, autograd.tracer.Box], Union[float, autograd.tracer.Box]], Box] = (0.0, 0.0, 0.0)) – [units = um]. Center of object in x, y, and z.

  • size (Union[tuple[Union[pydantic.v1.types.NonNegativeFloat, autograd.tracer.Box], Union[pydantic.v1.types.NonNegativeFloat, autograd.tracer.Box], Union[pydantic.v1.types.NonNegativeFloat, autograd.tracer.Box]], Box]) – [units = um]. Size in x, y, and z directions.

  • source_time (Union[GaussianPulse, ContinuousWave, CustomSourceTime]) – Specification of the source time-dependence.

  • field_dataset (Optional[FieldDataset]) –

    FieldDataset containing the desired frequency-domain fields patterns to inject. At least one tangential field component must be specified.

    Notes

    For the injection to work as expected (i.e. to reproduce the required E and H fields), the field data must decay by the edges of the source plane, or the source plane must span the entire simulation domain and the fields must match the simulation boundary conditions.

    The equivalent source currents are fully defined by the field components tangential to the source plane. For e.g. source normal along z, the normal components (Ez and Hz) can be provided but will have no effect on the results, and at least one of the tangential components has to be in the dataset, i.e. at least one of Ex, Ey, Hx, and Hy.

    If the data is not coming from a tidy3d simulation, the normalization is likely going to be arbitrary and the directionality of the source will likely not be perfect, even if both the E and H fields are provided. An empty normalizing run may be needed to accurately normalize results.

    To create this empty simulation it is recommended that users create a simulation with no structures but just a flux monitor (tidy3D.FluxMonitor) next to the custom source, ensuring that the flux monitor is at least one grid cell away from the source. Moreover, for accurate normalization, users must ensure that the same grid is used to run the original simulation as well as the empty simulation. The total flux calculated at the flux monitor of the empty simulation can then be used for proper normalization of results after tidy3d simulation.

    The coordinates of all provided fields are assumed to be relative to the source center. If only the E or only the H fields are provided, the source will not be directional, but will inject equal power in both directions instead.

Example

>>> from tidy3d import ScalarFieldDataArray
>>> pulse = GaussianPulse(freq0=200e12, fwidth=20e12)
>>> x = np.linspace(-1, 1, 101)
>>> y = np.linspace(-1, 1, 101)
>>> z = np.array([0])
>>> f = [2e14]
>>> coords = dict(x=x, y=y, z=z, f=f)
>>> scalar_field = ScalarFieldDataArray(np.ones((101, 101, 1, 1)), coords=coords)
>>> dataset = FieldDataset(Ex=scalar_field)
>>> custom_source = CustomFieldSource(
...     center=(1, 1, 1),
...     size=(2, 2, 0),
...     source_time=pulse,
...     field_dataset=dataset)

Creating an empty simulation with no structures with FluxMonitor for normalization but with the same grid as the original simulation.

Example

>>> sim_empty = sim.updated_copy(monitors = [Flux_monitor],
...             structures = [],
...             grid_spec= sim.grid_spec.updated_copy(override_structures = sim.structures)
...             )

Attributes

Methods

Inherited Common Usage

field_dataset#
__hash__()#

Hash method.