FESTIM
FESTIM copied to clipboard
PointValue quantity in FESTIM2
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)
Will it work in parallel?
I believe so, but I guess we can test this? That's because each cell belongs to one process
ok, I ask as PointValue seems to not work in parallel in FESTIM1
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
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
Oh well I guess we can just use the scifem eval function no?
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)