@@ -784,8 +784,18 @@ def _get_field(xdmf_file: Path, data_item: Element) -> Tuple[int, ndarray]:
784784 return icore , fld
785785
786786
787+ @dataclass (frozen = True )
788+ class FieldSub :
789+ file : Path
790+ dataset : str
791+ icore : int
792+ iblock : int
793+ shape : tuple [int , ...]
794+
795+
787796@dataclass (frozen = True )
788797class XmfEntry :
798+ isnap : int
789799 time : Optional [float ]
790800 mo_lambda : Optional [float ]
791801 mo_thick_sol : Optional [float ]
@@ -796,11 +806,39 @@ class XmfEntry:
796806 ncores : int
797807 fields : Mapping [str , tuple [int , tuple [int , ...]]]
798808
809+ def _last_core_yin (self ) -> int :
810+ return self .ncores // (2 if self .yin_yang else 1 )
811+
812+ def _range_core_yin (self ) -> range :
813+ return range (self ._last_core_yin ())
814+
815+ def _range_core_yang (self ) -> range :
816+ return range (self ._last_core_yin () + 1 , self .ncores )
817+
799818 def coord_files_yin (self , path_root : Path ) -> Iterator [Path ]:
800- ncores = self .ncores // (2 if self .yin_yang else 1 )
801- for icore in range (ncores ):
819+ for icore in self ._range_core_yin ():
802820 yield path_root / self .coord_filepattern .format (icore = icore + 1 )
803821
822+ def _fsub (self , path_root : Path , name : str , icore : int , yang : bool ) -> FieldSub :
823+ ifile , shape = self .fields [name ]
824+ yy_tag = "2" if yang else "_"
825+ ic = icore + 1
826+ return FieldSub (
827+ file = path_root / f"{ name } _{ ifile :05d} _{ ic :05d} .h5" ,
828+ dataset = f"{ name } { yy_tag } { ic :05d} _{ self .isnap :05d} " ,
829+ icore = icore ,
830+ iblock = int (yang ),
831+ shape = shape ,
832+ )
833+
834+ def field_subdomains (self , path_root : Path , name : str ) -> Iterator [FieldSub ]:
835+ if name not in self .fields :
836+ return
837+ for icore in self ._range_core_yin ():
838+ yield self ._fsub (path_root , name , icore , False )
839+ for icore in self ._range_core_yang ():
840+ yield self ._fsub (path_root , name , icore , True )
841+
804842
805843@dataclass (frozen = True )
806844class FieldXmf :
@@ -874,6 +912,7 @@ def _data(self) -> Mapping[int, XmfEntry]:
874912 ncores += 1
875913
876914 data [isnap ] = XmfEntry (
915+ isnap = isnap ,
877916 time = time ,
878917 mo_lambda = mo_lambda ,
879918 mo_thick_sol = mo_thick_sol ,
0 commit comments