A projection is simply solving
\int_\Omega u \cdot v ~\mathrm{d}x = \int_\Omega f \cdot v ~\mathrm{d} x
which is easy to implement in DOLFINx:
project is just syntactic sugar. The projection f_h of a function f onto the space V is found by computing the problem: find f_h \in V such that
(f_h, v) = (f, v) \quad \forall v \in V.
This is very easy to set up. See for example @michalhabera 's implementation in dolfiny: dolfiny/projection.py at master · michalhabera/dolfiny · GitHub .
The problem with the project syntax is the uninformed user will assume it will handle many esoteric cases. For example, incomplete data in f, singular comp…
For projection, you can consider the approach taken in dolfiny by either copying this approach or installing this convenience library.
Also it is beneficial to have a look at:
Finally, I have made a minimal example highlighting the combination of these operations:
import dolfinx
import dolfinx.io
import ufl
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np
mesh = dolfinx.UnitSquareMesh(MPI.COMM_WORLD, 5,5, dolfinx.cpp.mesh.CellType.quadrilateral)
num_cells_local = mesh.t…
A more scalable approach than the route taken in DOLFINy is to create a projector class, that caches the mass matrix, so that you do not have to re-assemble (and refactorize in the case of LU) if you use it multiple times).
For the quadrature points (in physical space), consider the first bit of: Numerical values from ufl.SpatialCoordinate - #2 by dokken