Hi,
Using dolfin-2019.1. Here is the relevant code excerpt:
import dolfin as dlf
DT = dlf.Constant(1e-4) # time step
MU1 = dlf.Constant(1.0e-3) # dummy dynamic viscosity value
RHO1 = dlf.Constant(917) # density
G = dlf.Constant((0, -9.81))
# 2D rectangular channel mesh ----------
mesh = dlf.RectangleMesh(dlf.Point(0, 0), dlf.Point(0.5, 2.0), 10, 40, 'right')
n = dlf.FacetNormal(mesh)
# function spaces ----------------------
V = dlf.VectorFunctionSpace(mesh, 'DG', 1)
Q = dlf.FunctionSpace(mesh, 'CG', 2)
# trial and test functions
u = dlf.TrialFunction(V) # phase velocity trial function
v = dlf.TestFunction(V)
jump_v = v('+') - v('-')
p = dlf.TrialFunction(Q) # shared pressure field for both phases
vf = dlf.TrialFunction(Q) # phase volume fraction trial function
q = dlf.TestFunction(Q)
u1_o = dlf.Function(V); u1_o.assign(dlf.Constant((0, 1.0)))
u1_tld = dlf.Function(V); u1_tld.assign(dlf.Constant((0, 1.0)))
u1_str = dlf.Function(V); u1_str.assign(dlf.Constant((0, 1.0)))
u_r_tld = u1_tld - u0_tld
# pressures
p_o = dlf.Function(Q); p_o.assign(dlf.Constant(0.0))
p_tnt = dlf.Function(Q); p_tnt.assign(dlf.Constant(0.0))
p_str = dlf.Function(Q); p_str.assign(dlf.Constant(0.0))
delta_p = dlf.Function(Q); delta_p.assign(dlf.Constant(0.0))
# volume fractions
vf0_o = dlf.Function(Q); vf0_o.assign(dlf.Constant(0.95))
vf0_tld = dlf.Function(Q); vf0_tld.assign(dlf.Constant(0.95))
vf0_tnt = dlf.Function(Q); vf0_tnt.assign(dlf.Constant(0.95))
#
vf1_o = dlf.Function(Q); vf1_o.assign(dlf.Constant(0.05))
vf1_tld = dlf.Function(Q); vf1_tld.assign(dlf.Constant(0.05))
vf1_tnt = dlf.Function(Q); vf1_tnt.assign(dlf.Constant(0.05))
# continuity equation of phase 1
#
N1 = (1/DT) * dlf.inner(q, vf - vf1_o) * dlf.dx
#
c_C1 = vf1_tld * dlf.inner(u1_tld, dlf.grad(q)) * dlf.dx
#
# volume fractions surface integrals,
# OMITTING THE - LIKE C0 & C1, TO ACCOUNT FOR IT IN THE EQNS
#
r1 = dlf.inner(vf1_tld, q) * dlf.dot(u1_tld, n) * dlf.ds
r0 = dlf.inner(vf0_tld, q) * dlf.dot(u0_tld, n) * dlf.ds
#
cont1 = N1 - c_C1 + r1
c_lhs1 = dlf.lhs(cont1)
c_rhs1 = dlf.rhs(cont1)
dlf.solve(c_lhs1 == c_rhs1, vf1_tnt, dbcvf1)
vf1_tld = THETA_NL * vf1_tnt + (1 - THETA_NL) * vf1_o
# velocity prediction
#
# discrete phase (1)
u_n_1 = 0.5 * (dlf.dot(u1_tld, n) + abs(dlf.dot(u1_tld, n)))
gradu_n_1 = 0.5 * (dlf.dot(dlf.grad(u1_tld), n)
+ abs(dlf.dot(dlf.grad(u1_tld), n)))
#
M1 = (RHO1 * vf1_tld / DT) * dlf.inner(v, u - u1_o) * dlf.dx
#
jump_A1 = dlf.inner(u_n_1('+') * u('+') - u_n_1('-') * u('-'), jump_v) \
* vf1_tld * RHO1 * dlf.dS
A1 = - RHO1 * vf1_tld * dlf.inner(dlf.grad(v) * u1_tld, u) * dlf.dx \
- dlf.div(vf1_tld * RHO1 * u1_tld) * dlf.inner(v, u) * dlf.dx \
+ vf1_tld * RHO1 * dlf.dot(n, u1_tld) * dlf.inner(v, u) * dlf.ds
#
jump_K1 = dlf.inner(gradu_n_1('+') - gradu_n_1('-'), jump_v) \
* vf1_tld * MU1 * dlf.dS
K1 = vf1_tld * MU1 * dlf.inner(dlf.grad(v), dlf.grad(u)) * dlf.dx \
- vf1_tld * MU1 * dlf.inner(dlf.dot(n, dlf.grad(u1_tld)), v) * dlf.ds
#
F1 = 0.75 * C * vf1_tld * vf0_tld * RHO0 * dlf.inner(v, u) \
* dlf.sqrt (dlf.dot(u_r_tld, u_r_tld)) * dlf.dx
#
# C1 = - C1 from paper to avoid bad operand type for unary error
# ADD THE - BACK IN THE pred1 FORM BELOW
C1 = vf1_tld * dlf.inner(v, dlf.grad(p_str)) * dlf.dx
#
b1 = vf1_tld * RHO1 *dlf.inner(G, v) * dlf.dx
#
f1 = 0.75 * C * vf1_tld * vf0_tld * RHO0 * dlf.inner(v, u0_tld) \
* dlf.sqrt(dlf.dot(u_r_tld, u_r_tld)) * dlf.dx
#
pred1 = M1 + A1 + jump_A1 + K1 + jump_K1 + F1 + C1 - b1 - f1
lhs1 = dlf.lhs(pred1)
rhs1 = dlf.rhs(pred1)
dlf.solve(lhs1 == rhs1, u1_str, dbcu)
At the last line I get the error below where a scalar is expected somewhere in pred1
and I cannot figure out where it comes from. Anyone can help?
python3 two_phase_FEM.py
created mesh with 800 cells and 451 vertices
Solving linear variational problem.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Expecting scalar.
Traceback (most recent call last):
File "two_phase_FEM.py", line 165, in <module>
dlf.solve(lhs1 == rhs1, u1_str, dbcu)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/dolfin/fem/solving.py", line 220, in solve
_solve_varproblem(*args, **kwargs)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/dolfin/fem/solving.py", line 242, in _solve_varproblem
form_compiler_parameters=form_compiler_parameters)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/dolfin/fem/problem.py", line 55, in __init__
L = Form(L, form_compiler_parameters=form_compiler_parameters)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/dolfin/fem/form.py", line 44, in __init__
mpi_comm=mesh.mpi_comm())
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/dolfin/jit/jit.py", line 47, in mpi_jit
return local_jit(*args, **kwargs)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/dolfin/jit/jit.py", line 97, in ffc_jit
return ffc.jit(ufl_form, parameters=p)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/jitcompiler.py", line 217, in jit
module = jit_build(ufl_object, module_name, parameters)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/jitcompiler.py", line 133, in jit_build
generate=jit_generate)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/dijitso/jit.py", line 165, in jit
header, source, dependencies = generate(jitable, name, signature, params["generator"])
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/jitcompiler.py", line 66, in jit_generate
prefix=module_name, parameters=parameters, jit=True)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/compiler.py", line 143, in compile_form
prefix, parameters, jit)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/compiler.py", line 190, in compile_ufl_objects
ir = compute_ir(analysis, prefix, parameters, jit)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/representation.py", line 183, in compute_ir
for (form_id, fd) in enumerate(form_datas)]
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/representation.py", line 183, in <listcomp>
for (form_id, fd) in enumerate(form_datas)]
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/representation.py", line 460, in _compute_integral_ir
parameters)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/uflacs/uflacsrepresentation.py", line 139, in compute_integral_ir
parameters)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/uflacs/build_uflacs_ir.py", line 338, in build_uflacs_ir
V, V_deps, V_targets = build_scalar_graph(expressions)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/uflacs/build_uflacs_ir.py", line 823, in build_scalar_graph
scalar_expressions = rebuild_with_scalar_subexpressions(G)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/uflacs/analysis/graph_rebuild.py", line 276, in rebuild_with_scalar_subexpressions
ws = reconstruct_scalar_subexpressions(v, wops)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ufl/corealg/multifunction.py", line 100, in __call__
return self._handlers[o._ufl_typecode_](o, *args)
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ffc/uflacs/analysis/graph_rebuild.py", line 62, in scalar_nary
error("Expecting scalar.")
File "<string>", line 1, in <lambda>
File "/home/zbinkz/HGST/Projects/Python/FEniCS-p3/lib/python3.7/site-packages/ufl/log.py", line 172, in error
raise self._exception_type(self._format_raw(*message))
Exception: Expecting scalar.