DiffEqOperators.jl
DiffEqOperators.jl copied to clipboard
grid spacing
It is kind difficult to understand what the arguments mean in the documents, specially for non-uniform grid. For examples, does dx
, when input as a vector, includes the spacing between the left/right boundary and the first/last point in CenteredDifference
, UpwindDiffer
and RobinBC
? What exactly is len
, is it the number of interior points?
Yes, in general we really need to completely overhaul the documentation and give it a real doc website with a lot more detail. When dx
is a vector, it includes the left right dx values and len
is the number of interior points.
I cann't get it work on non-uniform grid
# grid set up
L = 50.0 # domain [0,L]
N = 1000 # number of grid points
# a uniform grid
h = L/(N+1) # spatial steps
x = collect(range(h, step=h, length=N))
dx = vcat(x,L).-vcat(0,x)
# a non-uniform grid (finer mesh at the boundaries)
x = L*sin.(collect(range(h, step=h, length=N))/L*π/2).^2
dx = vcat(x,L).-vcat(0,x)
# a simple diffusion equation
D=10.0
Δ2 = CenteredDifference(2, 2,dx, N);
bcAge = RobinBC((0,-D,10.0),(1.0,0.0,0.0),dx,1);
function dAgedt_operator(dAge,Age,parm,t)
dAge .= D.*(Δ2*bcAge*Age) .+1
end
prob_operator = ODEProblem(dAgedt_operator,zeros(N),(0.0,10e3));
cb = TerminateSteadyState(1e-12, 1e-9,DiffEqCallbacks.allDerivPass);
@time sol = solve(prob_operator,CVODE_BDF(linear_solver=:Band,jac_upper=1,jac_lower=1),
reltol=1e-9,abstol=1e-12,callback=cb,tstops=10.0);
# analytical solution
analytical_sol = 175 .- x .- x.^2/20
The results are correct for the uniform grid but not the non-uniform one, which appears to give wrong boundary conditions at 0.
I took dx
as the distances between grid points. Is that correct for non-uniform grids?
I took dx as the distances between grid points. Is that correct for non-uniform grids?
Yeah that should be. I don't know if I can get to this soon, but thank you for all of your recent issues. I am collecting them to make a summer project out of it.