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

Incorrect boundary padded vector with composed PeriodicBC on 2d data

Open vigeesh opened this issue 3 years ago • 6 comments

I'm trying to pad my vector u using the boundary condition operator Q. It works fine for 1d data, but gives me incorrect padded vector for 2d data when I use PeriodicBC.

Code for reproduction

1-D

#left-plot
plot(data1d)
#right-plot
Q1 = Dirichlet0BC(Float64)
plot(Q1*data1d,label="Q1*u (Dirichlet)")
Q2 = PeriodicBC(Float64)
plot!(Q2*data1d,label="Q2*u (Periodic)")

out

2-D

#left-plot
heatmap(data2d)
#right-plot
Q3 = compose(Dirichlet0BC(Float64, (6,6))...)
heatmap(Q3*data2d)

2d_dir

But, when I use PeriodicBC,

#left-plot
Q4 = compose(PeriodicBC(Float64, (6,6))...)
heatmap(Q4*data2d)
#right-plot
heatmap(periodic_expected)

I get a padded data as shown in the left plot below, but I expect to get the one shown in the right, 2d_per

Am I doing something wrong in composing the BC's in 2-D?

vigeesh avatar Feb 22 '22 09:02 vigeesh

I will take a look at this

xtalax avatar Feb 22 '22 16:02 xtalax

In the meantime, you should be aware that MethodOfLines.jl now has support for periodic BCs. If this doesn't help you solve your problem we'd love to know why.

xtalax avatar Feb 23 '22 18:02 xtalax

There's something strange going on, here the first testset passes, wheras the second testset displays the issue you described though both contain periodic BCs

xtalax avatar Feb 23 '22 18:02 xtalax

Thanks @xtalax , I'll have a look at MethodOfLines.jl

here the first testset passes,

But it looks like it's not returning a correctly padded data.

I'm not sure if I understand this line:

BCx = vcat(fill(q1, div(m,2)), fill(q2, m-div(m,2)))  #The size of BCx has to be all size components *except* for x
BCy = vcat(fill(q2, div(n,2)), fill(q1, n-div(n,2)))

Why is it not,

BCx = fill(q1,m)
BCy = fill(q2,n)

But, even in the latter case, it gives me wrong results when I use PeriodicBC in both dims, but strangely gives me correct padding when I use a combination of PeriodicBC (along one dim) and Dirichlet/Neumann/RobinBC (for the other dim).

vigeesh avatar Feb 24 '22 12:02 vigeesh

This was to test the constructor which supports different bcs along a boundary to facilitate space dependant robin.

But, even in the latter case, it gives me wrong results when I use PeriodicBC in both dims, but strangely gives me correct padding when I use a combination of PeriodicBC (along one dim) and Dirichlet/Neumann/RobinBC (for the other dim).

How are you applying the BCs, with compose? I wonder if its due to some compiler strangeness simplifying the filled periodic as a single object.

xtalax avatar Feb 24 '22 14:02 xtalax

How are you applying the BCs, with compose?

yes, like in the test

BCx = fill(q1,m)
BCy = fill(q2,n)
Qx = MultiDimBC{1}(BCx)
Qy = MultiDimBC{2}(BCy)
Q = compose(BCx,BCy)

vigeesh avatar Feb 24 '22 14:02 vigeesh