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

Add demo of nonlinear scipy solver #3468

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Add demo of nonlinear scipy solver #3468

wants to merge 11 commits into from

Conversation

jorgensd
Copy link
Member

As we now support DOLFINx without PETSc, it is good to have a show-case of how to interface with scipy to solve problems.

@jorgensd jorgensd added the demo New demo or demo enhancements/improvements label Oct 11, 2024
jorgensd and others added 2 commits October 11, 2024 18:35
Thanks, Nate!

Co-authored-by: Nate <[email protected]>
Add header
Fix functional for complex run.
@garth-wells
Copy link
Member

We do already have a demo that uses a SciPy solver: https://github.com/FEniCS/dolfinx/blob/main/python/demo/demo_types.py

@jorgensd
Copy link
Member Author

We do already have a demo that uses a SciPy solver: https://github.com/FEniCS/dolfinx/blob/main/python/demo/demo_types.py

We only show how to solve linear problems.
I am happy to merge this one into that one.

@jorgensd jorgensd changed the title Add demo of scipy solver Add demo of nonlinear scipy solver Oct 11, 2024
@jorgensd
Copy link
Member Author

I at least think we should make it clearer from the demo title that it shows how to use scipy.
I guess if we make a separate demo repository we could add more descriptive documentation guiding the user.

Copy link
Member

@jhale jhale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not withstanding issue on where to put this raised by @garth-wells, here are my comments.

python/demo/demo_scipy-solvers.py Outdated Show resolved Hide resolved
python/demo/demo_scipy-solvers.py Show resolved Hide resolved
python/demo/demo_scipy-solvers.py Show resolved Hide resolved
python/demo/demo_scipy-solvers.py Outdated Show resolved Hide resolved
python/demo/demo_scipy-solvers.py Outdated Show resolved Hide resolved
python/demo/demo_scipy-solvers.py Outdated Show resolved Hide resolved
python/demo/demo_scipy-solvers.py Outdated Show resolved Hide resolved
python/demo/demo_scipy-solvers.py Show resolved Hide resolved

# If the Jacobian is independent of uh, we can avoid re-assembling the matrix

is_nonlinear = uh in ufl.algorithms.expand_derivatives(jacobian).coefficients()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhale I've here used `ufl to figure it out.
I think it is a quite nice point to make, as some people prefer always using a non-linear solver, but could benefit alot from not having to reassemble J at every step of the Newton solver (even if it is going to be just 1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
demo New demo or demo enhancements/improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants