Is there an inverse of basis.interpolate()
?
#816
-
Just that... Is there an inverse of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 18 replies
-
In theory it is L2 projection, i.e. skfem.utils.projection. However, I'm still not completely happy about skfem.utils.projection. I'm working on a new version which will hopefully also be useful for this. This is what I have in mind, proj() is the new function, and has similar syntax to asm(): basis = CellBasis(mesh, ElementTriP1())
# w is like the last parameter to forms
y1 = proj(lambda w: w.x[0], basis)
# take derivative with gradient averaging
x = mesh.p[0]
y2 = proj(lambda w: w['u'].grad[0], basis, u=x)
# real derivative
y3 = proj(lambda w: w['u'].grad[0], basis.with_element(ElementTriP0()), u=basis.interpolate(x))
# inverse
y4 = proj(lambda w: w['u'], basis, u=basis.interpolate(x))
# y4 should be almost equal to x |
Beta Was this translation helpful? Give feedback.
-
Alright, to answer the original question, with the existing import numpy as np
from skfem import *
m = MeshTri()
basis = Basis(m, ElementTriP1())
x1 = m.p[0] # the function f(x) = x
x1_interp = basis.interpolate(x1)
x2 = projection(LinearForm(lambda v, w: x1_interp * v), basis)
print(np.linalg.norm(x1 - x2)) which will print |
Beta Was this translation helpful? Give feedback.
Alright, to answer the original question, with the existing
projection
it would like this:which will print
2.6766507790745728e-16
.