-
Notifications
You must be signed in to change notification settings - Fork 58
Add VolumeMesher and VOLUME_MESH task type #2493
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
base: develop
Are you sure you want to change the base?
Conversation
ac85aa7
to
6b1c544
Compare
0e36855
to
1b29844
Compare
1282a66
to
d5e1b87
Compare
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/components/base_sim/data/sim_data.py
tidy3d/components/data/unstructured/base.py
tidy3d/components/data/unstructured/tetrahedral.py
tidy3d/components/data/unstructured/triangular.py
tidy3d/components/tcad/data/monitor_data/mesh.py
tidy3d/components/tcad/data/sim_data.py
tidy3d/components/tcad/mesher.py
tidy3d/web/api/tidy3d_stub.py
tidy3d/web/core/http_util.py
|
d5e1b87
to
169c6b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Momchil for going through this.
I guess my main concern is that VolumeMesher
doesn't add much. In fact, I think we don't need that class. Instead, we could create a new analysis type along the lines of CreateMesh()
that can be passed to analysis_spec
. Or even, it VolumeMesher
could be an analysis type:
sim = td.HeatChargeSimulation(
...
analysis_spec=td.VolumeMeshser(),
)
Even the parent task id and everything else could be used in the same way you were intended, right?
simulation: HeatChargeSimulation = pd.Field( | ||
title="Volume mesher", | ||
description="Original :class:`VolumeMesher` associated with the data.", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might as well go to the base class?
class VolumeMeshMonitor(HeatChargeMonitor): | ||
"""Monitor for the volume mesh.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess in the docstring we could add a couple of examples of monitors so that we make it clear that even if it is a "volume mesh monitor" the monitor itself can be planar?
we could probably close #2569 since it's included in here. As for missing tests from there, I think we can just get a 2d vtk and a 3d vtk from actual backend runs and add frontend unit tests that loads them (successfully with ignore_invalid_cells=True, and failing with ignore_invalid_cells=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
14 files reviewed, 8 comments
Edit PR Review Bot Settings | Greptile
"""Gets the name of the fields to be plot.""" | ||
return "Mesh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: parameter 'val' is unused in field_name implementation
"""Gets the name of the fields to be plot.""" | |
return "Mesh" | |
def field_name(self, _: str) -> str: |
cell_offsets = vtk["vtk_to_numpy"](vtk_obj.GetCells().GetOffsetsArray()) | ||
valid_cell_offsets = cell_offsets[:-1][invalid_cells == 0] | ||
cells_numpy = cells_numpy[ | ||
np.ravel(valid_cell_offsets[:, None] + np.arange(4, dtype=int)[None, :]) | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The hardcoded 4 in np.arange(4) assumes tetrahedral cells. Consider using cls._cell_num_vertices() instead for consistency with rest of the code
cell_offsets = vtk["vtk_to_numpy"](vtk_obj.GetCells().GetOffsetsArray()) | |
valid_cell_offsets = cell_offsets[:-1][invalid_cells == 0] | |
cells_numpy = cells_numpy[ | |
np.ravel(valid_cell_offsets[:, None] + np.arange(4, dtype=int)[None, :]) | |
] | |
cell_offsets = vtk["vtk_to_numpy"](vtk_obj.GetCells().GetOffsetsArray()) | |
valid_cell_offsets = cell_offsets[:-1][invalid_cells == 0] | |
cells_numpy = cells_numpy[ | |
np.ravel(valid_cell_offsets[:, None] + np.arange(cls._cell_num_vertices(), dtype=int)[None, :]) | |
] |
invalid_cells = np.diff(cell_offsets) != cls._cell_num_vertices() | ||
if any(invalid_cells): | ||
if ignore_invalid_cells: | ||
valid_cell_offsets = cell_offsets[:-1][invalid_cells == 0] | ||
cells_numpy = cells_numpy[ | ||
np.ravel(valid_cell_offsets[:, None] + np.arange(3, dtype=int)[None, :]) | ||
] | ||
else: | ||
raise DataError( | ||
"Only triangular 'vtkUnstructuredGrid' or 'vtkPolyData' can be converted into " | ||
"'TriangularGridDataset'." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Be explicit about vectorization in the broadcasting. Change:
invalid_cells = np.diff(cell_offsets) != cls._cell_num_vertices() | |
if any(invalid_cells): | |
if ignore_invalid_cells: | |
valid_cell_offsets = cell_offsets[:-1][invalid_cells == 0] | |
cells_numpy = cells_numpy[ | |
np.ravel(valid_cell_offsets[:, None] + np.arange(3, dtype=int)[None, :]) | |
] | |
else: | |
raise DataError( | |
"Only triangular 'vtkUnstructuredGrid' or 'vtkPolyData' can be converted into " | |
"'TriangularGridDataset'." | |
) | |
invalid_cells = np.diff(cell_offsets) != cls._cell_num_vertices() | |
if np.any(invalid_cells): |
class VolumeMeshMonitor(HeatChargeMonitor): | ||
"""Monitor for the volume mesh.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Class docstring should detail the purpose, typical usage scenario, and relationship to HeatChargeMonitor
. Consider adding an example.
@@ -218,7 +226,7 @@ def plot_field( | |||
# field.name = field_name | |||
field_data = self._field_component_value(field, val) | |||
|
|||
if isinstance(monitor_data, TemperatureData): | |||
if isinstance(monitor_data, (TemperatureData, VolumeMeshData)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: if block now includes VolumeMeshData but comment at line 175 only mentions TemperatureMonitorData
if isinstance(monitor_data, (TemperatureData, VolumeMeshData)): | |
field_monitor_name : str | |
Name of :class:`.TemperatureMonitorData` or :class:`.VolumeMeshData` to plot. |
simulation: HeatChargeSimulation = pd.Field( | ||
title="Volume mesher", | ||
description="Original :class:`VolumeMesher` associated with the data.", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: incorrect docstring - references VolumeMesher but field shows HeatChargeSimulation
simulation: HeatChargeSimulation = pd.Field( | |
title="Volume mesher", | |
description="Original :class:`VolumeMesher` associated with the data.", | |
) | |
simulation: HeatChargeSimulation = pd.Field( | |
title="Heat-Charge Simulation", | |
description="Original :class:`HeatChargeSimulation` associated with the data.", | |
) |
@requires_vtk | ||
def from_vtk( | ||
cls, | ||
file: str, | ||
field: Optional[str] = None, | ||
remove_degenerate_cells: bool = False, | ||
remove_unused_points: bool = False, | ||
ignore_invalid_cells: bool = False, | ||
) -> UnstructuredGridDataset: | ||
"""Load unstructured data from a vtk file. | ||
|
||
Parameters | ||
---------- | ||
fname : str | ||
Full path to the .vtk file to load the unstructured data from. | ||
field : str = None | ||
Name of the field to load. | ||
remove_degenerate_cells : bool = False | ||
Remove explicitly degenerate cells. | ||
remove_unused_points : bool = False | ||
Remove unused points. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Parameter ignore_invalid_cells
is documented but description is missing
@requires_vtk | |
def from_vtk( | |
cls, | |
file: str, | |
field: Optional[str] = None, | |
remove_degenerate_cells: bool = False, | |
remove_unused_points: bool = False, | |
ignore_invalid_cells: bool = False, | |
) -> UnstructuredGridDataset: | |
"""Load unstructured data from a vtk file. | |
Parameters | |
---------- | |
fname : str | |
Full path to the .vtk file to load the unstructured data from. | |
field : str = None | |
Name of the field to load. | |
remove_degenerate_cells : bool = False | |
Remove explicitly degenerate cells. | |
remove_unused_points : bool = False | |
Remove unused points. | |
ignore_invalid_cells : bool = False | |
Whether to ignore invalid cells during loading. |
elif "VolumeMesher" == type_: | ||
sim = VolumeMesher.from_file(file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Inconsistent string comparison style. Other type checks use type_ == 'String', but here it's flipped.
elif "VolumeMesher" == type_: | |
sim = VolumeMesher.from_file(file_path) | |
elif type_ == "VolumeMesher": | |
sim = VolumeMesher.from_file(file_path) |
Currently this depends on #2569 and has been rebased on it.
Introduces the
VolumeMesher
,VolumeMeshMonitor
, and associated data types to be able to compute and inspect aHeatChargeSimulation
mesh before running the solver. From the user perspective the workflow is:Greptile Summary
Introduces VolumeMesher functionality to compute and inspect HeatChargeSimulation meshes before running the solver, enabling better mesh quality verification and debugging.
VolumeMesher
class with associatedVolumeMeshMonitor
and data types to preview simulation meshesTetrahedralGridDataset
andTriangularGridDataset
withignore_invalid_cells
parameter for improved mesh handlingVOLUME_MESH
task type in web API with appropriate integrationsAbstractHeatChargeSimulationData
base class to unify HeatChargeSimulation and VolumeMesher results.vtk
) files alongside existing.vtu
support