Function evaluation fails after scaling mesh


69
views
0
6 weeks ago by
I'm trying to scale a mesh and to evaluate a function defined on this mesh at a point. Visualization of the function after scaling is correct but evaluating it at a point fails. The following code demonstrates the problem.
from fenics import *
import matplotlib.pyplot as plt

# Create a function
mesh = RectangleMesh(Point(0.0, 0.0), Point(2.0, 1.0), 20, 10)
V = FunctionSpace(mesh, "Lagrange", 1)
func = project(Expression("x[0]+x[1]",degree=1), V)

# Plot
plot(func)

# Evaluate function
print("Function value at (1,0.5) = " + str(func(1.,0.5)))

# Rescale mesh
mesh.scale(2.)

# Plot
plt.figure()
plot(func) 
plt.show()

# Evaluate fails!
try:
    print("Function value at (2,1) = " + str(func(2.,1.)))
except:
    print("Function evaluation has failed! Exiting")​

Any ideas what am I doing wrong or how can I fix the issue?

Thank you in advance!
Community: FEniCS Project

1 Answer


4
6 weeks ago by
Clear the cached bounding box tree

mesh.bounding_box_tree().build(mesh)​
Thank you! It solves the problem
written 6 weeks ago by printsg  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »