RBCMHDEnv3D

class fluidgym.envs.rbc_mhd.RBCMHDEnv3D(rayleigh_number: float, chandrasekhar_number: float, prandtl_number: float, aspect_ratio: float, resolution: int, wall_grading: float, min_layer_cells: int, n_electrodes: int, electrode_fill: float, max_current: float, power_penalty_weight: float, dt: float, adaptive_cfl: float, step_length: float, episode_length: int, aspect_ratio_x: float | None = None, n_stations: int | None = None, local_obs_window: int = 3, local_reward_weight: float | None = None, advection_scheme: str = 'linear_upwind', use_marl: bool = False, potential_tol: phipict.solvers.tolerance.SolverTolerance = None, potential_solve_max_iter: int = 10000, potential_use_preconditioner: bool = True, exclude_potential_solve_gradients: bool = False, **kwargs: Any)[source]

Bases: FluidEnv

Rayleigh-Bénard convection in a horizontal magnetic field.

Each Hartmann wall is divided into n_electrodes patches along y and n_stations stations along z. Each patch holds a raised-cosine electrode covering electrode_fill of the patch pitch in y and z, surrounded by insulating wall. Electrode k exists on both walls, and the pair carries the current I_k, half through each wall (the convention of fluidgym.envs.blanket.actuators). The action sets I_k; it is centred to zero net current (the box is otherwise insulating, so the potential problem needs it), clamped to the action bounds, centred again and scaled by max_current. In MARL mode, each station along z is an agent that sets the currents of its column of electrodes.

The reward is the relative change of the volume-averaged Nusselt number minus the electrical power fed into the fluid, relative to the power the buoyancy does on the uncontrolled flow:

r = Nu / Nu_ref - 1 - power_penalty_weight * P_el / P_ref

so the heat transfer is to be raised, both averaged over the PISO steps of the env step. Nu_ref and P_ref are the means of the uncontrolled episodes (domain statistics). In MARL mode, an agent receives local_reward_weight times the same Nusselt term over the columns of its observation window plus the remainder of the global reward, as in RBCEnv3D.

Parameters:
  • rayleigh_number (float) – Rayleigh number based on H and the plate temperature difference.

  • chandrasekhar_number (float) – Chandrasekhar number Q = Ha^2 based on H. Must be positive.

  • prandtl_number (float) – Prandtl number.

  • aspect_ratio (float) – Extent of the box along z, in units of H.

  • aspect_ratio_x (float | None) – Extent of the box along x, i.e. along B between the Hartmann walls, in units of H. Defaults to aspect_ratio.

  • resolution (int) – Number of cells along y; x and z have round(aspect_ratio_x * resolution) and round(aspect_ratio * resolution).

  • wall_grading (float) – tanh grading strength towards the walls normal to y and z.

  • min_layer_cells (int) – Minimum number of cells inside the Hartmann layer at each Hartmann wall; the x grading is chosen for it.

  • n_electrodes (int) – Electrodes along y on each Hartmann wall.

  • n_stations (int | None) – Electrode stations along z. Defaults to round(aspect_ratio * n_electrodes).

  • electrode_fill (float) – Fraction of the patch pitch an electrode covers in y and z, in (0, 1].

  • max_current (float) – Largest current of an electrode pair (both walls together), in units of sigma U B H^2.

  • power_penalty_weight (float) – Weight of the electrical power in the reward.

  • dt (float) – The simulation time step; substeps adapt to adaptive_cfl.

  • adaptive_cfl (float) – Target CFL number for adaptive time stepping.

  • step_length (float) – The physical time length of each environment step.

  • episode_length (int) – The number of steps per episode.

  • local_obs_window (int) – Number of electrode stations along z an agent observes in MARL mode (odd). Beyond the side walls, the window holds the quiescent conduction state.

  • local_reward_weight (float | None) – Weighting factor for local rewards in multi-agent settings. Has to be set for multi-agent RL.

  • advection_scheme (str) – Convective scheme of the momentum equation, "central" or "linear_upwind".

  • use_marl (bool) – Whether to enable multi-agent reinforcement learning mode.

  • potential_tol (float | SolverTolerance | Mapping | None) – Tolerance of the electric potential solve.

  • potential_solve_max_iter (int) – Iteration limit of the electric potential solve.

  • potential_use_preconditioner (bool) – Whether to solve the potential with AMG-preconditioned CG.

  • exclude_potential_solve_gradients (bool) – Drop the gradient of the potential solve. Diagnostic only.

  • **kwargs – Parameters of FluidEnv.

References

[1] T. Yanagisawa, Y. Hamano, T. Miyagoshi, Y. Yamagishi, Y. Tasaka, and Y. Takeda, “Convection patterns in a liquid metal under an imposed horizontal magnetic field,” Phys. Rev. E, vol. 88, no. 6, p. 063020, Dec. 2013, doi: 10.1103/PhysRevE.88.063020.

compute_nusselt() → Tensor[source]

Volume-averaged Nusselt number 1 + sqrt(Ra Pr) <u_y (T - T_ref)>.

Returns:

The Nusselt number of every environment, [E].

Return type:

torch.Tensor

detach() → None[source]

Detach all tensors from the current computation graph.

property electrode_mask: Tensor

Electrode cells of a Hartmann wall, [Z, Y] bool.

get_temperature() → Tensor[source]

Return the current temperature field resampled to the render shape.

Returns:

Temperature field, with a leading env dim for a vectorized environment.

Return type:

torch.Tensor

property hartmann_number: float

Hartmann number Ha = sqrt(Q).

property id: str

Unique identifier for the environment.

property initial_domain_id: str

Unique identifier for the initial domain.

The uncontrolled flow is the same for every electrode layout, and the electrode conditions are applied after loading (see _apply_potential_layout()), so all of them share the domains of the plain insulating box.

property n_agents: int

The number of agents in the environment.

property nu_ref: float

Reference Nusselt number for the reward.

property obs_resampling_shape: tuple[int, ...]

The shape (x, y, z) of the observation resampling grid.

plot(output_path: Path | None = None) → None[source]

Plot the electrode current shares on a Hartmann wall.

Parameters:

output_path (Path | None) – Directory to save the plot in. If None, the current directory is used. Defaults to None.

property power_ref: float

Buoyancy power of the uncontrolled flow, the scale of the power penalty.

property stuart_number: float

Lorentz force coefficient N = Q sqrt(Pr / Ra).