@@ -791,8 +791,14 @@ class XmfEntry:
791791 mo_thick_sol : Optional [float ]
792792 yin_yang : bool
793793 twod : Optional [str ]
794- coord_h5 : list [Path ]
795- coord_shape : list [tuple [int , ...]]
794+ coord_filepattern : str
795+ coord_shape : tuple [int , ...]
796+ ncores : int
797+
798+ def coord_files_yin (self , path_root : Path ) -> Iterator [Path ]:
799+ ncores = self .ncores // (2 if self .yin_yang else 1 )
800+ for icore in range (ncores ):
801+ yield path_root / self .coord_filepattern .format (icore = icore + 1 )
796802
797803
798804@dataclass (frozen = True )
@@ -829,34 +835,42 @@ def _data(self) -> Mapping[int, XmfEntry]:
829835 mo_thick_sol = self ._maybe_get (snap , "mo_thick_sol" , "Value" , float )
830836
831837 yin_yang = False
832- coord_h5 = [] # all the coordinate files
833- coord_shape = [] # shape of meshes
834838 twod = None
839+
840+ elt_subdomain = _try_find (self .path , snap , "Grid" )
841+ elt_geom = _try_find (self .path , elt_subdomain , "Geometry" )
842+ if elt_geom .get ("Type" ) == "X_Y" :
843+ twod = ""
844+ for data_item in elt_geom .findall ("DataItem" ):
845+ coord = _try_text (self .path , data_item ).strip ()[- 1 ]
846+ if coord in "XYZ" :
847+ twod += coord
848+ data_item = _try_find (self .path , elt_geom , "DataItem" )
849+ data_text = _try_text (self .path , data_item )
850+ coord_shape = _get_dim (self .path , data_item )
851+ coord_filepattern = data_text .strip ().split (":/" , 1 )[0 ]
852+ coord_file_chunks = coord_filepattern .split ("_" )
853+ coord_file_chunks [- 2 ] = "{icore:05d}"
854+ coord_filepattern = "_" .join (coord_file_chunks )
855+
856+ ncores = 0
835857 for elt_subdomain in snap .findall ("Grid" ):
836858 elt_name = _try_get (self .path , elt_subdomain , "Name" )
837859 if elt_name .startswith ("meshYang" ):
838860 yin_yang = True
839- break # iterate only through meshYin
840- elt_geom = _try_find (self .path , elt_subdomain , "Geometry" )
841- if elt_geom .get ("Type" ) == "X_Y" and twod is None :
842- twod = ""
843- for data_item in elt_geom .findall ("DataItem" ):
844- coord = _try_text (self .path , data_item ).strip ()[- 1 ]
845- if coord in "XYZ" :
846- twod += coord
847- data_item = _try_find (self .path , elt_geom , "DataItem" )
848- data_text = _try_text (self .path , data_item )
849- coord_shape .append (_get_dim (self .path , data_item ))
850- coord_h5 .append (self .path .parent / data_text .strip ().split (":/" , 1 )[0 ])
861+ ncores *= 2
862+ break
863+ ncores += 1
851864
852865 data [isnap ] = XmfEntry (
853866 time = time ,
854867 mo_lambda = mo_lambda ,
855868 mo_thick_sol = mo_thick_sol ,
856869 yin_yang = yin_yang ,
857- coord_h5 = coord_h5 ,
858- coord_shape = coord_shape ,
859870 twod = twod ,
871+ coord_filepattern = coord_filepattern ,
872+ coord_shape = coord_shape ,
873+ ncores = ncores ,
860874 )
861875 return data
862876
@@ -893,12 +907,12 @@ def read_geom_h5(xdmf: FieldXmf, snapshot: int) -> dict[str, Any]:
893907 header ["ntb" ] = 2 if entry .yin_yang else 1
894908
895909 all_meshes : list [dict [str , NDArray ]] = []
896- for h5file , shape in zip ( entry .coord_h5 , entry . coord_shape ):
910+ for h5file in entry .coord_files_yin ( xdmf . path . parent ):
897911 all_meshes .append ({})
898912 with h5py .File (h5file , "r" ) as h5f :
899913 for coord , mesh in h5f .items ():
900914 # for some reason, the array is transposed!
901- all_meshes [- 1 ][coord ] = mesh [()].reshape (shape ).T
915+ all_meshes [- 1 ][coord ] = mesh [()].reshape (entry . coord_shape ).T
902916 all_meshes [- 1 ][coord ] = _make_3d (all_meshes [- 1 ][coord ], entry .twod )
903917
904918 header ["ncs" ] = _ncores (all_meshes , entry .twod )
0 commit comments