Periodic Boundary Condition Embedding#

class PeriodicBoundaryEmbedding(input_dimension, periods, output_dimension=None)[source]#

Bases: Module

Imposing hard constraint periodic boundary conditions by embedding the input.

A periodic function \(u:\mathbb{R}^{\rm{in}} \rightarrow\mathbb{R}^{\rm{out}}\) periodic in the spatial coordinates \(\mathbf{x}\) with periods \(\mathbf{L}\) is such that:

\[u(\mathbf{x}) = u(\mathbf{x} + n \mathbf{L})\;\; \forall n\in\mathbb{N}.\]

The PeriodicBoundaryEmbedding() augments the input such that the periodic conditons is guarantee. The input is augmented by the following formula:

\[\mathbf{x} \rightarrow \tilde{\mathbf{x}} = \left[1, \cos\left(\frac{2\pi}{L_1} x_1 \right), \sin\left(\frac{2\pi}{L_1}x_1\right), \cdots, \cos\left(\frac{2\pi}{L_{\rm{in}}}x_{\rm{in}}\right), \sin\left(\frac{2\pi}{L_{\rm{in}}}x_{\rm{in}}\right)\right],\]

where \(\text{dim}(\tilde{\mathbf{x}}) = 3\text{dim}(\mathbf{x})\).

See also

Original reference:
  1. Dong, Suchuan, and Naxian Ni (2021). A method for representing periodic functions and enforcing exactly periodic boundary conditions with deep neural networks. Journal of Computational Physics 435, 110242. DOI: 10.1016/j.jcp.2021.110242.

  2. Wang, S., Sankaran, S., Wang, H., & Perdikaris, P. (2023). An expert’s guide to training physics-informed neural networks. DOI: arXiv preprint arXiv:2308.0846.

Warning

The embedding is a truncated fourier expansion, and only ensures function PBC and not for its derivatives. Ensuring approximate periodicity in the derivatives of \(u\) can be done, and extensive tests have shown (also in the reference papers) that this implementation can correctly compute the PBC on the derivatives up to the order \(\sim 2,3\), while it is not guarantee the periodicity for \(>3\). The PINA code is tested only for function PBC and not for its derivatives.

Parameters:
  • input_dimension (int) – The dimension of the input tensor, it can be checked with tensor.ndim method.

  • periods (float | int | dict) – The periodicity in each dimension for the input data. If float or int is passed, the period is assumed constant for all the dimensions of the data. If a dict is passed the dict.values represent periods, while the dict.keys represent the dimension where the periodicity is applied. The dict.keys can either be int if working with torch.Tensor or str if working with LabelTensor.

  • output_dimension (int) – The dimension of the output after the fourier embedding. If not None a torch.nn.Linear layer is applied to the fourier embedding output to match the desired dimensionality, default None.

forward(x)[source]#

Forward pass to compute the periodic boundary conditions embedding.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Periodic embedding of the input.

Return type:

torch.Tensor

property period#

The period of the periodic function to approximate.