-
-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redesign function/expression interpolation #161
Comments
Usecase of "pointwise" expression (expression evaluated at quadrature points) could be handled
|
Consider also FEniCS/ffcx#33. |
To support the point 2.ii, here is simple demonstration of TSFC expression kernel generation. (sidenote: merged in one python file just for brevity) import cffi
import importlib
import numpy as np
import ufl
import tsfc
el = ufl.FiniteElement("P", "triangle", 1)
u = ufl.Coefficient(el)
a = ufl.exp(u) + u
cexp = tsfc.compile_expression_at_points(a, [[1.0, 0]], a)
CODE_C = cexp[0].gencode()
CODE_H = """
static inline void expression_kernel (double *restrict A, const double *restrict w_0);
"""
ffi = cffi.FFI()
ffi.set_source("interpolator", CODE_C)
ffi.cdef(CODE_H)
ffi.compile()
from interpolator.lib import expression_kernel
# Target scalar value
A = np.array([0.0])
# Cell-local expansion coeffs of function
coeffs = np.array([1.0, 1.0, 1.0])
pA = ffi.cast("double *", A.ctypes.data)
pcoeffs = ffi.cast("double *", coeffs.ctypes.data)
expression_kernel(pA, pcoeffs)
print(A) It evaluates expression From the current implementation of interpolation in Firedrake, it is evident that only |
Fixed by an number of PRs. |
Generally, there is a need for "interpolation" when
(in all cases I assume the action of target FE space dual basis on donor object is well defined)
object being interpolated is a FE function
Typical IO postprocessing, P_k -> P_1
Error norm computation, coarsening, refining
object being interpolated is a blackbox
C++ compiled expression
Source term preparation, method of manufactured solutions, ...
UFL expression
E.g. Scalar function computed as trace of some other tensor FE function, various internal variables updates (ODE solved explicitly), grid transfer operators in multigrid, evaluation of handcoded gradients, ... Reference to older discussion, https://bitbucket.org/fenics-project/dolfin/issues/422/allow-arbitrary-ufl-expressions-passed-to
Other custom class complying to an interface.
This would allow e.g. local newton solver be interpolated to FE function, think of return mapping in plasticity, local nonlinear system for chemical reactions, ...
Ideas how to handle:
generate cell-local interpolation matrix at compile time
generate interpolation kernel on a symbolic level - at runtime takes geometric information as pushforwards, pullbacks
generate interpolation kernel on a symbolic level - at runtime takes geometric information as point where to evaluate
generate interpolation kernel on a symbolic level - at runtime takes geometric information as pushforwards, pullbacks, point where to evaluate
Check how this works in TSFC. Possibly employ TSFC.
generate
evaluate_dof
which runs.eval
of the blackbox.The main difference between 1. and 2. is existence of underlying basis, linear and nodal structure.
The text was updated successfully, but these errors were encountered: