scimba_torch.numerical_solvers.temporal_pde.neural_galerkin

Neural Galerkin method for time-dependent PDEs.

Classes

NeuralGalerkin(pde, projector[, scheme])

Implementation of the Neural Galerkin method for time-dependent PDEs.

class NeuralGalerkin(pde, projector, scheme='euler_exp', **kwargs)[source]

Bases: ExplicitTimeDiscreteScheme

Implementation of the Neural Galerkin method for time-dependent PDEs.

Parameters:
  • pde (TemporalPDE) – The temporal PDE to be solved.

  • projector (TimeDiscreteCollocationProjector) – The time discrete collocation projector.

  • scheme (str) – The time integration scheme to use (‘euler_exp’, ‘rk2’, ‘rk4’).

  • **kwargs – Additional keyword arguments.

sampling()[source]

Call the sampling function of the two samplers.

Save the number of points.

compute_model(t)[source]

Compute the mass matrix and the RHS of the Neural Galerkin method.

Computes:

\[\begin{split}M(\theta) &= \frac{1}{N} \sum (J(\theta) \otimes J(\theta))(x,mu) \\ F(\theta) &= \frac{1}{N} \sum (J(\theta) * f(\theta))(x,mu)\end{split}\]
Parameters:

t (float) – Current time.

residual(t, x, mu)[source]

This function computes the PDE residual and concatenates it, if needed.

Parameters:
  • t (float) – Current time.

  • x (LabelTensor) – Spatial points where the residual is computed.

  • mu (LabelTensor) – Parameter points where the residual is computed.

Return type:

Tensor

Returns:

The residual tensor.

Raises:

ValueError – If the residual is neither a tensor nor a tuple of tensors.

inner_update_lstsq(t)[source]

Computes the update of the parameters \(\theta_n\).

Uses a least squares solver, based on the Jacobian J and the RHS f.

Parameters:

t (float) – Current time.

Return type:

Tensor

Returns:

The update of the parameters \(\theta_n\).

inner_update_matrix(t)[source]

Compute the update of the parameters \(\theta_n\).

Based on the mass matrix \(M = J^T J\) and the RHS \(F = J^T f\).

Parameters:

t (float) – Current time.

Return type:

Tensor

Returns:

The update of the parameters \(\theta_n\).

inner_rk_step(t, dt, k=None)[source]

Compute the n-th step of the Runge-Kutta method.

Computes:

\[k_n = f(\theta_n + \Delta t \sum_{i=1}^{n-1} a_{n,i} k_i)\]
Parameters:
  • t (float) – Current time.

  • dt (float | list[float]) – Time step multiplied by the coefficients \(a_{n,i}\). If dt or k are not lists, they are converted to lists.

  • k (Tensor | list[Tensor] | None) – list of \(k_i\). If dt or k are not lists, they are converted to lists.

Return type:

Tensor

Returns:

The value of the new \(k_n\) based on the new parameters.

Note

If \(dt = 0\), computes \(f(\theta_n)\). Otherwise, k should not be None, to be multiplied to dt.

update(t, dt, **kwargs)[source]

Computes the next time step of the Neural Galerkin method.

Parameters:
  • t (float) – Current time.

  • dt (float) – Time step.

  • **kwargs – Additional keyword arguments.