Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitors working correctly to gather all the necessary data for interpolation #100

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tidy3d/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# monitor
from .monitor import AbstractFieldMonitor, FreqMonitor, TimeMonitor, FieldMonitor, FieldTimeMonitor
from .monitor import AbstractFluxMonitor, FluxMonitor, FluxTimeMonitor, ModeMonitor
from .monitor import Monitor, AbstractFluxMonitor, FluxMonitor, FluxTimeMonitor, ModeMonitor

# simulation
from .simulation import Simulation
Expand Down
5 changes: 5 additions & 0 deletions tidy3d/components/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class Coords(Tidy3dBaseModel):
y: Coords1D
z: Coords1D

@property
def to_list(self):
"""Return a list of the three Coord1D objects."""
return list(self.dict().values())


class FieldGrid(Tidy3dBaseModel):
"""Holds the grid data for a single field.
Expand Down
13 changes: 7 additions & 6 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def pml_thicknesses(self) -> List[Tuple[float, float]]:
"""
num_layers = self.num_pml_layers
pml_thicknesses = []
for num_layer, boundaries in zip(num_layers, self.grid.boundaries.dict().values()):
for num_layer, boundaries in zip(num_layers, self.grid.boundaries.to_list):
thick_l = boundaries[num_layer[0]] - boundaries[0]
thick_r = boundaries[-1] - boundaries[-1 - num_layer[1]]
pml_thicknesses.append((thick_l, thick_r))
Expand Down Expand Up @@ -768,8 +768,8 @@ def frequency_range(self) -> FreqBound:
at 5 standard deviations.
"""
source_ranges = [source.source_time.frequency_range for source in self.sources]
freq_min = min(freq_range[0] for freq_range in source_ranges)
freq_max = max(freq_range[1] for freq_range in source_ranges)
freq_min = min([freq_range[0] for freq_range in source_ranges], default=0.0)
freq_max = max([freq_range[1] for freq_range in source_ranges], default=0.0)
return (freq_min, freq_max)

""" Discretization """
Expand All @@ -783,7 +783,7 @@ def dt(self) -> float:
float
Time step (seconds).
"""
dl_mins = [np.min(sizes) for sizes in self.grid.sizes.dict().values()]
dl_mins = [np.min(sizes) for sizes in self.grid.sizes.to_list]
dl_sum_inv_sq = sum([1 / dl ** 2 for dl in dl_mins])
dl_avg = 1 / np.sqrt(dl_sum_inv_sq)
return self.courant * dl_avg / C_0
Expand Down Expand Up @@ -904,7 +904,7 @@ def discretize_inds(self, box: Box) -> List[Tuple[int, int]]:
ind_min = 0 if len(inds_leq_pt_min) == 0 else inds_leq_pt_min[-1]

# store indexes
inds_list.append((ind_min, ind_max + 1))
inds_list.append((ind_min, ind_max))

return inds_list

Expand All @@ -927,7 +927,8 @@ def discretize(self, box: Box) -> Grid:
for axis_label, axis_inds in zip("xyz", disc_inds):
# copy orginal bound coords into subgrid coords
bound_coords = self.grid.boundaries.dict()[axis_label]
sub_cell_boundary_dict[axis_label] = bound_coords[axis_inds[0] : axis_inds[1]]
# axis_inds[1] + 1 because we are selecting cell boundaries not cells
sub_cell_boundary_dict[axis_label] = bound_coords[axis_inds[0] : axis_inds[1] + 1]

# construct sub grid
sub_boundaries = Coords(**sub_cell_boundary_dict)
Expand Down
5 changes: 1 addition & 4 deletions tidy3d/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ def old_json_sources(sim: Simulation) -> List[Dict]:
src = {}

if isinstance(source, VolumeSource):
"""TODO: Is polarization the right word if we're talking about J and M?
Check Lumerical notation."""
component = "E" if source.polarization[0] == "J" else "H"
component += source.polarization[1]
component = source.polarization
if all(s == 0 for s in source.size):
src = {
"name": name,
Expand Down