# Using Conditional function inside a Project function

**URL:** <https://fenicsproject.discourse.group/t/using-conditional-function-inside-a-project-function/3967>\
**Category:** Linear Algebra\
**Created:** [August 20, 2020, 6:40am UTC](https://fenicsproject.discourse.group/t/using-conditional-function-inside-a-project-function/3967 "2020-08-20T06:40:34Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [August 20, 2020, 8:15am UTC](https://fenicsproject.discourse.group/t/using-conditional-function-inside-a-project-function/3967/4 "2020-08-20T08:15:25Z")

</div>

The problem is that you try to assign a function (the result of the projection), to a float.  
The initial kappa has to be a function.  
This is illustrated in the minimal example below. Please note the following:

1. Your proposed example is not minimal, and contains alot of variables not required to reproduce the error. The example below should be used as a guideline for further inquires.
2. To represent kappa, I am using a DG space, as kappa is discontinuous. If you decide to use a CG space, you will get transfer regions at the switch of the material.

```auto
from dolfin import *
from ufl import as_tensor

kappa_s = 138.0 #conductivity [W/m K]
kappa_l = 80.0 #conductivity [W/m K]

mesh = UnitSquareMesh(10,10)

Space = FunctionSpace(mesh, 'P', 1)
T = project(Expression("x[0]+0.1*x[1]", degree=2), Space)

kappa_space = FunctionSpace(mesh, "DG", 0)
kappa = project(kappa_s,kappa_space)
kappa_s = as_tensor(kappa_s,())
kappa_l = as_tensor(kappa_l,())
Tmelting = 0.5
print(kappa.vector().get_local())
kappa.assign(project(conditional(gt(T, Tmelting), kappa_l, kappa_s), kappa_space))
print(kappa.vector().get_local())

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/using-conditional-function-inside-a-project-function/3967)._
