NeuralPDE.jl icon indicating copy to clipboard operation
NeuralPDE.jl copied to clipboard

Periodic boundary setting

Open vavrines opened this issue 3 years ago • 2 comments

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)

right

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 wrong

I'm using NeuralPDE v4.2.0.

vavrines avatar Dec 27 '21 20:12 vavrines

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.

KirillZubov avatar Dec 29 '21 11:12 KirillZubov

I'm having the same issue. What's the problem with the linked PR?

YichengDWu avatar Aug 16 '22 06:08 YichengDWu