NeuralPDE.jl
NeuralPDE.jl copied to clipboard
Periodic boundary setting
Say solving the advection equation with periodic boundary condition
u_t+u_x=0, u(0,x)=sin(2πx), u(t,0)=u(t,1)
The following code works well
using NeuralPDE, ModelingToolkit, Plots, Flux, DiffEqFlux, GalacticOptim, Optim
using ModelingToolkit: Interval
@parameters t, x
@variables u(..)
∂t, ∂x = Differential(t), Differential(x)
eq = ∂t(u(t, x)) + ∂x(u(t, x)) ~ 0
domains = [t ∈ Interval(0.0, 1.0), x ∈ Interval(0.0, 1.0)]
bcs = [u(t, 0) ~ sin(-2π * t), u(t, 1) ~ u(t, 0), u(0, x) ~ sin(2π * x)]
dx = 0.05
chain = FastChain(FastDense(2, 16, Flux.σ), FastDense(16, 16, Flux.σ), FastDense(16, 1))
initθ = Float64.(DiffEqFlux.initial_params(chain))
discretization = PhysicsInformedNN(chain, GridTraining(dx); init_params = initθ)
@named pde_system = PDESystem(eq, bcs, domains, [t, x], [u(t, x)])
prob = discretize(pde_system, discretization)
cb = function (p, l)
println("loss: $l")
return false
end
opt = Optim.BFGS()
res = GalacticOptim.solve(prob, opt; cb = cb, maxiters = 1200)
phi = discretization.phi
sol0 = [phi([0, x], res.u)[1] for x in xs]
sol1 = [phi([0.5, x], res.u)[1] for x in xs]
plot(xs, sol0)
plot!(xs, sol1)
If I change the sentence bcs = [u(t, 0) ~ sin(-2π * t), u(t, 1) ~ u(t, 0), u(0, x) ~ sin(2π * x)]
to a real periodic setting, e.g., bcs = [u(t, 0) ~ u(t, 1), u(t, 1) ~ u(t, 0), u(0, x) ~ sin(2π * x)]
, the result becomes
I'm using NeuralPDE v4.2.0.
the problem is that points are generated for the loss function as a whole and not for each variable. In essence, we are solving the equation u(t, 1) ~ u(t, 1) instead u(t, 1) ~ u(t, 0) I will try to fix it as soon as possible.
I'm having the same issue. What's the problem with the linked PR?