# UFL conditions cannot be evaluated as bool in a Python context -error message

**URL:** <https://fenicsproject.discourse.group/t/ufl-conditions-cannot-be-evaluated-as-bool-in-a-python-context-error-message/3431>\
**Category:** mesh\
**Created:** [June 4, 2020, 1:45pm UTC](https://fenicsproject.discourse.group/t/ufl-conditions-cannot-be-evaluated-as-bool-in-a-python-context-error-message/3431 "2020-06-04T13:45:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sambeet\_Panigrahi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sambeet_panigrahi/32/1259_2.png) [@Sambeet\_Panigrahi](https://fenicsproject.discourse.group/u/Sambeet_Panigrahi)\
**Post date:** [June 4, 2020, 1:45pm UTC](https://fenicsproject.discourse.group/t/ufl-conditions-cannot-be-evaluated-as-bool-in-a-python-context-error-message/3431/1 "2020-06-04T13:45:48Z")

</div>

I have written the following codes for generating a 3D Cylindrical mesh.  
from fenics import \*  
from mshr import \*  
from math import \*  
from dolfin import \*  
# Create Geometry  
Rair = 5  
cyltot = Cylinder(Point(0,0,10),Point(0,0,0),Rair,Rair)  
mesh\_tot = generate\_mesh(cyltot,64)  
vtkfile = File(‘Mesh.pvd’)  
vtkfile \<\< mesh\_tot  
V = FunctionSpace(mesh\_tot,‘P’,1)

```
# Finding Subdomains
rho = Expression('sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2])',degree=2)

tol = 1E-14
class Copper(SubDomain):
    def inside(self, x, on_boundary):
        return rho <= 1 + tol

    
class Air(SubDomain):
    def inside(self, x, on_boundary):
        return rho >= 1 - tol
    

materials = MeshFunction('size_t',mesh_tot,mesh_tot.topology().dim())
Subdom_cu = Copper()
Subdom_air = Air()
materials.set_all(2)
Subdom_air.mark(materials, 3)

import matplotlib.pyplot as plt
plot(materials)
plt.show()

```

After running the above,I get the following error

> UFL conditions cannot be evaluated as bool in a Python context.  
> Traceback (most recent call last):  
> File “/home/fenics/shared/Cylinder/cylinder.py”, line 34, in   
> Subdom\_air.mark(materials, 3)  
> RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)

Can somebody help me in understanding what is the error here and point me towards a solution?

---

<div class="post-metadata">

**Author:** ![Sambeet\_Panigrahi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sambeet_panigrahi/32/1259_2.png) [@Sambeet\_Panigrahi](https://fenicsproject.discourse.group/u/Sambeet_Panigrahi)\
**Post date:** [June 4, 2020, 2:53pm UTC](https://fenicsproject.discourse.group/t/ufl-conditions-cannot-be-evaluated-as-bool-in-a-python-context-error-message/3431/2 "2020-06-04T14:53:47Z")

</div>

I just went through a few posts [this](https://fenicsproject.org/qa/5630/subdomains-in-3d/) and came to know that subdomains in 3D are not yet supported.If this is the problem in the above problem, can someone please suggest a workaround?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 4, 2020, 2:56pm UTC](https://fenicsproject.discourse.group/t/ufl-conditions-cannot-be-evaluated-as-bool-in-a-python-context-error-message/3431/3 "2020-06-04T14:56:12Z")

</div>

You should do:

```auto
import numpy as np
tol = 1E-14
class Copper(SubDomain):
    def inside(self, x, on_boundary):
        return np.sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]) <= 1 + tol

    
class Air(SubDomain):
    def inside(self, x, on_boundary):
        return np.sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]) >= 1 - tol
    

```

as you need to use the input coordinates in the inside function
