Skip to content

Commit b7f9727

Browse files
committed
Cache coordinates information in FieldXmf
1 parent 1d58b1f commit b7f9727

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

stagpy/stagyyparsers.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,10 @@ class XmfEntry:
857857
time: Optional[float]
858858
mo_lambda: Optional[float]
859859
mo_thick_sol: Optional[float]
860+
yin_yang: bool
861+
twod: Optional[str]
862+
coord_h5: list[Path]
863+
coord_shape: list[tuple[int, ...]]
860864

861865

862866
@dataclass(frozen=True)
@@ -892,10 +896,35 @@ def _data(self) -> Mapping[int, XmfEntry]:
892896
mo_lambda = self._maybe_get(snap, "mo_lambda", "Value", float)
893897
mo_thick_sol = self._maybe_get(snap, "mo_thick_sol", "Value", float)
894898

899+
yin_yang = False
900+
coord_h5 = [] # all the coordinate files
901+
coord_shape = [] # shape of meshes
902+
twod = None
903+
for elt_subdomain in snap.findall("Grid"):
904+
elt_name = _try_get(self.path, elt_subdomain, "Name")
905+
if elt_name.startswith("meshYang"):
906+
yin_yang = True
907+
break # iterate only through meshYin
908+
elt_geom = _try_find(self.path, elt_subdomain, "Geometry")
909+
if elt_geom.get("Type") == "X_Y" and twod is None:
910+
twod = ""
911+
for data_item in elt_geom.findall("DataItem"):
912+
coord = _try_text(self.path, data_item).strip()[-1]
913+
if coord in "XYZ":
914+
twod += coord
915+
data_item = _try_find(self.path, elt_geom, "DataItem")
916+
data_text = _try_text(self.path, data_item)
917+
coord_shape.append(_get_dim(self.path, data_item))
918+
coord_h5.append(self.path.parent / data_text.strip().split(":/", 1)[0])
919+
895920
data[isnap] = XmfEntry(
896921
time=time,
897922
mo_lambda=mo_lambda,
898923
mo_thick_sol=mo_thick_sol,
924+
yin_yang=yin_yang,
925+
coord_h5=coord_h5,
926+
coord_shape=coord_shape,
927+
twod=twod,
899928
)
900929
return data
901930

@@ -925,32 +954,12 @@ def read_geom_h5(xdmf: FieldXmf, snapshot: int) -> dict[str, Any]:
925954
"""
926955
header: Dict[str, Any] = {}
927956

928-
elt_snap = xdmf.get_snap(snapshot)
929957
entry = xdmf[snapshot]
930958
header["ti_ad"] = entry.time
931959
header["mo_lambda"] = entry.mo_lambda
932960
header["mo_thick_sol"] = entry.mo_thick_sol
933-
header["ntb"] = 1
934-
coord_h5 = [] # all the coordinate files
935-
coord_shape = [] # shape of meshes
936-
twod = None
937-
for elt_subdomain in elt_snap.findall("Grid"):
938-
elt_name = _try_get(xdmf.path, elt_subdomain, "Name")
939-
if elt_name.startswith("meshYang"):
940-
header["ntb"] = 2
941-
break # iterate only through meshYin
942-
elt_geom = _try_find(xdmf.path, elt_subdomain, "Geometry")
943-
if elt_geom.get("Type") == "X_Y" and twod is None:
944-
twod = ""
945-
for data_item in elt_geom.findall("DataItem"):
946-
coord = _try_text(xdmf.path, data_item).strip()[-1]
947-
if coord in "XYZ":
948-
twod += coord
949-
data_item = _try_find(xdmf.path, elt_geom, "DataItem")
950-
data_text = _try_text(xdmf.path, data_item)
951-
coord_shape.append(_get_dim(xdmf.path, data_item))
952-
coord_h5.append(xdmf.path.parent / data_text.strip().split(":/", 1)[0])
953-
_read_coord_h5(coord_h5, coord_shape, header, twod)
961+
header["ntb"] = 2 if entry.yin_yang else 1
962+
_read_coord_h5(entry.coord_h5, entry.coord_shape, header, entry.twod)
954963
return header
955964

956965

0 commit comments

Comments
 (0)