scimba_torch.numerical_solvers.collocation_projector

Collocation-based projectors for approximation spaces.

Functions

plot(f, sampler[, n_visu])

Plot the function f over a 2D domain using sampled points.

Classes

AnagramProjector(space[, rhs])

Subclass of CollocationProjector using anagram-based optimization.

CollocationProjector(space[, rhs])

A collocation-based nonlinear projection method.

LinearProjector(space, rhs, **kwargs)

Subclass of CollocationProjector for linear projection problems.

NaturalGradientProjector(space[, rhs])

Subclass of CollocationProjector using natural gradient optimization.

class CollocationProjector(space, rhs=None, **kwargs)[source]

Bases: AbstractNonlinearProjector

A collocation-based nonlinear projection method.

This subclass implements methods to assemble the input and output tensors for a specific nonlinear projection problem using collocation points. It computes the approximation of a nonlinear problem by sampling collocation points and evaluating the corresponding function values.

Parameters:
  • space (AbstractApproxSpace) – The approximation space where the projection will take place.

  • rhs (Optional[Callable[..., Tensor]]) – The function representing the right-hand side of the problem.

  • **kwargs – Additional parameters for the projection, including collocation points and losses.

set_rhs(rhs)[source]

Sets the right-hand side function for the projection.

Parameters:

rhs (Callable[..., Tensor]) – The function representing the right-hand side of the problem.

get_dof(flag_scope='all', flag_format='list')[source]

Retrieves the degrees of freedom (DoF) of the approximation space.

Parameters:
  • flag_scope (str) – Specifies the scope of the parameters to return.

  • flag_format (str) – The format for returning the parameters.

Returns:

The degrees of freedom in the specified format.

metric_matrix(x, mu, t=None, v=None, **kwargs)[source]

Computes the metric matrix for the given tensors.

Parameters:
  • x (LabelTensor) – Input tensor from the spatial domain.

  • mu (LabelTensor) – Input tensor from the parameter domain.

  • t (LabelTensor | None) – Input tensor from the time domain (optional).

  • v (LabelTensor | None) – Input tensor from the velocity domain (optional).

  • **kwargs – Additional arguments.

Return type:

Tensor

Returns:

The computed metric matrix.

Raises:

NotImplementedError – If the metric matrix is not defined for the current space type.

sample_all_vars(**kwargs)[source]

Samples values in the domains of the arguments of the function to project.

Parameters:

**kwargs (Any) – Additional arguments for sampling.

Return type:

tuple[LabelTensor, ...]

Returns:

A tuple containing the sampled tensors.

assembly_post_sampling(data, **kwargs)[source]

Assemble the I/O tensors for the nonlinear projection problem after sampling.

Parameters:
  • data (tuple[LabelTensor, ...]) – The sampled data.

  • **kwargs – Additional arguments for assembly, including flag_scope.

Return type:

tuple[tuple[Tensor, ...], tuple[Tensor, ...]]

Returns:

A tuple of tuples containing the assembled left and right-hand sides.

assembly(**kwargs)[source]

Assembles the system of equations for the projection problem.

Parameters:

**kwargs (Any) – Additional arguments for assembly, including the number of collocation points.

Return type:

tuple[tuple[Tensor, ...], tuple[Tensor, ...]]

Returns:

A tuple of tuples containing the assembled left and right-hand sides.

class NaturalGradientProjector(space, rhs=None, **kwargs)[source]

Bases: CollocationProjector

Subclass of CollocationProjector using natural gradient optimization.

This class extends the CollocationProjector to use natural gradient optimization for solving the projection problem.

Parameters:
  • space (AbstractApproxSpace) – The approximation space where the projection will take place.

  • rhs (Optional[Callable[..., Tensor]]) – The function representing the right-hand side of the problem.

  • **kwargs – Additional parameters for the projection, including collocation points and losses.

class AnagramProjector(space, rhs=None, **kwargs)[source]

Bases: CollocationProjector

Subclass of CollocationProjector using anagram-based optimization.

This class extends the CollocationProjector to use anagram-based optimization for solving the projection problem.

Parameters:
  • space (AbstractApproxSpace) – The approximation space where the projection will take place.

  • rhs (Optional[Callable[..., Tensor]]) – The function representing the right-hand side of the problem.

  • **kwargs – Additional parameters for the projection, including collocation points and losses.

class LinearProjector(space, rhs, **kwargs)[source]

Bases: CollocationProjector

Subclass of CollocationProjector for linear projection problems.

This class extends the CollocationProjector to handle linear projection problems.

Parameters:
  • space (AbstractApproxSpace) – The approximation space where the projection will take place.

  • rhs (Callable) – The function representing the right-hand side of the problem.

  • **kwargs – Additional parameters for the projection, including collocation points and losses.

plot(f, sampler, n_visu=500)[source]

Plot the function f over a 2D domain using sampled points.

Parameters:
  • f (Callable) – The function to plot, which takes in sampled points and parameters.

  • sampler (Callable) – A callable that samples points from the domain.

  • n_visu (int) – The number of points along each axis for visualization.