feat: Add graceful well-posedness check for missing boundary conditions#543
feat: Add graceful well-posedness check for missing boundary conditions#543utkuyilmaz1903 wants to merge 2 commits into
Conversation
| throw(ArgumentError( | ||
| "Missing boundary condition for variable $(u_op) in dimension $(x). " * | ||
| "The system is ill-posed. Since $(u_op) has spatial derivatives with respect to $(x), " * | ||
| "you must provide boundary conditions for both ends of the domain." |
There was a problem hiding this comment.
what about upwinding problems where the velocity always has one sign? Then we only need an upwind BC
| for x in spatial_ivs | ||
| has_deriv = false | ||
| for eq in pdes | ||
| if occursin_derivative_of(eq.lhs, u_op, x) || occursin_derivative_of(eq.rhs, u_op, x) |
There was a problem hiding this comment.
we also need to account for higher order derivs, where more than 2 BCs can be needed
|
Thanks for the guidance. I've updated the PR to dynamically check the maximum spatial derivative order by recursively scanning the AST. The validation rule is now simply |
|
Interestingly, the MWE in #540 passes this well-posedness check. This suggests that the |
|
Following up on my previous comment from Apr 3: I was mistaken about #540 being a Chebyshev indexing bug. I realized it is actually an ill-posed parameterized advection problem. Because the wind direction Currently, our |
c0de918 to
bb47d78
Compare
|
@xtalax @ChrisRackauckas I updated the well-posedness validation logic. |
59b6058 to
96efc36
Compare
|
Needs tests. In particular, I'd like to see some periodic BC cases in there. |
|
You probably noticed the current periodic behavior in the commits. Right now, if a coupled BC (like periodic) is detected, the validation simply bypasses the counting logic. While this is a good temporary measure because it prevents unfairly blocking valid periodic setups, it also creates a loophole: a 4th-order PDE can currently pass validation with just a single periodic BC, which will cause a confusing crash later downstream. I've also been analyzing a few other edge cases, specifically pure outflow systems (which mathematically require 0 spatial BCs) and one-sided dynamic advection like Burgers' equation. Tomorrow, I will be working on upgrading the core logic to handle all these cases properly and I will add the tests. |
c364a1c to
a85522e
Compare
|
I've added the component tests, including the periodic cases. I've also updated the core logic. Just a quick note on one design choice I made. I kept the dynamic advection check strict (demanding 2 BCs for non-constant coefficients). I think this is the safest approach for compile-time stability since the upwind direction is unknown, even though it might be slightly restrictive for edge cases like pure outflow or one-sided Burgers' equations. I think it is in a good state now, but please let me know if you think we should adjust anything. |
|
I think the current CI failures seem to be infrastructure-related and not related to this PR |
3032ace to
33fa68f
Compare
|
I wanted to report my findings. I've looked into the logs, and it seems our new BC validator might actually be catching some legacy tests that are genuinely missing spatial constraints:
For the other failing jobs, based on the logs, they appear to fail for unrelated reasons:
(Also, the downstream Let me know what you think. |
508a774 to
6d6f9c3
Compare
Add missing newline at end of file.
e89df76 to
ffcb63e
Compare
Summary
MethodOfLines did not check whether a PDE system had enough boundary conditions before starting discretization. If the setup was ill-posed, users often hit confusing errors deep inside the pipeline (e.g. bounds/index issues during upwind discretization) with no clear link back to missing or insufficient BCs.
This PR adds
boundary_validation.jland calls it fromconstruct_var_equation_mappingbefore discretization proceeds.What changes for users
Missing BCs: If a variable has a spatial derivative but no BC is given at any boundary point, discretization now stops early with a direct
ArgumentErrorinstead of failing later.Issue #540 (parametric advection): For
-v * Dx(u)with only one BC, the old behavior was an opaque downstream failure. Now MoL detects that the advection coefficient is dynamic (parameter/state-dependent), so the upwind direction is unknown at compile time, and asks for BCs at both ends.Constant-velocity advection: For something like
-2.0 * Dx(u), one BC is enough — the check does not treat numeric literals as dynamic coefficients (including Symbolics 7 wrapped literals).Higher-order PDEs: The required number of boundary locations follows the max spatial derivative order (e.g. second order → two distinct locations).
Robin / Neumann BCs: Boundary locations are read from the BC expression AST, not just simple Dirichlet assignments.
Duplicate locations:
0and0.0at the same point count as one location, not two.Closes #540.