Skip to content

EOS output

Append-mode writer for per-iteration pressure and density profiles. Used by the inner solver loop to record every Picard iterate so post-run plotting can show the convergence trajectory of the radial structure.

output

Output file creation for pressure and density profiles.

create_pressure_density_files(outer_iter, inner_iter, pressure_iter, radii, pressure, density)

Append pressure and density profiles to output files for a given iteration.

Parameters:

Name Type Description Default
outer_iter int

Current outer iteration index.

required
inner_iter int

Current inner iteration index.

required
pressure_iter int

Current pressure iteration index.

required
radii ndarray

Radial positions, in m.

required
pressure ndarray

Pressure values corresponding to radii, in Pa.

required
density ndarray

Density values corresponding to radii, in kg/m^3.

required

Returns:

Type Description
None
Source code in src/zalmoxis/eos/output.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def create_pressure_density_files(
    outer_iter, inner_iter, pressure_iter, radii, pressure, density
):
    """Append pressure and density profiles to output files for a given iteration.

    Parameters
    ----------
    outer_iter : int
        Current outer iteration index.
    inner_iter : int
        Current inner iteration index.
    pressure_iter : int
        Current pressure iteration index.
    radii : numpy.ndarray
        Radial positions, in m.
    pressure : numpy.ndarray
        Pressure values corresponding to ``radii``, in Pa.
    density : numpy.ndarray
        Density values corresponding to ``radii``, in kg/m^3.

    Returns
    -------
    None
    """

    output_dir = os.path.join(get_zalmoxis_root(), 'output')
    os.makedirs(output_dir, exist_ok=True)
    pressure_file = os.path.join(output_dir, 'pressure_profiles.txt')
    density_file = os.path.join(output_dir, 'density_profiles.txt')

    # Only delete the files once at the beginning of the run
    if outer_iter == 0 and inner_iter == 0 and pressure_iter == 0:
        for file_path in [pressure_file, density_file]:
            if os.path.exists(file_path):
                os.remove(file_path)

    # Append current iteration's pressure profile to file
    with open(pressure_file, 'a') as f:
        f.write(f'# Pressure iteration {pressure_iter}\n')
        np.savetxt(f, np.column_stack((radii, pressure)), header='radius pressure', comments='')
        f.write('\n')

    # Append current iteration's density profile to file
    with open(density_file, 'a') as f:
        f.write(f'# Pressure iteration {pressure_iter}\n')
        np.savetxt(f, np.column_stack((radii, density)), header='radius density', comments='')
        f.write('\n')