# 2D wave equation with open boundary conditions

**URL:** https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290
**Category:** Modelling & Simulations
**Tags:** diffeq, sciml
**Created:** [August 28, 2023, 2:30pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290 "2023-08-28T14:30:40Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 28, 2023, 2:30pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/1 "2023-08-28T14:30:40Z")

</div>

Here is the equation I’m trying to solve and I’m surely doing something wrong - but I don’t know what exactly.  
Could you please help me to understand where I’m thinking wrong about it?

```julia
using NeuralPDE, Lux, LuxCUDA, Random, ComponentArrays, CUDA
using Optimization
using OptimizationOptimisers
import ModelingToolkit: Interval

device = gpu_device()

println("Setting Parameters")

@parameters t x y
@variables u(..)
Dx = Differential(x)
Dy = Differential(y)
Dxx = Differential(x)^2
Dyy = Differential(y)^2
Dt = Differential(t)
Dtt = Differential(t)^2
t_min = 0.0
t_max = 2.0
x_min = 0.0
x_max = 2.0
x_center = (x_min + x_max)/2
y_min = 0.0
y_max = 2.0
y_center = (y_min + y_max)/2
c = 1.0

first_maxiter = 250
#retrain_maxiter = first_maxiter

eq_scale=10000
bc_scale=1000
ic_scale=1000

println("Setting PDE")

# 2D PDE
eq = eq_scale*Dtt(u(t, x, y)) ~ eq_scale*(Dx(c*c*Dx(u(t, x, y))) + Dy(c*c*Dy(u(t, x, y))))

println("Setting IC and BC")

# analytic_sol_func(t, x, y) = exp(x + y) * cos(x + y + 4t)
# # Initial and boundary conditions
# bcs = [u(t_min, x, y) ~ analytic_sol_func(t_min, x, y),
# u(t, x_min, y) ~ analytic_sol_func(t, x_min, y),
# u(t, x_max, y) ~ analytic_sol_func(t, x_max, y),
# u(t, x, y_min) ~ analytic_sol_func(t, x, y_min),
# u(t, x, y_max) ~ analytic_sol_func(t, x, y_max)]

open_bc = [
    bc_scale*u(t,x_min,y) ~ bc_scale*c*Dx(u(t,x_min,y)),
    bc_scale*u(t,x_max,y) ~ -bc_scale*c*Dx(u(t,x_max,y)),
    bc_scale*u(t,x,y_min) ~ bc_scale*c*Dx(u(t,x,y_min)),
    bc_scale*u(t,x,y_max) ~ -bc_scale*c*Dx(u(t,x,y_max))
]

# impulse source IC
ic_func(x,y) = (x-x_center+0.2)*exp(-12*((x-x_center)^2+(y-y_center)^2))

ic = [
    ic_scale*u(t_min,x,y) ~ ic_scale*ic_func(x, y),
    ic_scale*Dt(u(t_min,x,y)) ~ 0.0
]

all_conditions = append!(open_bc, ic)

println("Setting Space and Domain")
# Space and time domains
domains = [t ∈ Interval(t_min, t_max),
    x ∈ Interval(x_min, x_max),
    y ∈ Interval(y_min, y_max)]

println("Setting NN")
# Neural network
inner = 25
chain = Chain(Dense(3, inner, Lux.σ),
              Dense(inner, inner, Lux.σ),
              Dense(inner, inner, Lux.σ),
              Dense(inner, inner, Lux.σ),
              Dense(inner, 1))

println("Prep PINN and cast to F64 GPU")
strategy = GridTraining(0.05)
ps, st = Lux.setup(Random.default_rng(), chain)
ps = ps |> ComponentArray |> device .|> Float64

println("Setting discretization using PINN")
discretization = PhysicsInformedNN(chain,
                                   strategy,
                                   init_params = ps)

println("Putting it all together into PDESystem")
@named pde_system = PDESystem(eq, all_conditions, domains, [t, x, y], [u(t, x, y)])
problem = discretize(pde_system, discretization)
symprob = symbolic_discretize(pde_system, discretization)

println("Start to solve using Optimization.Adam for 2500 max iterations")
callback = function (p, l)
    println("Current loss is: $l")
    return false
end

res = Optimization.solve(problem, Adam(0.01); callback = callback, maxiters = first_maxiter)

#println("Remake a problem with warmed-up approximation from the above iterations")
#prob = remake(problem, u0 = res.u)
#res = Optimization.solve(problem, Adam(0.001); callback = callback, maxiters = 2500)

println("Inspect the solution")

phi = discretization.phi
ts, xs, ys = [infimum(d.domain):0.1:supremum(d.domain) for d in domains]
#u_real = [analytic_sol_func(t, x, y) for t in ts for x in xs for y in ys]
u_predict = [first(Array(phi(device([t, x, y]), res.u))) for t in ts for x in xs for y in ys]

using Plots
using Printf

function plot_(res)
    # Animate
    anim = @animate for (i, t) in enumerate(t_min:0.05:t_max)
        @info "Animating frame $i..."
        #u_real = reshape([analytic_sol_func(t, x, y) for x in xs for y in ys],
        # (length(xs), length(ys)))
        u_predict = reshape([first(Array(phi(device([t, x, y]), res.u))) for x in xs for y in ys],
                            length(xs), length(ys))
        #u_error = abs.(u_predict .- u_real)
        title = @sprintf("predict, t = %.3f", t)
        p1 = plot(xs, ys, u_predict, st = :surface, label = "", title = title)
        #title = @sprintf("real")
        #p2 = plot(xs, ys, u_real, st = :surface, label = "", title = title)
        #title = @sprintf("error")
        #p3 = plot(xs, ys, u_error, st = :contourf, label = "", title = title)
        plot(p1,
            #p2,
            #p3
            )
    end
    gif(anim, "3pde.gif", fps = 10)
end

println("First plot")
plot_(res)
println("Look at '3pde.gif'")

function plot_wave(res)
    anim = @animate for (i,t) in enumerate(t_min:0.05:t_max)
        @info "Animating frame $i..."
        u_predict = reshape([Array(phi(device([t, x, y]), res.u))[1] for x in xs for y in ys],
                            length(xs), length(ys))
        surface(xs,ys,u_predict,layout=(1,2),size=(640,320),
            xlabel="x",ylabel="y",
            #zaxis=((-0.1,0.1),"u(x,y)"),
            zlabel="u(x,y)",
            color=:redsblues,alpha=0.66,
            #clims=(-0.1,0.1),
            colorbar=:none,
            title="Wave equation",dpi=100 )
        contour!(xs,ys,u_predict,levels=24,aspect_ratio=1,
            subplot=2,
            xlabel="x",ylabel="y",
            color=:redsblues,
            #clims=(-0.1,0.1),
            colorbar=:none,
            title=@sprintf("t = %.2f",t) )
        
    end
    closeall()
    gif(anim, "wave_pde.gif", fps = 10)
end

println("Second plot")
plot_wave(res)

println("Look at 'wave_pde.gif'")

```

---

<div class="post-metadata">

### Author: ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)
#### Post date: [August 28, 2023, 3:09pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/2 "2023-08-28T15:09:21Z")

</div>

Can you provide more specific information about what’s going wrong? Are you getting error messages or do the results just not seem correct?

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 28, 2023, 5:35pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/3 "2023-08-28T17:35:17Z")

</div>

Thank you, @mike.ingold , the result is wrong.  
 ![3pde](https://global.discourse-cdn.com/julialang/original/3X/0/5/055d540af667fab896ae2ddec8a04941fadda592.gif)

Thanks in Advance!

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 29, 2023, 12:35pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/4 "2023-08-29T12:35:34Z")

</div>

It seems strange that you use Dx(c_c_Dx(…)) and not c_c_Dxx(…)

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 29, 2023, 2:06pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/5 "2023-08-29T14:06:27Z")

</div>

Thank you, @Knud_Sorensen , for the question.  
It’s a precursor to the fact that C will be varying with X and Y in the future. And if it will be - that’s how it’s going to look.  
Do you think that this might be a problem?  
I do want to hear that I setup the problem wrong - since that restores my trust in NeuralPDE.jl…

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 29, 2023, 5:57pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/6 "2023-08-29T17:57:44Z")

</div>

For example, I’m not sure about this line: `Dt(u(t_min,x,y)) ~ 0.0` - is it doing anything at all? Should I replace it with `Dt(u(t,x,y))(t_min,x,y) ~ 0.0`.  
My physics understanding suggest that I should solve this:

\begin{split}\begin{split} \frac{\partial^2 u}{\partial t^2} &= \frac{\partial}{\partial x}(c^2\frac{\partial u}{\partial x}) + \frac{\partial}{\partial y}(c^2\frac{\partial u}{\partial y}) \\ \frac{\partial u}{\partial t} - c\frac{\partial u}{\partial x} &= 0,\quad \mbox{ at } x = x\_0 \\ \frac{\partial u}{\partial t} + c\frac{\partial u}{\partial x} &= 0,\quad \mbox{ at } x = x\_e \\ \frac{\partial u}{\partial t} - c\frac{\partial u}{\partial y} &= 0,\quad \mbox{ at } y = y\_0 \\ \frac{\partial u}{\partial t} + c\frac{\partial u}{\partial y} &= 0,\quad \mbox{ at } y = y\_e \\ u(t\_0,x,y) &= (x-x\_{center}+0.2) \cdot e^{-12 \cdot ((x-x\_{center})^2+(y-y\_{center})^2)} \\ \frac{\partial u}{\partial t} &= 0,\quad \mbox{ at } t = t\_0 \\ \end{split}\end{split}

