Skip to content

Commit

Permalink
Using Coordinate instead of Point
Browse files Browse the repository at this point in the history
  • Loading branch information
weiliangjin2021 committed May 28, 2024
1 parent f5a2e3e commit c10eb6c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
3 changes: 1 addition & 2 deletions tidy3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# geometry
from .components.geometry.base import Box, Transformed, ClipOperation, GeometryGroup
from .components.geometry.primitives import Sphere, Cylinder, Point
from .components.geometry.primitives import Sphere, Cylinder
from .components.geometry.mesh import TriangleMesh
from .components.geometry.polyslab import PolySlab

Expand Down Expand Up @@ -179,7 +179,6 @@ def set_logging_level(level: str) -> None:
"AutoGrid",
"Box",
"Sphere",
"Point",
"Cylinder",
"PolySlab",
"GeometryGroup",
Expand Down
15 changes: 1 addition & 14 deletions tidy3d/components/geometry/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import shapely

from ..base import cached_property, skip_if_fields_missing
from ..types import Axis, Bound, Coordinate, MatrixReal4x4, Shapely, Tuple, Literal
from ..types import Axis, Bound, Coordinate, MatrixReal4x4, Shapely, Tuple
from ...exceptions import SetupError, ValidationError
from ...constants import MICROMETER, LARGE_NUMBER
from ...packaging import verify_packages_import
Expand Down Expand Up @@ -166,19 +166,6 @@ def _surface_area(self, bounds: Bound) -> float:
return area


class Point(Sphere):
"""A point: a sphere of radius = 0.
Example
-------
>>> b = Point(center=(1,2,3))
"""

radius: Literal[0] = pydantic.Field(
0, title="Radius", description="Radius of geometry.", units=MICROMETER
)


