evaluating all trial functions at a handful of points

4 months ago by
Given a FunctionSpace `V`, `V.dim()==n`, I need to evaluate all `n` trial functions at a handful (`m`) of points and build a sparse `m`-by-`n` matrix from it. (I can then use that matrix to evaluate any linear combination of trial functions at those points.)

Any hint on how to do this?
Community: FEniCS Project
I remember seeing something possibly-similar to this in a library for inverse problems:  You might be able to re-purpose parts of hIPPYlib's "pointwise observation" functionality.  See the Python file


and the associated C++ files


for the extension module.
written 4 months ago by David Kamensky  
Yup, that's what I'm looking for. A lot of code for such a simple thing unfortunately...
written 4 months ago by Nico Schlömer  

3 Answers

4 months ago by
Alright, I think I've got it now. You'll first have to find the cell in which the point sits (using BoundingBoxTree), and once you've got that, it's simply a matter of calling evaluate_basis_all and get_vertex_coordinates:

bbt = BoundingBoxTree()
dofmap = self.V.dofmap()
el = self.V.element()
for xy in centers:
    cell_id = bbt.compute_first_entity_collision(Point(*xy))
    cell = Cell(mesh, cell_id)
    coordinate_dofs = cell.get_vertex_coordinates()

    v = numpy.zeros(1, dtype=float)
        v, xy, coordinate_dofs, cell_id

dolfinx is 'vectorising' many of these functions in the NumPy sense, which will make to much more efficient when calling them from Python.
written 4 months ago by Garth Wells  
4 months ago by
See the function FiniteElement::evaluate_basis_all.
Sounds promising. Is there any documentation on the arguments? Also, do I assume correctly that I'll first have to extract the cell_id of the cell in which the point sits using BoundingBoxTree?
written 4 months ago by Nico Schlömer  
Never mind, I think I got it now. Thanks for the pointer, this is exactly what I needed.
written 4 months ago by Nico Schlömer  
4 months ago by
Hi Nico,

I had a hard time making out what you meant by your question. Is it that you have a function space V over a mesh that naturally allows n nodes, and you wish to evaluate "a" trial function defined over that space V, only on a subset of those nodes, (say) m points in all? If so, I believe that you need to have a function space that admits just those m points, and interpolate (or project your trial function to that space. But I admit, this reply is kind of groping in the dark.

What do you mean by making a matrix mxn. Do you have a form, that needs to be assembled? Some details might probably help.

Not $n$ nodes, $n$ degrees of freedom; $V.dim()==n$. I want to evaluate all basis functions at a few (let's say one) particular point. That point is no necessarily a node in mesh.
written 4 months ago by Nico Schlömer  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »