From c66f92f74ba7dceb0bc6c2566fc2ffac85dfeb92 Mon Sep 17 00:00:00 2001 From: simbilod Date: Sun, 14 Sep 2025 22:32:18 -0700 Subject: [PATCH] slight syntax tweaks --- meshwell/cad.py | 17 ++++------------ meshwell/mesh.py | 49 +++++++---------------------------------------- meshwell/model.py | 2 +- 3 files changed, 12 insertions(+), 56 deletions(-) diff --git a/meshwell/cad.py b/meshwell/cad.py index 8c536203..324d9390 100644 --- a/meshwell/cad.py +++ b/meshwell/cad.py @@ -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 ( @@ -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: @@ -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) @@ -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] @@ -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 @@ -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: @@ -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: diff --git a/meshwell/mesh.py b/meshwell/mesh.py index a4b1dc25..28017e08 100644 --- a/meshwell/mesh.py +++ b/meshwell/mesh.py @@ -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. @@ -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: @@ -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() @@ -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) """ @@ -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: @@ -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( @@ -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: diff --git a/meshwell/model.py b/meshwell/model.py index 938de31c..fbb4d72f 100644 --- a/meshwell/model.py +++ b/meshwell/model.py @@ -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: