-
-
Notifications
You must be signed in to change notification settings - Fork 194
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 functions to copy data between Function(s) and PETSc Vecs #3652
Conversation
Some outstanding points:
|
They do not do not always come in as a consistent state (observed in the SNESSolver). |
I've reduced the number of functions and made them much simpler, and demonstrated usage in the SNES tests. The functions should not have ghost updates. Copying the ghost values eliminates any need for a 'post' update. Any 'pre' ghost update should be performed by the caller. Throwing in mis-guided ghost updates is something we have eliminated in DOLFINx. If we go with this, the 'assign' functions that are 'linear algebra' only should probably move to a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only minor things to consider.
Should we move it into dolfinx.la.petsc
right away?
python/dolfinx/fem/petsc.py
Outdated
|
||
@functools.singledispatch | ||
def assign( | ||
x0: typing.Union[npt.NDArray[np.floating], list[npt.NDArray[np.floating]]], x1: PETSc.Vec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the typing also include np.complexfloating
for complex values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my reading of the numpy documentation this concept is expressed as np.inexact
. https://numpy.org/doc/stable/reference/arrays.scalars.html#inexact-types
I suspect we're making a number of issues overtyping/undertyping/incorrectly typing throughout the codebase. This could be looked at in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearly we should get this one agreed on so we can look elsewhere!
python/dolfinx/fem/petsc.py
Outdated
|
||
Assigns values in ``x`` to the degrees-of-freedom of ``u``, which is | ||
possibly a collection of ``Functions``s. When ``u`` is a collecion | ||
of ``Functions``s, values in ``x`` are assigned block-wise ro the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of ``Functions``s, values in ``x`` are assigned block-wise ro the | |
of ``Functions``s, values in ``x`` are assigned block-wise to the |
python/dolfinx/fem/petsc.py
Outdated
|
||
@assign_function.register(PETSc.Vec) | ||
def _(x: PETSc.Vec, u: typing.Union[_Function, list[_Function]]): | ||
"""Assign vector entries to :class:`.Function` degrees-of-freedom. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Assign vector entries to :class:`.Function` degrees-of-freedom. | |
"""Assign vector entries to :class:`Function` degrees-of-freedom. |
Should there really be a .
here?
We don't have a |
The |
My interpretation of @garth-wells comment was that the lower-level routine should be made private, rather than putting it in a new location |
Correct. |
Co-authored-by: Jørgen Schartum Dokken <[email protected]>
Co-authored-by: Jørgen Schartum Dokken <[email protected]>
Co-authored-by: Jørgen Schartum Dokken <[email protected]>
Co-authored-by: Jørgen Schartum Dokken <[email protected]>
A Collection has no ordering - Sequence is correct. Use np.inexact instead of np.floating
I've done the legwork to split la into a native and PETSc part in a manner consistent with the rest of our interface. This creates an API change https://github.com/FEniCS/dolfinx/tree/jhale/refactor-la-petsc |
Closed in favour of #3659 |
This PR adds functions that can copy data between function(s) and standard/blocked/nested PETSc Vecs. Dispatch to correct function is performed through weak typing, always duck-typing through to standard routine.
This work was based on #3648 by @jorgensd