SciML / DiffEqOperators.jl

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

Make periodic BCs work with discretizations that are at cell boundaries #301

Open ArjunNarayanan opened 3 years ago

ArjunNarayanan commented 3 years ago

Right now PeriodicBC assumes that the end-points of a discretization do not overlap under periodicity. To make this work, the user must be aware of this assumption and ensure that their discretization is at cell centers instead of cell boundaries.

This can get awkward. For example, if f has period 1, then you want f(0) = f(1). If you were to discretize on the unit interval, you would likely make a grid of the form x = 0:dx:1 with end-points included.

PeriodicBC assumes that the left-neighbor of x[1] is x[end] https://github.com/SciML/DiffEqOperators.jl/blob/56288c46af895976f66bdddc85e0c10a67b1668d/src/derivative_operators/bc_operators.jl#L175

This is not consistent with our choice of discretization above, since x[1] and x[end] are actually the same points (under periodicity).

We could get around this by making the grid x = dx/2:dx:(1-dx/2) but this is a little awkward, and it is (I assume) not consistent with other types of boundary conditions that require the grid point to actually lie on the boundary.

We could overcome this by simply requiring PeriodicBC to use the 2nd and end-1 th points, but perhaps there are more elegant solutions.

ChrisRackauckas commented 3 years ago

We could overcome this by simply requiring PeriodicBC to use the 2nd and end-1 th points, but perhaps there are more elegant solutions.

Yeah that's not quite elegant either. Maybe we should have a flag somewhere about the interpretation? It's a hard issue .

ArjunNarayanan commented 3 years ago

I haven't really looked into the other BC types in DiffEqOperators, but do they also assume that the discretization is at cell centers?

ChrisRackauckas commented 3 years ago

All others can work with the discretizations at the cell centers or on the grid points.