GradientPINN#
- class GradientPINN(problem, model, optimizer=None, scheduler=None, weighting=None, loss=None)[source]#
Bases:
PINN
Gradient Physics-Informed Neural Network (GradientPINN) solver class. This class implements the Gradient Physics-Informed Neural Network solver, using a user specified
model
to solve a specificproblem
. It can be used to solve both forward and inverse problems.The Gradient Physics-Informed Neural Network solver aims to find the solution \(\mathbf{u}:\Omega\rightarrow\mathbb{R}^m\) of a differential problem:
\[\begin{split}\begin{cases} \mathcal{A}[\mathbf{u}](\mathbf{x})=0\quad,\mathbf{x}\in\Omega\\ \mathcal{B}[\mathbf{u}](\mathbf{x})=0\quad, \mathbf{x}\in\partial\Omega \end{cases}\end{split}\]minimizing the loss function;
\[\mathcal{L}_{\rm{problem}} =& \frac{1}{N}\sum_{i=1}^N \mathcal{L}(\mathcal{A}[\mathbf{u}](\mathbf{x}_i)) + \frac{1}{N}\sum_{i=1}^N \mathcal{L}(\mathcal{B}[\mathbf{u}](\mathbf{x}_i)) + &\frac{1}{N}\sum_{i=1}^N \nabla_{\mathbf{x}}\mathcal{L}(\mathcal{A}[\mathbf{u}](\mathbf{x}_i)) + \frac{1}{N}\sum_{i=1}^N \nabla_{\mathbf{x}}\mathcal{L}(\mathcal{B}[\mathbf{u}](\mathbf{x}_i))\]where \(\mathcal{L}\) is a specific loss function, typically the MSE:
\[\mathcal{L}(v) = \| v \|^2_2.\]See also
Original reference: Yu, Jeremy, et al. Gradient-enhanced physics-informed neural networks for forward and inverse PDE problems. Computer Methods in Applied Mechanics and Engineering 393 (2022):114823. DOI: 10.1016.
Note
This class is only compatible with problems that inherit from the
SpatialProblem
class.Initialization of the
GradientPINN
class.- Parameters:
problem (AbstractProblem) – The problem to be solved. It must inherit from at least
SpatialProblem
to compute the gradient of the loss.model (torch.nn.Module) – The neural network model to be used.
optimizer (Optimizer) – The optimizer to be used. If
None
, thetorch.optim.Adam
optimizer is used. Default isNone
.scheduler (Scheduler) – Learning rate scheduler. If
None
, thetorch.optim.lr_scheduler.ConstantLR
scheduler is used. Default isNone
.weighting (WeightingInterface) – The weighting schema to be used. If
None
, no weighting schema is used. Default isNone
.loss (torch.nn.Module) – The loss function to be minimized. If
None
, thetorch.nn.MSELoss
loss is used. Default isNone
.
- Raises:
ValueError – If the problem is not a SpatialProblem.
- loss_phys(samples, equation)[source]#
Computes the physics loss for the physics-informed solver based on the provided samples and equation.
- Parameters:
samples (LabelTensor) – The samples to evaluate the physics loss.
equation (EquationInterface) – The governing equation.
- Returns:
The computed physics loss.
- Return type: