From 0e268f255a6d070d7f7306c19f6006ab84621393 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 31 Jul 2024 07:44:32 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Doc=20raises=20for=20mesh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bluemira/mesh/meshing.py | 22 ++++++++++++++++++++++ bluemira/mesh/tools.py | 14 ++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/bluemira/mesh/meshing.py b/bluemira/mesh/meshing.py index b36010e769..2ffed21ea4 100644 --- a/bluemira/mesh/meshing.py +++ b/bluemira/mesh/meshing.py @@ -197,6 +197,13 @@ def __init__( def _check_meshfile(meshfile: str | list) -> list[str]: """ Check the mesh file input. + + Raises + ------ + ValueError + Meshfile list is empty + TypeError + Meshfile must be a string or list of strings """ # todo: should be implemented also a check on the file extension. Only a # limited type of file extensions is allowed by gmsh. @@ -223,6 +230,11 @@ def meshfile(self, meshfile: str | list[str]): def __call__(self, obj: Component | Meshable, dim: int = 2): """ Generate the mesh and save it to file. + + Raises + ------ + TypeError + Objects not meshable """ bluemira_print("Starting mesh process...") @@ -269,6 +281,11 @@ def __call__(self, obj: Component | Meshable, dim: int = 2): def __mesh_obj(self, obj, dim: int): """ Function to mesh the object. + + Raises + ------ + ValueError + Meshing not implemented for geometry type """ from bluemira.geometry.tools import serialise_shape # noqa: PLC0415 @@ -520,6 +537,11 @@ def get_gmsh_dict( """ Returns the gmsh dict in a default (only tags) or gmsh (tuple(dim, tag)) format. + + Raises + ------ + ValueError + No object to mesh """ if isinstance(file_format, str): file_format = GmshFileType[file_format.upper()] diff --git a/bluemira/mesh/tools.py b/bluemira/mesh/tools.py index 8d11fb8635..beedac86eb 100644 --- a/bluemira/mesh/tools.py +++ b/bluemira/mesh/tools.py @@ -63,7 +63,7 @@ def msh_to_xdmf( Raises ------ - MeshConversionError: + MeshConversionError * If the file does not exist * If the dimensionality != [2, 3] * If no domain physical groups are found @@ -113,6 +113,11 @@ def import_mesh( Dolfin MeshFunctionSizet object containing the geometry link_dict: Link dictionary between MSH and XDMF objects + + Raises + ------ + FileNotFoundError + no mesh file(s) found """ domain_file = Path(directory, f"{file_prefix}_{DOMAIN_SUFFIX}") boundary_file = Path(directory, f"{file_prefix}_{BOUNDARY_SUFFIX}") @@ -124,7 +129,7 @@ def import_mesh( msg = "\n".join([ fn.as_posix() for fn, exist in zip(files, exists, strict=False) if not exist ]) - raise MeshConversionError(f"No mesh file(s) found:\n {msg}") + raise FileNotFoundError(f"No mesh file(s) found:\n {msg}") mesh = Mesh() @@ -175,6 +180,11 @@ def _check_dimensions(dimensions: int | list[int]) -> tuple[int]: def _export_domain(mesh, file_prefix, directory, dimensions): """ Export the domain of a mesh to XDMF. + + Raises + ------ + MeshConversionError + No domain physical group found """ dimensions = _check_dimensions(dimensions)