Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-uniform adaptive meshing #232

Open
ns-ku opened this issue Nov 3, 2024 · 4 comments
Open

Non-uniform adaptive meshing #232

ns-ku opened this issue Nov 3, 2024 · 4 comments
Labels

Comments

@ns-ku
Copy link

ns-ku commented Nov 3, 2024

Hi!

I am testing BVP solvers but cannot figure how to obtain a non-uniform meshing for BVP problems.
The mesh that I get does get adapted but remains uniform (for that, I check sol.t).
Are the non-uniform meshes (like in bvp4c in Matlab) supported by BoundaryValueDiffEq?
I use version 5.12.0.

Here is the example of the code:
`function bvp!(du, u, p, x)
du[1] = u[2]
du[2] = -u[1]
end

function bc!(residual, u, p, t)
residual[1] = u[1][1] - 0
residual[2] = u[1][end] -2
end

tspan = (0, pi/2)
u0 = [1.0, -1.0]
prob = BVProblem(bvp!, bc!, u0, tspan)

sol = solve(prob, MIRK4(), dt = 0.05, abstol = 1e-9)

plot(sol, seriestype=:scatter, lw=2)
xlabel!("x")
ylabel!("u(x)")
plot(sol.t, seriestype=:scatter, lw=2)`

Am I missing something?

Thanks a lot for the help in advance!`

@ns-ku ns-ku added the question label Nov 3, 2024
@ErikQQY
Copy link
Member

ErikQQY commented Nov 3, 2024

The non-uniform mesh refinement will only be triggered if the defect of the obtained numerical solution from solving given BVP system is higher than absolute tolerance and the initial mesh is not equidistributed, which means the BVP you want to solve is not well-posed and the dt you gave the solver is not satisfying, but this linear problem may not be such a case.

@ns-ku
Copy link
Author

ns-ku commented Nov 3, 2024

Thanks!
That was just an example. I have, of course, also tried with non-linear equations.
I was just wondering if something can generally be done for those problems, where the solution changes rapidly within a small time-span (like Allen-Cahn equations), to get a better resolution in the problematic regions but coarser mesh in the regions with nearly no changes.

@ErikQQY
Copy link
Member

ErikQQY commented Nov 8, 2024

Sorry, somehow lost track of this issue

I was just wondering if something can generally be done for those problems

The answer is yes, the point of defect estimation and mesh refinement is to overcome such difficulty in solving such problems, you can refer to chapter 9 of "Numerical Solution of Boundary Value Problems for Ordinary Differential Equations" by U. Ascher et al, which is also the mesh selection and redistribution algorithms in MIRK and FIRK methods in BoundaryValueDiffEq.jl

@ChrisRackauckas
Copy link
Member

That was just an example. I have, of course, also tried with non-linear equations.

On a difficult nonlinear equation it didn't adapt? This case seems to just be because MIRK methods of high order converge very fast on this test equation, so there's no need to adapt, the starting dt choice is a sufficient approximation to the tolerance that is chosen. You'd need to also decrease the relative tolerance to make it do more. We see in the benchmarks on many equations that it very quickly can get to an error below machine epsilon for linear BVPs.

I'd suspect in a nonlinear equation you'd find it generally will need to adapt though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants