I wanted to generate a contour plot for 2D heat conduction by neural PDE but this code generates blank plot without any contour

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)


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))


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)

opt = OptimizationOptimJL.BFGS()

#Callback function
callback = function (p, l)
println(“Current loss is: $l”)
return false

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”);

> Preformatted text


Please put your code in triple backticks, as described here

otherwise it’s very tedious to copy and run the code.

What are the package/Julia versions you are using here?

What is the output of


What is the output of

using Pkg


1 Like

I think I answered this question on Slack and it was just older packages held back by having some random un-updated thing in the global environment.