-
-
Notifications
You must be signed in to change notification settings - Fork 74
Add option to shift grid by half a point in MOLFiniteDifference
for conservative method
#378
Comments
We will want arrays of
The points at which coefficient functions are evaluated also changes. Other than that, yes agreed. |
Update: Almost all of the existing code can be reused by doing # Define the grid on which the dependent variables will be evaluated (see #378)
# "center" is recommended for Dirichlet BCs
# "edge" is recommended for Neumann BCs (spatial discretization is conservative)
if grid_align == "center"
grid = space
grid_indices = space_indices
elseif grid_align == "edge"
# boundary conditions implementation assumes centered_order=2
@assert discretization.centered_order==2
# construct grid including ghost nodes beyond outer edges
# e.g. space 0:dx:1 goes to grid -dx/2:dx:1+dx/2
space_ext = map(s -> vcat(2s[1]-s[2],s,2s[end]-s[end-1]), space)
grid = map(s -> (s[1:end-1]+s[2:end])/2, space_ext)
# TODO: allow depvar-specific center/edge choice?
end and using f(u(t,0),Dx(u(t,0)) ~ c we can replace i.e. if grid_align=="center", we have bc equations for u1 and un and interior equations for u2:un-1 (values at dx:dx:L-dx); if grid_align="edges", we have bc equations for u1 and un+1 (ghost nodes) and interior equations for u2:un (values of u at dx/2:dx:L-dx/2) |
To allow a
MOLFiniteDifference
method to be conservative, we just need to shift the grid bydx/2
so thatx=0
andx=L
are aligned with edges of the grid instead of cell centers. In this case the grid would bedx/2:dx:L-dx/2
instead of0:dx:L
.For example this could be a keyword-argument in
MOLFiniteDifference
:grid_align="center"
(default, current implementation), or"edge"
.In terms of implementation, the only difference would be in the boundary conditions:
Dt(u1) ~ Dx((u2-u1)/dx - a)
wherea
is the flux at the left-hand boundaryDt(un) ~ Dx(b - (un-u(n-1))/dx)
whereb
is the flux at the right-hand boundary.If the boundary conditions are Neumann
a
andb
are given directly. If the boundary conditions are Dirichleta
andb
can be calculated by extrapolating to ghost nodes.Therefore, in the general case
we can replace
Dx(u(t,0))
witha
andu(t,0)
withu1-a*dx/2
, which then gives a bc equation for the fluxa
(and similarly on the right-hand boundary).(This is like a Finite Volume discretization, but on a regular grid the result is the same)
Will wait for discussions in this issue before trying to implement this
The text was updated successfully, but these errors were encountered: