Problems when I integrate conditional values

5 months ago by

Gents, I am sorry for bugging again! I use the 2016.0 FEniCS version

# Libraries import
from fenics import *
import time
import mshr
import ufl
import os
from math import floor, ceil
get_ipython().magic('matplotlib inline')
print dolfin.dolfin_version()
ufl.algorithms.apply_derivatives.CONDITIONAL_WORKAROUND = True
parameters["form_compiler"]["representation"] = "uflacs"

Vc = VectorFunctionSpace(mesh,"CG",2)
R = VectorFunctionSpace(mesh,"R",0,dim=2)

position = Function(Vc)
position.assign(Expression(["x[0]","x[1]"], element=Vc.ufl_element()))
c = TestFunction(R)

centroid = assemble(conditional(ge(l,0.5),dot(c,position),0.0)*dx)

and I am facing the following error

True value of Condtional should only be one function: {((0, 'j', 2, 2),): '(FE3_C0[ip][j]*F1 + FE3_C1[ip][j]*F2)'}

RuntimeErrorTraceback (most recent call last)
<ipython-input-16-918ca1ab25a7> in <module>()
     24         # Center of mass
     25         volume = assemble(conditional(ge(l,0.5),Constant(1.0),0.0)*dx)
---> 26         centroid = assemble(conditional(ge(l,0.5),dot(c,position),0.0)*dx)
     27         centroid /= volume
     28         xc = centroid[0][0]; yc = centroid[1][0]

At first I thought the command 'ufl.algorithms.apply_derivatives.CONDITIONAL_WORKAROUND = True' would fix the problem, but now I am out of ideas.
Thanks for all!

Community: FEniCS Project
can you post a minimal (non-) working example?
written 5 months ago by Hernán Mella  

1 Answer

5 months ago by
I had to change a few things to get the code snippet running with 2017.2, but ended up with the more informative error message

ArityMismatch: Conditional subexpressions with non-matching form arguments​

This indicates that the main problem is:  one branch of the conditional involves a test function (c), while the other does not.  Thus the assemble() routine does not know whether it is assembling an RHS vector (i.e., known stuff times a test function times dx) or a scalar (known stuff times dx).  One fix would be something like

centroid = assemble(conditional(ge(l,0.5),dot(c,position),Constant(0.0)*dot(c,position))*dx)​

if a vector with entries corresponding to position dotted with each test function in R is desired.  However, the correct solution depends on what exactly you are computing. 

Please login to add an answer/comment or follow this question.

Similar posts:
Search »