class Cylinder(base.Centered, base.Circular, base.Planar):
"""Cylindrical geometry with optional sidewall angle along axis
direction. When ``sidewall_angle`` is nonzero, the shape is a
Expand Down
17 changes: 8 additions & 9 deletions tidy3d/components/grid/grid_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from .grid import Coords1D, Coords, Grid
from .mesher import GradedMesher, MesherType
from ..base import Tidy3dBaseModel, cached_property
from ..types import Axis, Symmetry, annotate_type, TYPE_TAG_STR
from ..types import Axis, Symmetry, annotate_type, TYPE_TAG_STR, Coordinate
from ..source import SourceType
from ..structure import Structure, StructureType
from ..geometry.base import Box
from ..geometry.primitives import Point
from ...log import log
from ...exceptions import SetupError
from ...constants import MICROMETER, C_0, fp_eps
Expand Down Expand Up @@ -87,7 +86,7 @@ def make_coords(
periodic: bool,
wavelength: pd.PositiveFloat,
num_pml_layers: Tuple[pd.NonNegativeInt, pd.NonNegativeInt],
fixpoints: List[Point],
fixpoints: List[Coordinate],
) -> Coords1D:
"""Generate 1D coords to be used as grid boundaries, based on simulation parameters.
Symmetry, and PML layers will be treated here.
Expand All @@ -105,7 +104,7 @@ def make_coords(
Free-space wavelength.
num_pml_layers : Tuple[int, int]
number of layers in the absorber + and - direction along one dimension.
fixpoints : List[Point]
fixpoints : List[Coordinate]
A set of points that enforce grid boundaries to pass through them.
Returns
Expand Down Expand Up @@ -428,7 +427,7 @@ def _make_coords_initial(
wavelength: float,
symmetry: Symmetry,
is_periodic: bool,
fixpoints: List[Point],
fixpoints: List[Coordinate],
) -> Coords1D:
"""Customized 1D coords to be used as grid boundaries.
Expand All @@ -445,7 +444,7 @@ def _make_coords_initial(
normal to each of the three axes.
is_periodic : bool
Apply periodic boundary condition or not.
fixpoints : List[Point]
fixpoints : List[Coordinate]
A set of points that enforce grid boundaries to pass through them.
Returns
Expand Down Expand Up @@ -585,7 +584,7 @@ class GridSpec(Tidy3dBaseModel):
"uses :class:`.AutoGrid`.",
)

fixpoints: Tuple[Point, ...] = pd.Field(
fixpoints: Tuple[Coordinate, ...] = pd.Field(
(),
title="Grid specification fixpoints",
description="A set of points that enforce grid boundaries to pass through them. "
Expand Down Expand Up @@ -723,7 +722,7 @@ def auto(
min_steps_per_wvl: pd.PositiveFloat = 10.0,
max_scale: pd.PositiveFloat = 1.4,
override_structures: List[StructureType] = (),
fixpoints: List[Point] = (),
fixpoints: List[Coordinate] = (),
dl_min: pd.NonNegativeFloat = 0.0,
mesher: MesherType = GradedMesher(),
) -> GridSpec:
Expand All @@ -743,7 +742,7 @@ def auto(
A list of structures that is added on top of the simulation structures in
the process of generating the grid. This can be used to refine the grid or make it
coarser depending than the expected need for higher/lower resolution regions.
fixpoints : List[Point]
fixpoints : List[Coordinate]
A set of points that enforce grid boundaries to pass through them.
dl_min: pd.NonNegativeFloat
Lower bound of grid size.
Expand Down
11 changes: 5 additions & 6 deletions tidy3d/components/grid/mesher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
from shapely.errors import ShapelyDeprecationWarning

from ..base import Tidy3dBaseModel
from ..types import Axis, ArrayFloat1D
from ..types import Axis, ArrayFloat1D, Coordinate
from ..structure import Structure, MeshOverrideStructure, StructureType
from ..medium import AnisotropicMedium, Medium2D, PECMedium
from ..geometry.primitives import Point
from ...exceptions import SetupError, ValidationError
from ...constants import C_0, fp_eps
from ...log import log
Expand Down Expand Up @@ -50,7 +49,7 @@ def insert_fixpoints(
axis: Axis,
interval_coords: ArrayFloat1D,
max_dl_list: ArrayFloat1D,
fixpoints: List[Point],
fixpoints: List[Coordinate],
) -> Tuple[ArrayFloat1D, ArrayFloat1D]:
"""Insert fixpoints to the intervals."""

Expand All @@ -74,7 +73,7 @@ def insert_fixpoints(
axis: Axis,
interval_coords: ArrayFloat1D,
max_dl_list: ArrayFloat1D,
fixpoints: List[Point],
fixpoints: List[Coordinate],
) -> Tuple[ArrayFloat1D, ArrayFloat1D]:
"""Insert fixpoints to the intervals.
Expand All @@ -86,7 +85,7 @@ def insert_fixpoints(
Coordinate of interval boundaries.
max_dl_list : ArrayFloat1D
Maximal allowed step size of each interval generated from `parse_structures`.
fixpoints : List[Point]
fixpoints : List[Coordinate]
A set of points that enforce grid boundaries to pass through them.
Returns
Expand All @@ -109,7 +108,7 @@ def insert_fixpoints(

min_step = np.amin(max_dl_list) * 0.5
for point in fixpoints:
new_coord = point.center[axis]
new_coord = point[axis]
# Skip if the point is outside the domain
if new_coord >= interval_coords[-1] or new_coord <= interval_coords[0]:
continue
Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def plot_grid(

# Plot fixpoints
for point in self.grid_spec.fixpoints:
_, (x_point, y_point) = point.pop_axis(point.center, axis=axis)
_, (x_point, y_point) = Geometry.pop_axis(point, axis=axis)
x_point, y_point = (self._evaluate_inf(v) for v in (x_point, y_point))
ax.scatter(x_point, y_point, color=plot_params.edgecolor)

Expand Down

0 comments on commit c10eb6c

Please sign in to comment.