I don’t know if I formulated it right, though.

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 29, 2023, 5:59pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/7 "2023-08-29T17:59:06Z")

</div>

Try to change it and see what happens. I also a newbie to working with differential equations in julia.

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 29, 2023, 6:09pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/8 "2023-08-29T18:09:44Z")

</div>

then you put in the wrong boundary conditions.  
\begin{split}\begin{split}u - c\frac{\partial u}{\partial x} &= 0,\quad \mbox{ at } x = x\_0 \ u + c\frac{\partial u}{\partial x} &= 0,\quad \mbox{ at } x = x\_e \ u - c\frac{\partial u}{\partial y} &= 0,\quad \mbox{ at } y = y\_0 \ u + c\frac{\partial u}{\partial y} &= 0,\quad \mbox{ at } y = y\_e \ \end{split}\end{split}

Sorry, don’t know how to get it rendered.

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 29, 2023, 6:25pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/9 "2023-08-29T18:25:29Z")

</div>

Just put two dollar signs around the equations:

\begin{split}\begin{split} u - c\frac{\partial u}{\partial x} &= 0,\quad \mbox{ at } x = x\_0 \\ u + c\frac{\partial u}{\partial x} &= 0,\quad \mbox{ at } x = x\_e \\ u - c\frac{\partial u}{\partial y} &= 0,\quad \mbox{ at } y = y\_0 \\ u + c\frac{\partial u}{\partial y} &= 0,\quad \mbox{ at } y = y\_e \\ \end{split}\end{split}

Yes - my bad - was during a meeting when I typed it… Thank you for the correction.

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 29, 2023, 6:38pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/10 "2023-08-29T18:38:51Z")

</div>

Whom should I ask for help here - I’m clearly missing something and it feels that if an experienced person would look at it - he/she would immediately be able to tell what is going on.

At this point - I’m really lost…

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 29, 2023, 6:43pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/11 "2023-08-29T18:43:38Z")

</div>

Did you fix the boundary conditions in your code ?? What result do you get then ?

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 29, 2023, 6:45pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/12 "2023-08-29T18:45:56Z")

</div>

I can see you went back and corrected your latex, but I think your latex was correct, and your code was wrong.

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 29, 2023, 6:58pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/13 "2023-08-29T18:58:42Z")

</div>

Yes! Looking into it… Well, I feel like 💩 now.

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 29, 2023, 7:13pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/14 "2023-08-29T19:13:33Z")

</div>

Just rerun it - still wrong.  
Here is the new code.

```julia
using NeuralPDE, Lux, LuxCUDA, Random, ComponentArrays, CUDA
using Optimization
using OptimizationOptimisers
import ModelingToolkit: Interval

device = gpu_device()

println("Setting Parameters")

@parameters t x y
@variables u(..)
Dx = Differential(x)
Dy = Differential(y)
Dxx = Differential(x)^2
Dyy = Differential(y)^2
Dt = Differential(t)
Dtt = Differential(t)^2
t_min = 0.0
t_max = 2.0
x_min = 0.0
x_max = 2.0
x_center = (x_min + x_max)/2
y_min = 0.0
y_max = 2.0
y_center = (y_min + y_max)/2
c = 1.0

first_maxiter = 250
retrain_maxiter = first_maxiter

eq_scale=1000
bc_scale=1000
ic_scale=1000

println("Setting PDE")

# 2D PDE
eq = eq_scale*Dtt(u(t, x, y)) ~ eq_scale*(Dx(c*c*Dx(u(t, x, y))) + Dy(c*c*Dy(u(t, x, y))))

println("Setting IC and BC")

open_bc = [
    bc_scale*Dt(u(t,x_min,y)) ~ bc_scale*c*Dx(u(t,x_min,y)),
    bc_scale*Dt(u(t,x_max,y)) ~ -bc_scale*c*Dx(u(t,x_max,y)),
    bc_scale*Dt(u(t,x,y_min)) ~ bc_scale*c*Dx(u(t,x,y_min)),
    bc_scale*Dt(u(t,x,y_max)) ~ -bc_scale*c*Dx(u(t,x,y_max))
]

# impulse source IC
ic_func(x,y) = (x-x_center+0.2)*exp(-12*((x-x_center)^2+(y-y_center)^2))

ic = [
    ic_scale*u(t_min,x,y) ~ ic_scale*ic_func(x, y),
    ic_scale*Dt(u(t_min,x,y)) ~ 0.0
]

all_conditions = append!(open_bc, ic)

println("Setting Space and Domain")
# Space and time domains
domains = [t ∈ Interval(t_min, t_max),
    x ∈ Interval(x_min, x_max),
    y ∈ Interval(y_min, y_max)]

println("Setting NN")
# Neural network
inner = 25
chain = Chain(Dense(3, inner, Lux.σ),
              Dense(inner, inner, Lux.σ),
              Dense(inner, inner, Lux.σ),
              Dense(inner, inner, Lux.σ),
              Dense(inner, 1))

println("Prep PINN and cast to F64 GPU")
strategy = GridTraining(0.05)
ps, st = Lux.setup(Random.default_rng(), chain)
ps = ps |> ComponentArray |> device .|> Float64

println("Setting discretization using PINN")
discretization = PhysicsInformedNN(chain,
                                   strategy,
                                   init_params = ps)

println("Putting it all together into PDESystem")
@named pde_system = PDESystem(eq, all_conditions, domains, [t, x, y], [u(t, x, y)])
problem = discretize(pde_system, discretization)
symprob = symbolic_discretize(pde_system, discretization)

println("Start to solve using Optimization.Adam for 2500 max iterations")
callback = function (p, l)
    println("Current loss is: $l")
    return false
end

res = Optimization.solve(problem, Adam(0.1); callback = callback, maxiters = first_maxiter)

println("Remake a problem with warmed-up approximation from the above iterations")
prob = remake(problem, u0 = res.u)
res = Optimization.solve(problem, Adam(0.01); callback = callback, maxiters = retrain_maxiter)

println("Inspect the solution")

phi = discretization.phi
ts, xs, ys = [infimum(d.domain):0.1:supremum(d.domain) for d in domains]
#u_real = [analytic_sol_func(t, x, y) for t in ts for x in xs for y in ys]
u_predict = [first(Array(phi(device([t, x, y]), res.u))) for t in ts for x in xs for y in ys]

using Plots
using Printf

function plot_(res)
    # Animate
    anim = @animate for (i, t) in enumerate(t_min:0.05:t_max)
        @info "Animating frame $i..."
        #u_real = reshape([analytic_sol_func(t, x, y) for x in xs for y in ys],
        # (length(xs), length(ys)))
        u_predict = reshape([first(Array(phi(device([t, x, y]), res.u))) for x in xs for y in ys],
                            length(xs), length(ys))
        #u_error = abs.(u_predict .- u_real)
        title = @sprintf("predict, t = %.3f", t)
        p1 = plot(xs, ys, u_predict, st = :surface, label = "", title = title)
        #title = @sprintf("real")
        #p2 = plot(xs, ys, u_real, st = :surface, label = "", title = title)
        #title = @sprintf("error")
        #p3 = plot(xs, ys, u_error, st = :contourf, label = "", title = title)
        plot(p1,
            #p2,
            #p3
            )
    end
    gif(anim, "3pde.gif", fps = 10)
end

println("First plot")
plot_(res)
println("Look at '3pde.gif'")

function plot_wave(res)
    anim = @animate for (i,t) in enumerate(t_min:0.05:t_max)
        @info "Animating frame $i..."
        u_predict = reshape([Array(phi(device([t, x, y]), res.u))[1] for x in xs for y in ys],
                            length(xs), length(ys))
        #U,_ = unpack(sol(t))
        surface(xs,ys,u_predict,layout=(1,2),size=(640,320),
            xlabel="x",ylabel="y",
            #zaxis=((-0.1,0.1),"u(x,y)"),
            zlabel="u(x,y)",
            color=:redsblues,alpha=0.66,
            #clims=(-0.1,0.1),
            colorbar=:none,
            title="Wave equation",dpi=100 )
        contour!(xs,ys,u_predict,levels=24,aspect_ratio=1,
            subplot=2,
            xlabel="x",ylabel="y",
            color=:redsblues,
            #clims=(-0.1,0.1),
            colorbar=:none,
            title=@sprintf("t = %.2f",t) )
        
    end
    closeall()
    gif(anim, "wave_pde.gif", fps = 10)
end

println("Second plot")
plot_wave(res)

println("Look at 'wave_pde.gif'")

```

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 29, 2023, 7:43pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/15 "2023-08-29T19:43:18Z")

