Skip to content

# utils.py

# `` Parameters `dataclass`

    Parameters(
        dim: D1,
        n_x: int,
        n_y: int,
        n_z: int,
        p: float,
        p0: float,
        seed: int,
        n_iterations: int,
        sample_period: int,
        axis_topology_x: Topology,
        axis_topology_y: Topology,
        axis_topology_z: Topology,
        axis_bcs_x: tuple[BoundaryCondition, BoundaryCondition],
        axis_bcs_y: tuple[BoundaryCondition, BoundaryCondition],
        axis_bcs_z: tuple[BoundaryCondition, BoundaryCondition],
        axis_bc_values_x: tuple[bool, bool],
        axis_bc_values_y: tuple[bool, bool],
        axis_bc_values_z: tuple[bool, bool],
        do_edge_buffering: bool,
        processing: Processing,
        n_threads: int,
    )

Dummy declaration: shadows definition in Rust.

Used by:

- Python modules
  - `` make_name
  - `` make_title

# `` make_name

    make_name(parameters: Parameters, variable: str, i_slice: int | None = None)

Generate a string summarizing the sim for file naming.

Source code in `python/dprs/utils.py`

     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    def make_name(parameters: Parameters, variable: str, i_slice: int|None = None):
        """Generate a string summarizing the sim for file naming."""
        return (
              f"{variable}"
            + (
                f"_p{parameters.p:0.7f}".replace(".", "p")
                    if parameters.dim==sim.Dimension.D3
                else f"_p{parameters.p:0.6f}".replace(".", "p")
            )
            + f"_s{parameters.seed}"
            + f"_nx{parameters.n_x}"
            + (
                f"_ny{parameters.n_y}" if parameters.n_y>1
                else ""
            )
            + (
                f"_nz{parameters.n_z}" if parameters.n_z>1
                else ""
            )
            + (f"_i{i_slice*parameters.sample_period:0{5}}"
               if i_slice is not None else "")
        )

# `` make_title

    make_title(
        parameters: Parameters, i_slice: int | None = None, z_slice: int | None = None
    )

Generate a string summarizing the sim for entitling plots.

Source code in `python/dprs/utils.py`

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    def make_title(parameters: Parameters, i_slice: int|None = None, z_slice: int|None = None):
        """Generate a string summarizing the sim for entitling plots."""
        return (
            (
                rf"$p={parameters.p:0.7f}$" if parameters.dim==sim.Dimension.D3
                else rf"$p={parameters.p:0.6f}$"
            )
            + rf"   $s={parameters.seed}$"
            + (
                rf"   $n_x={parameters.n_x}$" if parameters.n_x>=10000
                else rf"   $n_x={parameters.n_x}$"
            )
            + (
                rf"   $n_y={parameters.n_y}$" if parameters.n_y>1
               else ""
            )
            + (
                rf"   $n_z={parameters.n_z}$" if parameters.n_z>1
               else ""
            )
            + ("\n" + rf"$i={i_slice*parameters.sample_period:0{5}}$"
               if i_slice is not None else "")
            + (rf"   $z={z_slice}$"
               if z_slice is not None else "")
        )