Skip to content
Open
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
17 changes: 4 additions & 13 deletions meshwell/cad.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from os import cpu_count
from typing import Dict, List, Tuple, Optional
from typing import List, Tuple, Optional
from pathlib import Path

from meshwell.validation import (
Expand Down Expand Up @@ -45,9 +45,6 @@ def __init__(
# Store parameters for backward compatibility
self.point_tolerance = point_tolerance

# Shared point cache for geometry entities that support point deduplication
self._shared_point_cache: Dict[Tuple[float, float, float], int] = {}

def _instantiate_entity(
self, index: int, entity_obj, progress_bars: bool
) -> LabeledEntities:
Expand All @@ -56,10 +53,6 @@ def _instantiate_entity(
if progress_bars and physical_name:
print(f"Processing {physical_name} - instantiation")

# Set up shared point cache for geometry entities that support it
if hasattr(entity_obj, "_set_point_cache"):
entity_obj._set_point_cache(self._shared_point_cache)

# Instantiate entity
dimtags_out = entity_obj.instanciate(self)
dimtags = unpack_dimtags(dimtags_out)
Expand All @@ -77,7 +70,7 @@ def _process_entities(
entities_list: List,
progress_bars: bool,
) -> Tuple[List, int]:
"""Process structura entities."""
"""Process structural entities."""
# Separate and order entities
structural_entities = [e for e in entities_list if not e.additive]

Expand Down Expand Up @@ -229,8 +222,6 @@ def _process_dimension_group_cuts(

self.model_manager.model.occ.removeAllDuplicates()
self.model_manager.sync_model()
# Clear shared point cache after boolean operations
self._shared_point_cache.clear()

return processed_entities

Expand Down Expand Up @@ -312,7 +303,7 @@ def process_entities(

return final_entity_list

def to_xao(self, output_file: Path) -> None:
def save_xao(self, output_file: Path) -> None:
"""Save current model state to .xao file.

Args:
Expand Down Expand Up @@ -361,7 +352,7 @@ def cad(
)

# Save to file
cad_processor.to_xao(output_file)
cad_processor.save_xao(output_file)

# Finalize if we created the model
if model is None:
Expand Down
49 changes: 7 additions & 42 deletions meshwell/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,6 @@ def _apply_mesh_refinement(
else:
self._apply_background_refinement()

def get_top_physical_names(self) -> list[str]:
"""Get all physical names of dimension dim from the GMSH model.

Returns:
List of physical names as strings
"""
return self.model_manager.get_top_physical_names()

def get_all_physical_names(self) -> list[str]:
"""Get all physical names from the GMSH model.

Returns:
List of physical names as strings
"""
return self.model_manager.get_physical_names()

def get_physical_dimtags(self, physical_name: str) -> list[tuple[int, int]]:
"""Get the dimtags associated with a physical group name.

Args:
physical_name: Name of the physical group

Returns:
List of (dim, tag) tuples for entities in the physical group
"""
return self.model_manager.get_physical_dimtags(physical_name)

def _recover_labels_from_cad(self, resolution_specs: Dict) -> Tuple[List, Dict]:
"""Recover labeled entities from loaded CAD model.

Expand All @@ -161,8 +134,8 @@ def _recover_labels_from_cad(self, resolution_specs: Dict) -> Tuple[List, Dict]:
final_entity_dict = {}

# We address entities by "named" physicals (not default):
top_physical_names = self.get_top_physical_names()
all_physical_names = self.get_all_physical_names()
top_physical_names = self.model_manager.get_top_physical_names()
all_physical_names = self.model_manager.get_physical_names()

for index, physical_name in enumerate(all_physical_names):
if physical_name in resolution_specs:
Expand All @@ -176,7 +149,7 @@ def _recover_labels_from_cad(self, resolution_specs: Dict) -> Tuple[List, Dict]:
index=index,
physical_name=physical_name,
model=self.model_manager.model,
dimtags=self.get_physical_dimtags(physical_name=physical_name),
dimtags=self.model_manager.get_physical_dimtags(physical_name),
resolutions=resolutions,
)
entities.update_boundaries()
Expand Down Expand Up @@ -264,17 +237,9 @@ def process_mesh(
gmsh.write(temp_mesh_path)
return meshio.read(temp_mesh_path)

def save_to_file(self, output_file: Path) -> None:
def save_mesh(self, output_file: Path, format: str = "msh") -> None:
"""Save current mesh to file.

Args:
output_file: Output mesh file path
"""
self.model_manager.save_to_mesh(output_file)

def to_msh(self, output_file: Path, format: str = "msh") -> None:
"""Save current mesh to .msh file.

Args:
output_file: Output file path (will be suffixed with .format)
"""
Expand All @@ -292,7 +257,7 @@ def to_meshio(self) -> meshio.Mesh:
gmsh.write(temp_mesh_path)
return meshio.read(temp_mesh_path)

def load_xao_file(self, input_file: Path) -> None:
def load_xao(self, input_file: Path) -> None:
"""Load CAD geometry from .xao file.

Args:
Expand Down Expand Up @@ -415,7 +380,7 @@ def mesh(
resolution_specs = {}

# Load geometry from file
mesh_generator.load_xao_file(input_file)
mesh_generator.load_xao(input_file)

# Process geometry into mesh
mesh_obj = mesh_generator.process_geometry(
Expand All @@ -434,7 +399,7 @@ def mesh(
)

# Save to file
mesh_generator.save_to_file(output_file)
mesh_generator.model_manager.save_to_mesh(output_file)

# Finalize if we created the model
if model is None:
Expand Down
2 changes: 1 addition & 1 deletion meshwell/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def mesh(self):

Example:
model = ModelManager(filename="my_project")
model.mesh.load_xao_file("input.xao")
model.mesh.load_xao("input.xao")
mesh_obj = model.mesh.process_geometry(dim=3, default_characteristic_length=0.1)
"""
if self._mesh is None:
Expand Down
Loading