spectral_galerkin_heat.solvers.spectral

Unified Spectral Solver (CPU and GPU).

Classes

SpectralSolver

Spectral method solver for the heat equation with phase change and evaporation.

Module Contents

class spectral_galerkin_heat.solvers.spectral.SpectralSolver(backend, context=None, *, mixing_omega=None, convergence_tol=None, max_picard_iter=None)

Bases: spectral_galerkin_heat.solvers.base.HeatSolver

Spectral method solver for the heat equation with phase change and evaporation.

Uses fast cosine transforms (DCT) and exponential time differencing (ETD1). Runs on CPU (NumPy/Numba) or GPU (CuPy/CUDA) depending on the injected MathBackend: use NumpyBackend() for CPU and get_backend("cupy") for GPU.

Every numerical operation goes through self.backend.xp (the array module) and self.backend.kernels (the physics kernels), so the solver code is identical for both targets.

Parameters:
initialize(context=None)

Set up the spectral solver state, allocate buffers, and set the initial condition.

Parameters:

context (SimulationContext, optional) – If provided, replaces the stored SimulationContext. By default None.

Returns:

The initialized solver state object (backend-specific SpectralSolverState) containing grid buffers and spectra.

Return type:

Any

Raises:

RuntimeError – If SimulationContext is neither provided here nor at construction.

step(t, dt)

Advance the spectral solution by one time step using ETD1 and nonlinear evaporation correction.

Handles laser source, latent heat, and evaporation effects.

Parameters:
  • t (float) – Current simulation time.

  • dt (float) – Time step size.

Returns:

SsStateAny

The updated solver state.

metricsdict

Metrics from the iteration, such as max temperature and number of evaporation steps.

Return type:

tuple

set_state(temperature_field)

Overwrite the internal spectral coefficients from a spatial temperature field.

Converts the cell-centred temperature array into spectral (DCT) modes so that the solver can continue stepping from the injected state.

Parameters:

temperature_field (ndarray) – A 3-D array (shape (N_z, N_y, N_x)) containing temperatures. May be a NumPy or CuPy array.

Raises:

RuntimeError – If called before the solver is initialized.

Return type:

None

finalize()

Release nothing and return.

The spectral solver holds no resources requiring explicit release (CuPy frees device memory on garbage collection). This override is present only to satisfy the abstract HeatSolver.finalize() interface so the class is instantiable.

Return type:

None