I would like to implement a crosswind stabilization using the next formula attached and I get AssertionError and I don’t know the reason.
from dolfin import *
import numpy as np
mesh=UnitSquareMesh(32,32)
V_c = FunctionSpace(mesh, "P", 1)
V_u = VectorFunctionSpace(mesh, "P", 2)
# boundary condition
betta=Constant(-0.004)
bc_bt= DirichletBC(V_c, Constant(0.0004), "near(x[0], 1.0) and on_boundary")
bc= [ bc_bt]
# Create velocity Function
u=interpolate(Expression(("vmag*cos(theta)*x[0]","vmag*sin(theta)*x[1]"),domain=mesh, degree=1, theta=pi/6, vmag=3.5), V_u)
# Test and trial functio
v = TestFunction(V_c)
c = TrialFunction(V_c)
c_k = interpolate(Constant(0.0),V_c) # initial guess
# Mesh-related functions
n = FacetNormal(mesh)
h = CellDiameter(mesh)
h_avg = (h('+') + h('-'))/2
diff=Constant(1.2e-5)
# Source term
f = Constant(0.0)
#STABILIZATION CROSSWIND TERMS
alpha=Constant(0.5)
I= Identity(mesh.geometry().dim())
def q(c):
return (sqrt(dot(dot(u,grad(c)),dot(u,grad(c))))/sqrt(dot(grad(c),grad(c))))
# Define variational problem for Picard iteration
# Galerkin variational problem
F= (diff*dot(grad(c),grad(v))+inner(u,grad(c))*v)*dx+(betta*c*v)*ds-f*v*dx
# Add crosswind stabilization terms
CWD=(I-(outer(u,u)/sqrt(dot(dot(u,u),dot(u,u)))))
F += dot(dot(0.5*alpha*h_avg*q(c_k)*grad(c),CWD),grad(v))*dx
# Create bilinear and linear forms
a = lhs(F)
L = rhs(F)
# Picard iterations
c = Function(V_c) # new unknown function
eps = 1.0 # error measure ||u-u_k||
tol = 1.0E-5 # tolerance
iter = 0 # iteration counter
maxiter = 25 # max no of iterations allowed
while eps > tol and iter < maxiter:
iter += 1
solve(a == L, c, bc)
diff = c.vector().get_local() - c_k.vector().get_local()
eps = np.linalg.norm(diff, ord=np.Inf)
c_k.assign(c) # update for next iteration
I have the problem when i try to solve the system, I think that it is beacuse there are some mistake in the crosswind stabilization when I introduce the terms but I dont know where
AssertionError Traceback (most recent call last)
<ipython-input-8-fb3f7f1fa4e7> in <module>
8 while eps > tol and iter < maxiter:
9 iter += 1
---> 10 solve(a == L, c, bc)
11 diff = c.vector().get_local() - c_k.vector().get_local()
12 eps = np.linalg.norm(diff, ord=np.Inf)
...
~/anaconda3/envs/fenics/lib/python3.8/site-packages/ffc/uflacs/analysis/balancing.py in balance_modified_terminal(expr)
52 layers = [expr]
53 while not expr._ufl_is_terminal_:
---> 54 assert expr._ufl_is_terminal_modifier_
55 expr = expr.ufl_operands[0]
56 layers.append(expr)
AssertionError: