Why my newly created Expression always returns the value 0?


54
views
0
3 months ago by
Cuiyu  
Hello, I am quite new to Fenics. I apologize if the question has been answered.

Below is my code:
class Flower1(Expression):
def eval(self,value,x):
r = 1
values = np.zeros(7)
for i in range(0,6):
theta = i*pi/6
x_i = r*cos(theta)
y_i = r*sin(theta)
values[i] = (x[0]-x_i)**2 + (x[1]-y_i)**2-r**2
values[6] = x[0]**2 + x[1]**2-4*r**2
value = values.min()

When I try to run the following:

level_set = Flower1(degree = 2)
print(level_set(4,4))

the printed value always returns 0.0 no matter at what point I try to evaluate. Any help on this? Thanks!

Community: FEniCS Project
Can you edit your question so that the code is copy-pastable into a python shell? Thanks!
written 3 months ago by Martin Genet  

1 Answer


3
3 months ago by
Use value[0] = values.min() in order to assign value to existing variable?
Thank you! It works.
written 3 months ago by Cuiyu  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »