# The velocity of inflow code problem

**URL:** <https://fenicsproject.discourse.group/t/the-velocity-of-inflow-code-problem/5760>\
**Category:** Uncategorized\
**Created:** [May 7, 2021, 3:52pm UTC](https://fenicsproject.discourse.group/t/the-velocity-of-inflow-code-problem/5760 "2021-05-07T15:52:21Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [May 7, 2021, 5:15pm UTC](https://fenicsproject.discourse.group/t/the-velocity-of-inflow-code-problem/5760/2 "2021-05-07T17:15:20Z")

</div>

You could use an `UserExpression`, where you use `numpy.random` to create your random variation on each evaluation.  
See for instance:

> [@Material property depending on solution](https://fenicsproject.discourse.group/t/material-property-depending-on-solution/549/2):
>
> Hi Rem, I’m really not an expert but have you tried a UserExpression? Something like class CoeffClass(UserExpression): def \_\_init\_\_(self, temp, \*\*kwargs): super().\_\_init\_\_(kwargs) self.temp = temp def eval(self, values, x): values[0] = ... 2\*self.temp(x) ... if x[0] \> 0.5: values[1] = 1 else: ... values[1] = 0 def value\_shape(self): return () Indexing needs to match your function space dimensions,…

or

> [@Define random values through expression](https://fenicsproject.discourse.group/t/define-random-values-through-expression/1448/2):
>
> Hi, f=Expression(“g”, g=g, degree=1) should be thought of as defining f such that f(x)=g(x). In ran\_mu\_expr=Expression(“ran\_mu”,ran\_mu=ran\_mu, degree=4) you seem to make an assumption that Expression will do the lookup in ran\_mu array to assign the coefficient value appropriately. That is not the case. Consider instead from dolfin import \* import numpy as np class RandomScalar(UserExpression): def eval(self, value, x): value[:] = np.random.rand() def value\_shape(self, ): …

or

> [@Initial Conditions for mixed Element](https://fenicsproject.discourse.group/t/initial-conditions-for-mixed-element/2032/4):
>
> Hello, I’m trying to solve a different problem: I have a poromechanic Material and I’m pulling on the right side. I’m not sure, if my implementation of the initial Condition is correct, because I define, that the pressure at p0 = 10000 but the pressure of my next time step is in a range from 0 (because of my boundary Condition) to -100. I dont understand the big difference between t0 and t1. Is there a mistake in my implementation? Or do I have to implement an initial pressure differently? …

---

_[View the full topic](https://fenicsproject.discourse.group/t/the-velocity-of-inflow-code-problem/5760)._
