#!/usr/bin/env python3 from __future__ import annotations import ast import csv import math import os import re import shlex import subprocess from pathlib import Path ROOT = Path(os.environ.get("ENGIWORLD_EVAL_ROOT", "/home/user/Desktop")) CASE = ROOT / "dynamic" FORCES = CASE / "postProcessing/bodyForces/0/forces.dat" NUMBER = re.compile(r"[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?") def read(path: Path) -> str: return path.read_text(encoding="utf-8", errors="ignore") def named_block(text: str, name: str) -> str: text = re.sub(r"/\*.*?\*/|//[^\n]*", "", text, flags=re.S) match = re.search(rf"(?m)^\s*{re.escape(name)}\s*\{{", text) if not match: raise ValueError(f"missing block {name}") start = text.find("{", match.start()) depth = 0 for index in range(start, len(text)): depth += text[index] == "{" depth -= text[index] == "}" if depth == 0: return text[start + 1 : index] raise ValueError(f"unterminated block {name}") def paren_section(text: str, name: str) -> str: match = re.search(rf"(?m)^\s*{re.escape(name)}\s*\(", text) if not match: raise ValueError(f"missing section {name}") start = text.find("(", match.start()) depth = 0 for index in range(start, len(text)): depth += text[index] == "(" depth -= text[index] == ")" if depth == 0: return text[start + 1 : index] raise ValueError(f"unterminated section {name}") def has_entry(block: str, key: str, value: str) -> bool: return re.search(rf"(? float: match = re.search(rf"(? float: match = re.search( rf"(? tuple[float, float, float]: match = re.search( rf"(? str: return named_block(named_block(text, "boundaryField"), name) def zone_labels(text: str, name: str) -> set[int]: block = named_block(text, name) match = re.search(r"\bcellLabels\s+List