diff --git a/pandamesh/__init__.py b/pandamesh/__init__.py index 8869fb2..26b65a3 100644 --- a/pandamesh/__init__.py +++ b/pandamesh/__init__.py @@ -3,6 +3,7 @@ from pandamesh import data from pandamesh.gmsh_mesher import ( FieldCombination, + GeneralVerbosity, GmshMesher, MeshAlgorithm, SubdivisionAlgorithm, @@ -21,6 +22,7 @@ __all__ = ( "data", "FieldCombination", + "GeneralVerbosity", "GmshMesher", "MeshAlgorithm", "SubdivisionAlgorithm", diff --git a/pandamesh/common.py b/pandamesh/common.py index b148495..1e2ecb9 100644 --- a/pandamesh/common.py +++ b/pandamesh/common.py @@ -1,6 +1,6 @@ import functools import operator -from enum import Enum +from enum import Enum, IntEnum from itertools import combinations from typing import Any, Sequence, Tuple @@ -56,7 +56,7 @@ def _show_options(options: Enum) -> str: return "\n".join(map(str, options)) -def invalid_option(value: Any, options: Enum) -> str: +def invalid_option(value: Any, options: Enum | IntEnum) -> str: return f"Invalid option: {value}. Valid options are:\n{_show_options(options)}" diff --git a/pandamesh/gmsh_mesher.py b/pandamesh/gmsh_mesher.py index 033445d..5233a4e 100644 --- a/pandamesh/gmsh_mesher.py +++ b/pandamesh/gmsh_mesher.py @@ -101,6 +101,18 @@ class FieldCombination(Enum): MEAN = "Mean" +class GeneralVerbosity(IntEnum): + """Level of information printed.""" + + SILENT = 0 + ERRORS = 1 + WARNINGS = 2 + DIRECT = 3 + INFORMATION = 4 + STATUS = 5 + DEBUG = 99 + + def coerce_field(field: Union[dict, str]) -> dict: if not isinstance(field, (dict, str)): raise TypeError("field must be a dictionary or a valid JSON dictionary string") @@ -169,6 +181,8 @@ def __init__(self, gdf: gpd.GeoDataFrame) -> None: self.mesh_size_from_curvature = False self.field_combination = FieldCombination.MIN self.subdivision_algorithm = SubdivisionAlgorithm.NONE + self.force_geometry = False + self.general_verbosity = GeneralVerbosity.SILENT def __repr__(self): return repr(self) @@ -233,18 +247,14 @@ def recombine_all(self, value: bool) -> None: gmsh.option.setNumber("Mesh.RecombineAll", value) @property - def force_geometry(self) -> None: - raise NotImplementedError - # return self._force_geometry + def force_geometry(self) -> bool: + return self._force_geometry @force_geometry.setter def force_geometry(self, value: bool) -> None: - # Wait for the next release incorporating this change: - # https://gitlab.onelab.info/gmsh/gmsh/-/merge_requests/358 - raise NotImplementedError - # if not isinstance(value, bool): - # raise TypeError("force_geometry must be a bool") - # self._force_geometry = value + if not isinstance(value, bool): + raise TypeError("force_geometry must be a bool") + self._force_geometry = value @property def mesh_size_extend_from_boundary(self): @@ -336,6 +346,17 @@ def subdivision_algorithm(self, value): self._subdivision_algorithm = value gmsh.option.setNumber("Mesh.SubdivisionAlgorithm", value) + @property + def general_verbosity(self) -> GeneralVerbosity: + return self._general_verbosity + + @general_verbosity.setter + def general_verbosity(self, value: GeneralVerbosity) -> None: + if value not in GeneralVerbosity: + raise ValueError(invalid_option(value, GeneralVerbosity)) + self._general_verbosity = value + gmsh.option.setNumber("General.Verbosity", value) + # Methods # ------- diff --git a/pixi.toml b/pixi.toml index 91f5562..a1a5e19 100644 --- a/pixi.toml +++ b/pixi.toml @@ -1,7 +1,7 @@ [project] name = "pandamesh" version = "0.1.3" -description = "Add a short description here" +description = "From geodataframe to mesh" authors = ["Huite Bootsma "] channels = ["conda-forge"] platforms = ["win-64", "linux-64", "osx-arm64", "osx-64"]