-
-
Notifications
You must be signed in to change notification settings - Fork 580
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
Proposal for a Spatial Method: Spectral Volumes #900
Comments
Hi @YannickNoelStephanKuhn , that sounds great, thanks for suggesting this! I think the easiest way to tackle this will be to create equations of increasing complexity and make sure they get discretised properly. For example: # define discretisation
# ....
var = pybamm.Variable("var", domain="negative electrode")
disc.set_variable_slices([var])
# first test
eqn = var
eqn_disc = disc.process_symbol(eqn)
# test discretised as expected
# ....
# second test
eqn = pybamm.grad(var)
eqn_disc = disc.process_symbol(eqn)
# test discretised as expected
# ....
# third test
eqn = pybamm.div(pybamm.grad(var))
eqn_disc = disc.process_symbol(eqn)
# test discretised as expected
# .... There is also more information on how to add a spatial method here, but the section on which methods need to be overwritten is out of date. See also this example notebook. Let us know if you need help with anything! |
Hi @YannickNoelStephanKuhn , how's this going? Do you need any help? |
Hello @tinosulzer , thank you for your support. I don't need any help yet, it is just that due to the "current events" due to the [redacted] that I didn't have as much time for this as I would've liked. |
Haha, fair enough, no pressure :) |
I finally found the time to actually implement this. Now I need some help with validating that it works as intended. The testing code above doesn't work anymore, or I understood something wrong about it. My minimal (non-)working example:
It breaks for the div-grad-equation with "pybamm.expression_tree.exceptions.ShapeError: Cannot find shape (original error: dimension mismatch)". Any ideas why that happens? On another note: alongside my spatial method I implemented a 1D submesh which is the only type of submesh that it is compatible with. This way, I could inherit most of pybamm.FiniteVolume. But that isn't as much of a constraint as it sounds like. Consider the following submesh:
My spatial method requires that each compartment (in this example, there are four) gets subdivided with Chebyshev collocation points. For convergence order 2, this looks like:
For convergence order 3, this looks like:
To me, this seemed like the better trade-off than re-writing most of pybamm.FiniteVolume. |
Glad you have found time to look at this again! disc.bcs = {
var.id: {
"left": (pybamm.Scalar(0), "Neumann"),
"right": (pybamm.Scalar(0), "Dirichlet"),
}
} Admittedly, this needs a clearer error message. |
I deleted my last comment, since I discovered the problem myself in the meantime. Sorry if I caused confusion. I simply included some of the operators that are crucial for applying Neumann conditions in the if branch that only gets triggered if Dirichlet conditions are present. Thus, the dimensions didn't match up, and I had to dig for the wrongly discretised symbol in /discretisation/discretisation.py at line 806. The error message there might be more helpful if it printed the discretised symbol in question. |
Ok, glad you have it under control :) Feel free to add any more error messages that you feel might be useful or more informative. Let me know if you need any more help. |
I might break the error message for some edge cases in the process, and it would only be useful for someone else who implements a spatial method and can't count dimensions properly. :) And my local flake8 somehow missed some things that your flake8 found, so I fixed them in my fork. |
Fixed by #1123 |
Spectral Volumes are a higher-order generalization of Finite Volumes. They subdivide the same mesh Finite Volumes would use into so-called Control Volumes. These are used to compute a polynomial in each Finite Volume which is conservative in each Control Volume. Both the polynomial and its integral average over the Finite Volume are a higher-order approximation.
In contrast to higher-order Finite Volumes, which have all sorts of difficult numerical issues, Spectral Volumes are easily incorporated into any (1D, 2D, 3D) mesh. Additionally, they give higher-order approximations for boundary values which give much better resolution of e.g. Butler-Volmer flows. Compared to Orthogonal Collocation or other Spectral Methods, Spectral Volumes have the following additional benefits:
I implemented 2nd-order Spectral Volumes for my own battery code, and while I couldn't see that the convergence rate increases globally as I hoped for, the convergence rate of interfacial processes was indeed higher. My proposal is that I implement Spectral Volumes of arbitrary order in 1D as a Spatial Method for PyBaMM. A discussion about the storage of the additional internal states and possible output of these internal states for plotting would be necessary first, though.
Relevant paper: https://www.sciencedirect.com/science/article/pii/S0021999102970415
TL;DR: Spectral Volumes are the Finite Volume-equivalent to Spectral Methods for Finite Elements. Since they are not a Spectral Method per se, I didn't write this as a reply to issue #565.
The text was updated successfully, but these errors were encountered: