# Linearity of solution dependent property

**URL:** <https://fenicsproject.discourse.group/t/linearity-of-solution-dependent-property/5719>\
**Category:** Linear Algebra\
**Created:** [May 2, 2021, 7:00pm UTC](https://fenicsproject.discourse.group/t/linearity-of-solution-dependent-property/5719 "2021-05-02T19:00:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dengcy](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dengcy/32/2460_2.png) [@dengcy](https://fenicsproject.discourse.group/u/dengcy)\
**Post date:** [May 2, 2021, 7:01pm UTC](https://fenicsproject.discourse.group/t/linearity-of-solution-dependent-property/5719/1 "2021-05-02T19:01:00Z")

</div>

Hi, I am working on a problem with solution dependent property, for instance k(u)\frac{du}{dt}=\frac{d^2u}{dx^2}. I am wondering how to implement it. I saw some posts giving almost the same solution: define `u=Function(V)`, and then define `k` as an expression such as `k=Expression('u+1',u=u,degree=2)`. I am confused by this implementation, since it is treating each time step as a non-linear problem (linear problem defines `TrialFunction` first). It looks to me that `Expression` freezes `k(u)` at each time step based on the solution of `u` in the previous step, thus we are solving a linear problem at each time step. Why in all examples (e.g. [Material property depending on solution](https://fenicsproject.discourse.group/t/material-property-depending-on-solution/549)) we do not define `u=TrialFunction(V)`?

I tried `u=TrialFunction(V)` and `k=Expression('u+1',u=u,degree=2)`. It reports error, so it seems `Expression` does not input `TrialFunction`. Is it designed on purpose?

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [May 2, 2021, 7:42pm UTC](https://fenicsproject.discourse.group/t/linearity-of-solution-dependent-property/5719/2 "2021-05-02T19:42:54Z")

</div>

Perhaps look at the [nonlinear Poisson demo](https://fenicsproject.org/olddocs/dolfin/latest/python/demos/nonlinear-poisson/demo_nonlinear-poisson.py.html) as a guide.

---

<div class="post-metadata">

**Author:** ![dengcy](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dengcy/32/2460_2.png) [@dengcy](https://fenicsproject.discourse.group/u/dengcy)\
**Post date:** [May 2, 2021, 11:22pm UTC](https://fenicsproject.discourse.group/t/linearity-of-solution-dependent-property/5719/3 "2021-05-02T23:22:05Z")

</div>

Thanks for your reply. I have read the demo. The demo expresses `k(u)=u **2` directly without an `Expression`. I can understand that the demo is a non-linear case since `u** 2` is computed in Jacobian. I will need a conditional expression (e.g.,`u>1?u+1:u+2`) so I do not think I can use a simple form.

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [May 2, 2021, 11:38pm UTC](https://fenicsproject.discourse.group/t/linearity-of-solution-dependent-property/5719/4 "2021-05-02T23:38:53Z")

</div>

Why not? Your conditional is piecewise gateaux differentiable.

If you don’t want to use Newton’s method you could look into Picard iteration. E.g. the Navier Stokes demo.

---

<div class="post-metadata">

**Author:** ![dengcy](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dengcy/32/2460_2.png) [@dengcy](https://fenicsproject.discourse.group/u/dengcy)\
**Post date:** [May 3, 2021, 12:02am UTC](https://fenicsproject.discourse.group/t/linearity-of-solution-dependent-property/5719/5 "2021-05-03T00:02:03Z")

</div>

Thanks again for your reply. How to express the conditional expression in the variational form?

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [May 3, 2021, 12:07am UTC](https://fenicsproject.discourse.group/t/linearity-of-solution-dependent-property/5719/6 "2021-05-03T00:07:38Z")

</div>

Check [the documentation](https://fenics.readthedocs.io/projects/ufl/en/latest/manual/form_language.html#conditional-operators).

E.g.

```auto
from dolfin import *

mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh,"DG",0)
x = SpatialCoordinate(mesh)
f0 = conditional(lt(x[0], 0.5), 1.0, 0.0)

```

![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/2/2e90c629468ef7c8f7b8fbf194d6b6bce2aa992e.png)
