FESTIM icon indicating copy to clipboard operation
FESTIM copied to clipboard

PointValue quantity in FESTIM2

Open RemDelaporteMathurin opened this issue 7 months ago • 7 comments

We would need the equivalent of PointValue in FESTIM2. This should be sufficient:

import festim as F

from dolfinx.geometry import bb_tree, compute_colliding_cells, compute_collisions_points

class PointValue(F.VolumeQuantity):
    def __init__(self, field, volume, x0, filename = None):
        super().__init__(field, volume, filename)
        self.x0 = x0

    def compute(self):
        u = self.field.solution
        mesh = u.function_space.mesh
        tree = bb_tree(mesh, mesh.geometry.dim)
        cell_candidates = compute_collisions_points(tree, self.x0)
        cell = compute_colliding_cells(mesh, cell_candidates, self.x0).array
        assert len(cell) > 0
        first_cell = cell[0]
        
        self.value = self.field.solution.eval(self.x0, first_cell)
        self.data.append(self.value)

RemDelaporteMathurin avatar Mar 31 '25 13:03 RemDelaporteMathurin

Will it work in parallel?

KulaginVladimir avatar Mar 31 '25 15:03 KulaginVladimir

I believe so, but I guess we can test this? That's because each cell belongs to one process

RemDelaporteMathurin avatar Mar 31 '25 15:03 RemDelaporteMathurin

ok, I ask as PointValue seems to not work in parallel in FESTIM1

KulaginVladimir avatar Mar 31 '25 15:03 KulaginVladimir

I took it from @jorgensd comment on Discourse: https://fenicsproject.discourse.group/t/how-to-evaluate-function-at-a-given-point-in-dolfinx/2526/2?u=remdelaportemathurin

RemDelaporteMathurin avatar Mar 31 '25 15:03 RemDelaporteMathurin

That will not necessarily give a unique answer (if u is discontinuous), and does not give an answer on every process. For parallel eval, some care should be taken (ie discuss what it should return in parallel). See for instance https://github.com/scientificcomputing/scifem/blob/main/examples/evaluate_function.py and the corresponding implementation

jorgensd avatar Mar 31 '25 16:03 jorgensd

Oh well I guess we can just use the scifem eval function no?

RemDelaporteMathurin avatar Mar 31 '25 17:03 RemDelaporteMathurin

One should cache some of the work in: https://github.com/scientificcomputing/scifem/blob/main/src/scifem/eval.py if you want to use it for repeated eval on a mesh that doesn’t move (static geometry)

jorgensd avatar Mar 31 '25 17:03 jorgensd