1616"""
1717
1818import codecs
19+ from enum import Enum
1920import gzip
2021import os
2122from os .path import dirname
@@ -215,6 +216,14 @@ def __getattr__(self, name: str):
215216 return CaseVariable (self ._variables , name + "/" )
216217
217218
219+ class MeshType (Enum ):
220+ """Types of Mesh."""
221+
222+ SURFACE = "surface"
223+ VOLUME = "volume"
224+ UNKNOWN = "unknown"
225+
226+
218227class Mesh :
219228 """Class to provide mesh data.
220229
@@ -236,6 +245,16 @@ def __init__(self, file_handle):
236245 """Initialize the object."""
237246 self ._file_handle = file_handle
238247
248+ def get_mesh_type (self ) -> MeshType :
249+ """Returns the type of the mesh."""
250+ try :
251+ if "cells" in self ._file_handle ["meshes" ]["1" ].keys ():
252+ return MeshType .VOLUME
253+ else :
254+ return MeshType .SURFACE
255+ except Exception :
256+ return MeshType .UNKNOWN
257+
239258 def get_surface_ids (self ) -> list :
240259 """Returns list of ids of all available surfaces."""
241260 id_data = self ._file_handle ["meshes" ]["1" ]["faces" ]["zoneTopology" ]["id" ]
@@ -528,6 +547,16 @@ def __init__(self, settings_file_name: Optional[str] = None) -> None:
528547 super ().__init__ (rp_vars_str )
529548
530549
550+ class EmptyContainer :
551+ """Empty Container."""
552+
553+ def __getattr__ (self , item ):
554+ return lambda * args , ** kwargs : None
555+
556+ def __call__ (self , * args , ** kwargs ):
557+ return None
558+
559+
531560class CaseFile (RPVarProcessor ):
532561 """Class to read a Fluent case file.
533562
@@ -552,6 +581,7 @@ def __init__(
552581 project_file_name : Optional[str]
553582 The path of a project file from which the case file is selected.
554583 """
584+ self ._is_case_file = False
555585
556586 if (not case_file_name ) == (not project_file_name ):
557587 raise RuntimeError (
@@ -572,23 +602,35 @@ def __init__(
572602 )
573603
574604 try :
575- if Path (case_file_name ).match ("*.cas.h5" ):
605+ if Path (case_file_name ).match ("*.cas.h5" ) or Path (case_file_name ).match (
606+ "*.msh.h5"
607+ ):
576608 _file = h5py .File (case_file_name )
577- settings = _file ["settings" ]
578- rpvars = settings ["Rampant Variables" ][0 ]
579- rp_vars_str = rpvars .decode ()
580- elif Path (case_file_name ).match ("*.cas" ):
609+ if Path (case_file_name ).match ("*.cas.h5" ):
610+ self ._is_case_file = True
611+ settings = _file ["settings" ]
612+ rpvars = settings ["Rampant Variables" ][0 ]
613+ rp_vars_str = rpvars .decode ()
614+ elif Path (case_file_name ).match ("*.cas" ) or Path (case_file_name ).match (
615+ "*.msh"
616+ ):
581617 with open (case_file_name , "rb" ) as _file :
582618 rp_vars_str = _file .read ()
583- rp_vars_str = _get_processed_string (rp_vars_str )
584- elif Path (case_file_name ).match ("*.cas.gz" ):
619+ if Path (case_file_name ).match ("*.cas" ):
620+ self ._is_case_file = True
621+ rp_vars_str = _get_processed_string (rp_vars_str )
622+ elif Path (case_file_name ).match ("*.cas.gz" ) or Path (case_file_name ).match (
623+ "*.msh.gz"
624+ ):
585625 with gzip .open (case_file_name , "rb" ) as _file :
586626 rp_vars_str = _file .read ()
587- rp_vars_str = _get_processed_string (rp_vars_str )
627+ if Path (case_file_name ).match ("*.cas.gz" ):
628+ self ._is_case_file = True
629+ rp_vars_str = _get_processed_string (rp_vars_str )
588630 else :
589631 error_message = (
590632 "Could not read case file. "
591- "Only valid Case files (.h5, .cas, .cas.gz) can be read. "
633+ "Only valid Case files (.h5, .cas, .cas.gz) or Mesh files (.msh.h5, .msh, .msh.gz) can be read. "
592634 )
593635 raise RuntimeError (error_message )
594636
@@ -603,13 +645,24 @@ def __init__(
603645 except Exception as e :
604646 raise RuntimeError (f"Could not read case file { case_file_name } " ) from e
605647
606- super ().__init__ (rp_vars_str = rp_vars_str )
648+ if self ._is_case_file :
649+ super ().__init__ (rp_vars_str = rp_vars_str )
607650 self ._mesh = Mesh (_file )
608651
609652 def get_mesh (self ):
610653 """Get the mesh data."""
611654 return self ._mesh
612655
656+ def __getattribute__ (self , item ):
657+ if (
658+ item != "_is_case_file"
659+ and not self ._is_case_file
660+ and item
661+ in set (filter (lambda k : not k .startswith ("__" ), dir (RPVarProcessor )))
662+ ):
663+ return EmptyContainer ()
664+ return super ().__getattribute__ (item )
665+
613666
614667def _get_processed_string (input_string : bytes ) -> str :
615668 """Processes the input string (binary) with help of an identifier to return it in a
0 commit comments