1# These functions are RAMSES-specific
2import re
3
4from yt.config import ytcfg
5from yt.funcs import mylog
6
7
8def ramses_header(hvals):
9    header = (
10        ("ncpu", 1, "i"),
11        ("ndim", 1, "i"),
12        ("nx", 3, "i"),
13        ("nlevelmax", 1, "i"),
14        ("ngridmax", 1, "i"),
15        ("nboundary", 1, "i"),
16        ("ngrid_current", 1, "i"),
17        ("boxlen", 1, "d"),
18        ("nout", 3, "i"),
19    )
20    yield header
21    # TODO: REMOVE
22    noutput, iout, ifout = hvals["nout"]
23    next_set = (
24        ("tout", noutput, "d"),
25        ("aout", noutput, "d"),
26        ("t", 1, "d"),
27        ("dtold", hvals["nlevelmax"], "d"),
28        ("dtnew", hvals["nlevelmax"], "d"),
29        ("nstep", 2, "i"),
30        ("stat", 3, "d"),
31        ("cosm", 7, "d"),
32        ("timing", 5, "d"),
33        ("mass_sph", 1, "d", True),
34    )
35    yield next_set
36
37
38field_aliases = {
39    "standard_five": ("Density", "x-velocity", "y-velocity", "z-velocity", "Pressure"),
40    "standard_six": (
41        "Density",
42        "x-velocity",
43        "y-velocity",
44        "z-velocity",
45        "Pressure",
46        "Metallicity",
47    ),
48}
49
50## Regular expressions used to parse file descriptors
51VERSION_RE = re.compile(r"# version: *(\d+)")
52# This will match comma-separated strings, discarding whitespaces
53# on the left hand side
54VAR_DESC_RE = re.compile(r"\s*([^\s]+),\s*([^\s]+),\s*([^\s]+)")
55
56OUTPUT_DIR_RE = re.compile(r"(output|group)_(\d{5})")
57STANDARD_FILE_RE = re.compile(r"((amr|hydro|part|grav)_\d{5}\.out\d{5}|info_\d{5}.txt)")
58
59
60## Configure family mapping
61particle_families = {
62    "DM": 1,
63    "star": 2,
64    "cloud": 3,
65    "dust": 4,
66    "star_tracer": -2,
67    "cloud_tracer": -3,
68    "dust_tracer": -4,
69    "gas_tracer": 0,
70}
71
72if ytcfg.has_section("ramses-families"):
73    for key in particle_families.keys():
74        val = ytcfg.get("ramses-families", key, fallback=None)
75        if val is not None:
76            mylog.info(
77                "Changing family %s from %s to %s", key, particle_families[key], val
78            )
79            particle_families[key] = val
80