SciML / DiffEqOperators.jl

Linear operators for discretizations of differential equations and scientific machine learning (SciML)
https://docs.sciml.ai/DiffEqOperators/stable/
Other
284 stars 74 forks source link

Incorrect boundary padded vector with composed PeriodicBC on 2d data #514

Open vigeesh opened 2 years ago

vigeesh commented 2 years ago

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?

xtalax commented 2 years ago

I will take a look at this

xtalax commented 2 years ago

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 commented 2 years ago

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

vigeesh commented 2 years ago

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).

xtalax commented 2 years ago

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.

vigeesh commented 2 years ago

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)