Skip to content

Klein-Gordon 1D

Example
Source DeepXDE example
Problem Forward and Inverse (the Inverse mode is PINNStudio's addition)
Dimension 1D (x, t)
Regime Time-dependent
Geometry Interval
Outputs u
Settings Default, Tuned

Governing equations

Mathematical form (from the benchmark records):

\[\frac{\partial^2 u}{\partial t^2} - \frac{\partial^2 u}{\partial x^2} + u^2 = -x\cos t + x^2\cos^2 t, \qquad x \in [-1, 1],\ t \in [0, 10]\]

As typed in PINNStudio's Equations page (each expression is a residual, set to zero):

du_tt + alpha*du_xx + beta*u + gamma*u**k + x*cos(t) - x**2*cos(t)**2

Constants: alpha = -1, beta = 0, gamma = 1, k = 2

Domain

  • Interval: \(x \in [-1, 1]\)
  • Time interval: \(t \in [0, 10]\)

Initial conditions

Output Initial value How it is imposed (Settings: Default)
u x loss term

Boundary conditions

Type Where Output Value Details
Dirichlet BC True (the whole boundary) u x*cos(t) —
Operator BC (advanced) initial time — du_t applied at the initial time

Unknowns and measured data (Inverse)

Trainable parameter Initial value True value
gamma 0.5 1

Measured data (Inverse page, measured-data files):

Settings

Forward mode

Settings: Default — DeepXDE's own settings

  • Network: FNN, hidden layers 2 × 40, inputs (x, t), 1 output; activation tanh, initializer Glorot uniform
  • Points: 30,000 domain, 1,500 boundary, 1,500 initial, 6,000 test
  • Loss weights: 1,1,1,1 (equations, then boundary-condition rows, then initial conditions)
Phase Optimizer Iterations Learning rate Decay
1 Adam 20,000 0.001 inverse time (3000, 0.9)
2 L-BFGS 15,000 — none
Settings: Tuned

The Training Log reports: Tuned settings: a larger network (hidden layers twice as wide, one more layer). The change is applied to the example's own settings.

  • Network: FNN, hidden layers 3 × 80, inputs (x, t), 1 output; activation tanh, initializer Glorot uniform
  • Points: 30,000 domain, 1,500 boundary, 1,500 initial, 6,000 test
  • Loss weights: 1,1,1,1 (equations, then boundary-condition rows, then initial conditions)
Phase Optimizer Iterations Learning rate Decay
1 Adam 20,000 0.001 inverse time (3000, 0.9)
2 L-BFGS 15,000 — none

Inverse mode

Settings: Default — DeepXDE's settings with PINNStudio's Inverse-mode changes (see Notes)

  • Network: FNN, hidden layers 2 × 40, inputs (x, t), 1 output; activation tanh, initializer Glorot uniform
  • Points: 30,000 domain, 1,500 boundary, 1,500 initial, 6,000 test
  • Loss weights: 1,1,1,1 (equations, then boundary-condition rows, then initial conditions)
Phase Optimizer Iterations Learning rate Decay
1 Adam 20,000 0.001 inverse time (3000, 0.9)
2 L-BFGS 15,000 — none
Settings: Tuned

The Training Log reports: Tuned settings: 3× iterations, a larger network, 3× points and an L-BFGS phase together. The change is applied to the example's own settings.

  • Network: FNN, hidden layers 3 × 80, inputs (x, t), 1 output; activation tanh, initializer Glorot uniform
  • Points: 90,000 domain, 4,500 boundary, 4,500 initial, 6,000 test
  • Loss weights: 1,1,1,1 (equations, then boundary-condition rows, then initial conditions)
Phase Optimizer Iterations Learning rate Decay
1 Adam 60,000 0.001 inverse time (3000, 0.9)
2 L-BFGS 45,000 — none

Results

The configuration selected in PINNStudio's benchmark study, run on one RTX 4090. Forward: relative L₂ error of each output at the last reference time. Inverse: each parameter's relative error and, per seed, the largest of them (worst parameter error).

Forward problem

Settings: Tuned — Larger network (2× width, one more layer). Values: median over seeds 2026, 1, 2.

Output Relative L₂
u 2.3 × 10⁻³
Forward result: PINN, reference and error
Forward, Tuned settings: PINN, reference and error.

Inverse problem

Settings: Tuned — all of the changes together. Values: median over seeds 2026, 1, 2.

Parameter True value Recovered Relative error
gamma 1 1.00912 0.91 %

Worst parameter error: 0.91 % (the median over the seeds of each seed's largest error).

Inverse result: PINN, reference and error
Inverse, Tuned settings: PINN, reference and error.
Inverse result: parameter convergence
Inverse, Tuned settings: parameter convergence.

Full benchmark record: every setting tried, the per-seed values and all figures are in the benchmark records on GitHub.

Loading it in PINNStudio

  • Forward: toolbar Examples: › Forward › under the ── 1D ── heading, Klein-Gordon 1D › Default or Tuned, then Solve.
  • Inverse: toolbar Examples: › Inverse › under the ── 1D ── heading, Klein-Gordon 1D › Default or Tuned, then Solve.

Loading an example fills in every setting; anything you change before Solve is listed in the Training Log. Your save folder, GPU, random-seed and plot-style settings are kept.

Reference solution

  • Exact solution, Error Analysis › reference from formula: u = x*cos(t)

Notes

  • The second initial condition du/dt = 0 is applied at t = 0. (DeepXDE's script passes it to an OperatorBC, which selects spatial-boundary points rather than t = 0.)
  • Inverse mode (PINNStudio's addition): the coefficient gamma of the nonlinear term (initial guess 0.5, true 1) is learned from u measured at t = 1, 2, ..., 10 (reference_data/deepxde/klein_gordon_inverse). alpha and beta stay known: the solution u = x cos t has u_xx = 0, so the data cannot tell alpha, and beta = 0.

Definition and records

How the benchmark values were measured and checked: Reproducibility.

← Back to the example gallery