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)) ~ -(1000/238)
Boundary conditions
bcs = [Dx(u(0, y)) ~ 0.0, Dx(u(1, y)) ~ 0.0,
u(x, 0) ~ 350, Dy(u(x, 1)) ~ (50/238)*(298-u(x, 1)) ]
Space and time domains
domains = [x ∈ Interval(0.0, 1.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)
I wrote this code for 2D heat conduction in square shape. It runs properly and gives contour plot. But the problem is: when I want to makde it rectangular shape having x=2, y=1. the code results blank plot. There shows no contour. Just shows colour range with values. How can I do this