using NeuralPDE, Lux, Optimization, OptimizationOptimJL
import ModelingToolkit: Interval
@parameters x y
@variables u(…)
Dxx = Differential(x)^2
Dyy = Differential(y)^2
Dx = Differential(x)
Dy = Differential(y)
2D PDE
eq = Dxx(u(x, y)) + Dyy(u(x, y)) ~ -(1e-6/0.238)
Boundary conditions
bcs = [Dx(u(0, y)) ~ 0.0, Dx(u(2, y)) ~ 0.0,
Dy(u(x, 0)) ~ 0.0, Dy(u(x, 1)) ~ (5e-5/0.238)*(298-u(x, 1))]
Space and time domains
domains = [x ∈ Interval(0.0, 2.0), y ∈ Interval(0.0, 1.0)]
Neural network
dim = 2 # number of dimensions
chain = Lux.Chain(Dense(dim, 16, Lux.σ), Dense(16, 16, Lux.σ), Dense(16, 1))
Discretization
dx = 0.05
discretization = PhysicsInformedNN(chain, GridTraining(dx))
@named pde_system = PDESystem(eq, bcs, domains, [x, y], [u(x, y)])
prob = discretize(pde_system, discretization)
#Optimizer
opt = OptimizationOptimJL.BFGS()
#Callback function
callback = function (p, l)
println(“Current loss is: $l”)
return false
end
res = Optimization.solve(prob, opt, callback = callback, maxiters = 1000)
phi = discretization.phi
using Plots
xs, ys = [infimum(d.domain):(dx / 10):supremum(d.domain) for d in domains]
u_predict = reshape([first(phi([x, y], res.u)) for x in xs for y in ys],
(length(xs), length(ys)))
p1 = plot(xs, ys, u_predict, linetype = :contourf, title = “predict”);
plot(p1)`
> Preformatted text
`