DeepRitzMethod<T>
Models & Types · AiDotNet.PhysicsInformed.PINNs
Implements the Deep Ritz Method for solving variational problems and PDEs.
Inheritance: NeuralNetworkBase<T> → DeepRitzMethod<T>
How It Works
For Beginners: The Deep Ritz Method is a variational approach to solving PDEs using neural networks. Instead of minimizing the PDE residual directly (like standard PINNs), it minimizes an energy functional.
The Ritz Method (Classical): Many PDEs can be reformulated as minimization problems. For example:
- Poisson equation: -∇²u = f is equivalent to minimizing E(u) = ½∫|∇u|² dx - ∫fu dx
- This is called the “variational formulation”
- The solution minimizes the energy functional
Deep Ritz (Modern):
- Use a neural network to represent u(x)
- Compute the energy functional using automatic differentiation
- Train the network to minimize the energy
- Naturally incorporates boundary conditions
Advantages over Standard PINNs:
- More stable training (minimizing energy vs. residual)
- Natural framework for problems with variational structure
- Often converges faster
- Physical interpretation (energy minimization)
Applications:
- Elasticity (minimize strain energy)
- Electrostatics (minimize electrostatic energy)
- Fluid dynamics (minimize dissipation)
- Quantum mechanics (minimize expected energy)
- Optimal control problems
Key Difference from PINNs: PINN: Minimize ||PDE residual||² Deep Ritz: Minimize ∫ Energy(u, ∇u) dx
Both solve the same PDE, but Deep Ritz uses the variational (energy) formulation, which can be more natural and stable for certain problems.
Example
var architecture = new NeuralNetworkArchitecture<float>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputSize: 2, outputSize: 1);
var deepRitz = new DeepRitzMethod<float>(architecture, DeepRitzEnergy<float>.Poisson());
Constructors
| Constructor | Summary |
|---|---|
DeepRitzMethod(NeuralNetworkArchitecture<T> architecture, Func<Tensor<T>, Tensor<T>, Tensor<T>, Tensor<T>> energyFunctional, DeepRitzMethodOptions options) |
Initializes a new instance of the Deep Ritz Method. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
Serializes Deep Ritz-specific data. |
Methods
| Method | Summary |
|---|---|
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the Deep Ritz model. |
T ComputeTotalEnergy() |
The Monte Carlo estimate of the energy integral (1/N) sum_i E(x_i, u(x_i), grad u(x_i)) at the current quadrature points, with grad u taken through the gradient tape. |
Tensor<T> Forward(Tensor<T> input) |
Performs a forward pass through the network. |
Vector<T> GetSolution(Vector<T> point) |
Gets the solution at a specific point. |