reaction term in C++ .ufl file


209
views
0
5 months ago by
Ting  
Hi all,

I have trouble to set the reaction term in the C++ .ufl file. I have a coupled PDE system of u1 and u2. They have a reaction term u1*u2 in the system, which means I'll have u1*u2*v*dx in the varational form. But it looks like .ufl do not permit this way. I can do this in python, but c++ always give the trouble. Can any one help to set this term in the c++? Thank you so much!

The code is :

# ufl file for solving the system of heat equations
# -div(D*grad u) = u*v + f_u = u*v + 4*alpha - alpha*beta*r^5
# -div(D*grad v) = -u*v + f_v = -u*v + 9*beta*r + alpha*beta*r^5

# Define the function space
space = FiniteElement("Lagrange", triangle, 1)

element = space * space
#element = MixedElement([space, space])

# Define trial and test functions
u = TrialFunction(element)
(v_1, v_2) = TestFunctions(element)
f_1 = Coefficient(space)
f_2 = Coefficient(space)

u_1, u_2 = split(u)


# Define bilinear and linear form
a = inner(grad(u_1), grad(v_1))*dx  + inner(grad(u_2), grad(v_2))*dx

L = f_1*v_1*dx + inner(u_1, u_2)*v_1*dx + f_2*v_2*dx - inner(u_1, u_2)*v_2*dx

And the error message is :

Traceback (most recent call last):
File "/usr/bin/ffc", line 9, in <module>
load_entry_point('fenics-ffc==2017.2.0', 'console_scripts', 'ffc')()
File "/usr/lib/python2.7/dist-packages/ffc/main.py", line 217, in main
resultcode = _compile_files(args, parameters, enable_profile)
File "/usr/lib/python2.7/dist-packages/ffc/main.py", line 256, in _compile_files
code_h, code_c = compile_ufl_data(ufd, prefix, parameters)
File "/usr/lib/python2.7/dist-packages/ffc/main.py", line 99, in compile_ufl_data
parameters=parameters)
File "/usr/lib/python2.7/dist-packages/ffc/compiler.py", line 143, in compile_form
prefix, parameters, jit)
File "/usr/lib/python2.7/dist-packages/ffc/compiler.py", line 185, in compile_ufl_objects
analysis = analyze_ufl_objects(ufl_objects, kind, parameters)
File "/usr/lib/python2.7/dist-packages/ffc/analysis.py", line 94, in analyze_ufl_objects
for form in forms)
File "/usr/lib/python2.7/dist-packages/ffc/analysis.py", line 94, in <genexpr>
for form in forms)
File "/usr/lib/python2.7/dist-packages/ffc/analysis.py", line 178, in _analyze_form
do_apply_restrictions=True)
File "/usr/lib/python2.7/dist-packages/ufl/algorithms/compute_form_data.py", line 388, in compute_form_data
check_form_arity(preprocessed_form, self.original_form.arguments()) # Currently testing how fast this is
File "/usr/lib/python2.7/dist-packages/ufl/algorithms/check_arities.py", line 152, in check_form_arity
check_integrand_arity(itg.integrand(), arguments)
File "/usr/lib/python2.7/dist-packages/ufl/algorithms/check_arities.py", line 145, in check_integrand_arity
args = map_expr_dag(rules, expr, compress=False)
File "/usr/lib/python2.7/dist-packages/ufl/corealg/map_dag.py", line 37, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress)
File "/usr/lib/python2.7/dist-packages/ufl/corealg/map_dag.py", line 86, in map_expr_dags
r = handlers[v._ufl_typecode_](v, *[vcache[u] for u in v.ufl_operands])
File "/usr/lib/python2.7/dist-packages/ufl/algorithms/check_arities.py", line 57, in product
raise ArityMismatch("Multiplying expressions with overlapping form argument number {0}, argument is {1}.".format(x.number(), x))
ufl.algorithms.check_arities.ArityMismatch: Multiplying expressions with overlapping form argument number 1, argument is v_1.
Community: FEniCS Project
Ok, it looks like that python do not allow inner(u_1, u_2) term. So is any one know how to deal with this kind of reaction term?
written 5 months ago by Ting  

1 Answer


3
5 months ago by
Your problem is nonlinear in u, which explain the error message. Defining u as a Coefficient and changing the formulation of your problem to a non-linear one would be enough:

# Define the function space
space = FiniteElement("Lagrange", triangle, 1)

element = space * space
#element = MixedElement([space, space])

u = Coefficient(element)
(v_1, v_2) = TestFunctions(element)
f_1 = Coefficient(space)
f_2 = Coefficient(space)

u_1, u_2 = split(u)

F = inner(grad(u_1), grad(v_1))*dx  + inner(grad(u_2), grad(v_2))*dx - (f_1*v_1*dx + inner(u_1, u_2)*v_1*dx + f_2*v_2*dx - inner(u_1, u_2)*v_2*dx)

du = TrialFunction(element)
J  = derivative(F, u, du)

Use the nonlinear-poisson demo as reference.
Please login to add an answer/comment or follow this question.

Similar posts:
Search »