How to solve 2D PDE for heat conduction with x and y having different length (A rectangle)

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

Welcome! Your post is a little hard to read — could you take some time to edit and format it such that it leads with the core question and the code itself is formatted? You can use triple-backticks to encapsulate a section of code like so:

```
# code block goes here
```

Thanks! Doing that will help those who may be able to answer your question read and understand it more clearly.

2 Likes