Hard-constrained architectures
Learning objectives
- State the general lifted-ansatz construction u(x) = u_BC(x) + φ(x) NN(x) and explain what each piece contributes
- Construct the ansatz for two-point Dirichlet BCs on an interval, and verify the boundary conditions are identities of the architecture
- Recognise when this construction is and is not available (rectangular geometry → easy; complicated boundary → hard)
- Choose between hard-constrained and soft-enforced BCs for a given problem
§1.5 introduced hard-constraint enforcement on the simplest possible problem (a harmonic oscillator with two ICs at ). This section generalises the recipe to two-point Dirichlet boundary value problems, gives the general construction template, and surveys when it applies and when it does not.
The lifted-ansatz template
For a PDE with boundary conditions on , write the network output as:
Three pieces:
- : any (smooth) function that matches the prescribed boundary values. Often a polynomial extension of the BC values into the interior.
- : a (smooth) function that vanishes on . Often a polynomial that is zero at the boundary points and positive in the interior.
- : an ordinary neural network with no constraints — free to be anything.
Substitute : . The boundary condition is satisfied for any choice of network parameters . Optimisation never has to learn the BCs; they are baked into the architecture.
Try it: two-point Dirichlet
The simplest non-trivial example is the two-point Dirichlet problem on with and . Choose:
- : the linear interpolant. , .
- : the smallest polynomial vanishing at both endpoints. .
The full ansatz: . Drag the boundary sliders in the widget below to see this in action. The PDE we are solving is the homogeneous Helmholtz equation with the chosen Dirichlet BCs; its true solution is where .
The widget races a soft-enforcement network (red, with the deliberately poorly-tuned ) against the hard-constraint network (blue). The status strip shows the BC error at each endpoint for the soft network; the hard network's BC error is zero by construction. Drag the boundary value sliders during training to see the hard network's prediction snap to the new boundaries instantly while the soft network has to chase them.
Other common ansatz constructions
| Boundary condition | Ansatz |
|---|---|
| 1D ODE on [0, T] with u(0) = u₀ | u(t) = u₀ + t·NN(t) |
| 1D ODE with u(0) = u₀, u′(0) = v₀ | u(t) = u₀ + v₀·t + t²·NN(t) |
| 1D BVP on [a, b] with u(a) = uₐ, u(b) = u_b | u(x) = u_BC(x) + (x − a)(b − x)·NN(x) |
| 2D rectangle [a, b] × [c, d] with all-Dirichlet BCs | u(x, y) = u_BC(x, y) + (x − a)(b − x)(y − c)(d − y)·NN(x, y) |
| Periodic BCs in x | Replace input x with [sin(2πx / L), cos(2πx / L)] before the network |
When the construction does NOT apply
Hard-constraint enforcement requires:
- A closed-form that matches the boundary data. For non-zero, time-dependent, or implicit boundaries this can be hard to construct.
- A closed-form that vanishes on . For complicated geometries (curved boundaries, holes, internal interfaces) this is often as hard as solving the PDE.
For seismic problems on rectangular cubes (the typical domain of choice), both pieces are easy. For real geological topography (an undulating free surface, internal salt boundaries), soft enforcement remains the default. Modern PINN-FWI work often uses a hybrid: hard for the simple BCs (zero free-surface displacement, zero initial wavefield, periodic horizontal continuation), soft for everything else.
What you now know
You can write down a hard-constraint ansatz for any of the standard boundary conditions — single-point initial value, two-point Dirichlet, mixed Dirichlet-Neumann (with extra polynomial factors), and periodic. You can also recognise when the construction is not available and you have to fall back on soft enforcement plus the loss-balance machinery of Part 3. §2.5 turns to architectures designed for the multi-scale problems that vanilla, Fourier-feature, and SIREN networks all struggle with individually.
Pause-and-check. (1) For a 1D BVP on [-2, 2] with u(-2) = 0 and u(2) = 1, write the hard-constraint ansatz. (2) Why is the polynomial the simplest choice for two-point Dirichlet on [0, 1], rather than, say, ? (3) For a 2D PDE on a circular disc of radius with on the boundary, write a candidate . Why does this construction not generalise to arbitrary geometries?
References
- Lagaris, I.E., Likas, A., Fotiadis, D.I. (1998). Artificial neural networks for solving ordinary and partial differential equations. IEEE Trans. Neural Networks 9(5), 987–1000.
- Sukumar, N., Srivastava, A. (2022). Exact imposition of boundary conditions with distance functions in physics-informed deep neural networks. CMAME 389, 114333.
- Berg, J., Nyström, K. (2018). A unified deep artificial neural network approach to partial differential equations in complex geometries. Neurocomputing 317, 28–41.
- Sun, L., Gao, H., Pan, S., Wang, J.-X. (2020). Surrogate modeling for fluid flows based on physics-constrained deep learning without simulation data. CMAME 361, 112732.