cell_markers definition based on function.


262
views
0
8 months ago by
Hi, I want to define cell_markers for the adaptive refinement based in the function. For that I have done like this..
from dolfin import *
mesh = UnitSquareMesh(10,10)
W = VectorFunctionSpace(mesh,'CG',1)
#u , v = TrialFunction(W), TestFunction(W)
lmbda = 121.15e3
mu = 85.77e3
def en_dens(u):    
    str_ele = sym(grad(u))
    IC = tr(str_ele)
    ICC = tr(str_ele * str_ele)
    return (0.5*lmbda*IC**2) + mu*ICC
u = Function(W)
cell_markers = MeshFunction('bool', mesh)
cell_markers.set_all(False)
for cell in cells(mesh):
    pp = cell.midpoint()
    if en_dens(u(pp)) >= 10.0:
        cell_markers.set(cell,True)​

But I am getting Error: Invalid type conversion: <type 'numpy.ndarray'> can not be converted to any UFL type.
The representation of the object is:
array([ 0., 0.]). How to resolve this issue.
Thanks for the help
HSK

Community: FEniCS Project

1 Answer


1
8 months ago by
$\texttt{u(pp)}$u(pp) returns a numpy array which then gets thrown into the  $\texttt{grad}$grad  operator. Grad can only operate on functions. A quick solution could be
from dolfin import *
mesh = UnitSquareMesh(10,10)
W = VectorFunctionSpace(mesh,'CG',1)
V = FunctionSpace(mesh, 'CG',1)

lmbda = 121.15e3
mu = 85.77e3

u = Function(W)
str_ele = sym(grad(u))
IC = tr(str_ele)
ICC = tr(str_ele * str_ele)
evalFun = project(((0.5*lmbda*IC**2) + mu*ICC), V)

cell_markers = MeshFunction('bool', mesh)
cell_markers.set_all(False)
for cell in cells(mesh):
    pp = cell.midpoint()
    if evalFun(pp) >= 10.0:
        cell_markers.set(cell,True)​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »