Hi,
I'm trying to implement a MCA velocity profile as inlet for cerebral aneurysm and I have an error in the following piece of code:
assemble(inner(InflowExpression(),m)*ds(2), inflow_profile.vector(), boundaries)
Throws-> TypeError: cannot convert dictionary update sequence element #0 to a sequence
Can you help me to understand and resolve this issue? The complete code is bellow:
class InflowExpression(Expression):
def __init__(self):
Expression.__init__(self)
def eval(self, value, data):
value[0] = -data.normal().x()
value[1] = -data.normal().y()
value[2] = -data.normal().z()
def value_shape(self):
return (3,)
MCAtime = array([ 0., 27., 42., 58., 69., 88., 110., 130.,
136., 168., 201., 254., 274., 290., 312., 325.,
347., 365., 402., 425., 440., 491., 546., 618.,
703., 758., 828., 897., 1002.])/(75/60.0)/1000
scale = 750
#Create interpolated mean velocity in time
y1 = array([ 390. , 398.76132931, 512.65861027, 642.32628399,
710.66465257, 770.24169184, 779.00302115, 817.55287009,
877.12990937, 941.96374622, 970. , 961.2386707 ,
910.42296073, 870.12084592, 843.83685801, 794.7734139 ,
694.89425982, 714.16918429, 682.62839879, 644.07854985,
647.58308157, 589.75830816, 559.96978852, 516.16314199,
486.37462236, 474.10876133, 456.58610272, 432.05438066, 390. ])/574.211239628*scale
k = int((T+1)/max(MCAtime))
n = len(y1)
y = numpy.zeros((n-1)*k)
time = numpy.zeros((n-1)*k)
for i in range(k):
y[i*(n-1):(i+1)*(n-1)] = y1[:-1]
time[i*(n-1):(i+1)*(n-1)] = MCAtime[:-1]+i*max(MCAtime)
spline = intpol.UnivariateSpline(time,y,k=3, s=0)
#ass = spline.integral(0,max(MCAtime))/max(MCAtime)
n = 1000
x = linspace(0,max(MCAtime),n)
#plt.plot(x, spline(x))
#plt.show()
#create paraboloid profile
center = [0., 0., 0.]
# radius
r = 0.8
# Define function spaces
V = VectorFunctionSpace(mesh, "CG", 1)
Q = FunctionSpace(mesh, "CG", 1)
m = TrialFunction(V)
inflow_profile = Function(V)
boundaries = MeshFunction("size_t", mesh, "cylinder_volume9_facet_region.xml")
#########
assemble(inner(InflowExpression(),m)*ds(2), inflow_profile.vector(), boundaries)
# Throws-> TypeError: cannot convert dictionary update sequence element #0 to a sequence
#########
N = int(len(inflow_profile.vector()))
for i in range(int(N/3)):
n1 = inflow_profile.vector()[i]
n2 = inflow_profile.vector()[int(N/3)+i]
n3 = inflow_profile.vector()[int(2*N/3)+i]
norm = numpy.sqrt(n1**2+n2**2+n3**2)
if(norm > 0):
x = p.vector()[i]
y = p.vector()[N/3+i]
z = p.vector()[2*N/3+i]
d_c = sqrt((center[0]-x)**2+(center[1]-y)**2+(center[2]-z)**2)/r
inflow_profile.vector()[i] = n1/norm*(1-d_c**2)
inflow_profile.vector()[N/3+i] = n2/norm*(1-d_c**2)
inflow_profile.vector()[2*N/3+i] = n3/norm*(1-d_c**2)
#Initiate inflow parabolic profile
inflow_function = Function(inflow_profile.function_space())
inflow_function.vector()[:] = inflow_profile.vector()[:]*spline.__call__(t)
# spline._call_(t) -> 497.831552977
#Create boundary conditions for velocity
noslip = DirichletBC(V, Constant ((0,0,0)),boundaries,3)
inflow = DirichletBC(V, inflow_function, boundaries,1)
outflow = DirichletBC(Q, Constant (0), boundaries,2)
bcu = [noslip, inflow]
bcp = [outflow]
Thank you!!!