aa2884
July 20, 2023, 10:53am
1
After solving for my function, u, I can evaluate the solution at a point Point(x,y,z) using the line of code
u(Point(x,y,z)). If I want to evaluate the gradient operator of my solution at Point (x,y,z) what is the best way to do so?
dokken
July 20, 2023, 11:13am
2
In legacy dolfin:
Project the gradient into a suitable space and use point evaluation.
See:
OK. That was fast and easy once I wrote the question.
I just used
gu=grad(u)
Gu=dolfin.project(gu)
Gu(Point(0,0))
In Dolfinx you can use the Expression
class.
return _cpp.fem.create_expression_complex64
elif dtype is np.complex128:
return _cpp.fem.create_expression_complex128
else:
raise NotImplementedError(f"Type {dtype} not supported.")
ffi = module.ffi
self._cpp_object = create_expression(dtype)(ffi.cast("uintptr_t", ffi.addressof(self._ufcx_expression)),
coeffs, constants, mesh, self.argument_function_space)
def eval(self, cells: np.ndarray, values: typing.Optional[np.ndarray] = None) -> np.ndarray:
"""Evaluate Expression in cells. Values should have shape
(cells.shape[0], num_points * value_size * num_all_argument_dofs).
If values is not passed then a new array will be allocated.
"""
_cells = np.asarray(cells, dtype=np.int32)
if self.argument_function_space is None:
argument_space_dimension = 1
else:
argument_space_dimension = self.argument_function_space.element.space_dimension
1 Like
aa2884
July 21, 2023, 4:17pm
3
Great, thanks for your help once again it is really appreciated!