</div>

Any errors ? What does the new plot look like ?

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 29, 2023, 7:55pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/16 "2023-08-29T19:55:12Z")

</div>

No errors, @Knud_Sorensen .  
 ![3pde](https://global.discourse-cdn.com/julialang/original/3X/4/b/4bd0110a8d7374434a17262fdee5d27a0e5fbeab.gif)  
and  
 ![wave_pde](https://global.discourse-cdn.com/julialang/original/3X/8/5/85540a8db1a0aa358fe5b5d8adad60390805461f.gif)

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 29, 2023, 8:34pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/17 "2023-08-29T20:34:39Z")

</div>

How low does the loss go ?

---

<div class="post-metadata">

### Author: ![thoth291](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thoth291/32/5202_2.png) [@thoth291](https://discourse.julialang.org/u/thoth291)
#### Post date: [August 30, 2023, 8:56pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/18 "2023-08-30T20:56:26Z")

</div>

Excuse me, @Knud_Sorensen , I had to switch temporarily to another task and missed your comment.  
The low goes as low as 1735 - please note that all constraints are scaled by 1000 - which is quite big.  
If I set the scalers to 1.0 - then the error goes down to 0.001733 and this is how the gifs are looking.  
 ![3pde](https://global.discourse-cdn.com/julialang/original/3X/c/5/c5957daf11750e70580f19cf84bb5eacdff3798a.gif)  
 ![wave_pde](https://global.discourse-cdn.com/julialang/original/3X/0/b/0b1ce34d655f20ccf5227758dd0a44e173a0e781.gif)  
So, it’s ether solves properly and I’m just not visualizing it well - or it’s just something else which I don’t understand.

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 30, 2023, 9:23pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/19 "2023-08-30T21:23:25Z")

</div>

Your program prints that it uses 2500 iterations  
But in reality, it only uses 500.  
Maybe try to run it for the full 2500 and see what the loss comes to.

---

<div class="post-metadata">

### Author: ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)
#### Post date: [August 31, 2023, 12:41pm UTC](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290/20 "2023-08-31T12:41:45Z")

</div>

I have played around with your code ! Is this more what you are looking for ?  
 ![3pde](https://global.discourse-cdn.com/julialang/original/3X/1/3/139453347a60c610b5a82e25c957f2722c8734c4.gif)  
 ![wave_pde](https://global.discourse-cdn.com/julialang/original/3X/a/5/a5db58303d6dc73e5abd1a4db6abae24b67ef9d0.gif)

[Next page](https://discourse.julialang.org/t/2d-wave-equation-with-open-boundary-conditions/103290.md?page=2)
