Fix inconsistent ufl usage in demos - #3532
Conversation
|
Not sure if it is worth continuing to work on this. Some of the developers are of the opinion that the choice of doing is to ensure that the weak formulation of the problem is as close to the one on paper as possible, avoiding to have to add a prefix |
|
Good point, but could we then switch to consistent usage of |
|
I guess so, unless the list of imported names gets super long. If I were you I would put this on hold until a few other developers have had the opportunity to comment. |
I think having a mixture doesn’t hurt. |
|
I noticed this by chance when copying the elasticity weak form 2.0 * μ * ufl.sym(grad(v)) + λ * ufl.tr(ufl.sym(grad(v))) * ufl.Identity(len(v))and it was not clear to me why it didn't just work with an |
Here I agree it is very confusing. It dangerously suggests |
4fee9be to
2910d49
Compare
|
Updated all demos that shared this behavior to always follow the style used for the weak form, which I guess is the most important part of the |
michalhabera
left a comment
There was a problem hiding this comment.
Looks good. I would have the opinion to make it unified and do not use ufl.grad, ufl.sym, ..., but if others like to keep some demos with the explicit names then this is a good compromise.
I quite like the explicitness of |
If I had to pick, I prefer |
There was a problem hiding this comment.
I find this confusing and would prefer ufl.foo. When I read, for example
c, mu = split(u)
it is extremely unclear if split is a dolfinx or a ufl function.
It would be better, in general, if imports from packages other than the 'home' package (dolfinx in the case of the demos) used namespacing.
|
When one decides for a consistent style one could also check for it https://docs.astral.sh/ruff/settings/#lint_flake8-import-conventions_banned-from |
I do not have a strong opinion here, so either way looks good. See also https://google.github.io/styleguide/pyguide.html#224-decision |
|
Switched to consistent and |
Some examples use multiple import schemes of
ufl, this switches to a single import style per demo.For example currenltly
demo_elasticity.pycontains:Other examples that share this:
demo_biharmonic.pydemo_cahn-hilliard.pydemo_hdg.pydemo_helmholtz.pydemo_lagrange_variants.pydemo_poisson_matrix_free.pydemo_poisson.pydemo_pyamg.pydemo_stokes.py