# Function in pyfr

**URL:** <https://pyfr.discourse.group/t/function-in-pyfr/593>\
**Category:** General\
**Created:** [29 April 2022 14:47 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593 "2022-04-29T14:47:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [29 April 2022 14:47 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/1 "2022-04-29T14:47:00Z")

</div>

Hello,  
I know square root is sqrt(). Can I use function such like triple root in ini. file? I use pow(x, 1/3), it is wrong.

![TR_WS00A12QTM}1T7T$QACH](https://global.discourse-cdn.com/free1/uploads/pyfr/original/1X/178932ecae096da08cd7857bd857ca8578ea8156.png)

Thanks

---

<div class="post-metadata">

**Author:** ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)\
**Post date:** [29 April 2022 15:59 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/2 "2022-04-29T15:59:50Z")

</div>

`pow(x, 1/3)` is fine and I assure you that it works.

Regards, Freddie.

---

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [1 May 2022 02:56 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/3 "2022-05-01T02:56:29Z")

</div>

Yes, pow(x,1/3) is fine, but when I use pow(pow(x,1/3), 1/2) in integrate plugin, the result is Nah…

Also, I want to use temperature T in integrate plugin, is it possible?

Thanks

---

<div class="post-metadata">

**Author:** ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)\
**Post date:** [1 May 2022 13:05 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/4 "2022-05-01T13:05:35Z")

</div>

`pow(pow(x, 1/3), 1/2)` will work fine also, but will of course deliver a NaN if `x < 0`. You can also simplify the two `pow` calls into a single expression.

The temperature can be computed through the ideal gas law.

Regards, Freddie.

---

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [5 May 2022 02:29 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/5 "2022-05-05T02:29:22Z")

</div>

OK，thanks.

I missed something. I need to set the mu as mu=kT at every soultion point and flux point, k is constant, T is temperature at the solution point or flux point.

Is it possible?

Regards

---

<div class="post-metadata">

**Author:** ![WillT](https://avatars.discourse-cdn.com/v4/letter/w/bc79bd/32.png) [@WillT](https://pyfr.discourse.group/u/WillT)\
**Post date:** [5 May 2022 07:41 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/6 "2022-05-05T07:41:59Z")

</div>

Yep, you will need to change how mu is set in the viscous flux function here: [PyFR/flux.mako at d175beccd3fc5587903cc00c0f401041ff22abe4 · PyFR/PyFR · GitHub](https://github.com/PyFR/PyFR/blob/d175beccd3fc5587903cc00c0f401041ff22abe4/pyfr/solvers/navstokes/kernels/flux.mako)

To pass the constant `k` to the function, you can define it in the constants section of the ini file and then use it from the dictionary `c` in the mako file i.e. `mu_c = ${c['k']}*T`. Where you will need to define the temperature as well.

---

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [7 May 2022 12:19 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/7 "2022-05-07T12:19:17Z")

</div>

Thanks for your replay.  
Can Pyfr simulate 2D linear convection-diffusion equation?  
such as :  
 ![image](https://global.discourse-cdn.com/free1/uploads/pyfr/original/1X/bfea473b22400719dfa388f9aa6fdb3d141e6fe8.png)

Thanks

---

<div class="post-metadata">

**Author:** ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)\
**Post date:** [7 May 2022 14:15 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/8 "2022-05-07T14:15:09Z")

</div>

No, however you should be able to add a solver into PyFR for solving this problem without too much issue.

Regards, Freddie.

---

<div class="post-metadata">

**Author:** ![WillT](https://avatars.discourse-cdn.com/v4/letter/w/bc79bd/32.png) [@WillT](https://pyfr.discourse.group/u/WillT)\
**Post date:** [9 May 2022 07:49 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/9 "2022-05-09T07:49:54Z")

</div>

I implemented most of what you need on a slightly older version of PyFR. [GitHub - WillTrojak/PyFR at feature/lin\_advection](https://github.com/WillTrojak/PyFR/tree/feature/lin_advection)

---

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [9 May 2022 15:12 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/10 "2022-05-09T15:12:51Z")

</div>

ok, thanks.

I add the [solver-source-term] which consists of trigonometric functions, and the error:

 ![MRDLBV}HF___X)6DQL`}A](https://global.discourse-cdn.com/free1/uploads/pyfr/original/1X/17f317d97f00ec095f4e0bda9d382347238fe08b.png)

 ![7I~BQKCCQMXQXE2FIT4ED5](https://global.discourse-cdn.com/free1/uploads/pyfr/original/1X/803026430c1edff1ae51bd44a43c5a54e8b2aa61.png)

Do you know what happened?

Regards

---

<div class="post-metadata">

**Author:** ![WillT](https://avatars.discourse-cdn.com/v4/letter/w/bc79bd/32.png) [@WillT](https://pyfr.discourse.group/u/WillT)\
**Post date:** [9 May 2022 17:33 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/11 "2022-05-09T17:33:35Z")

</div>

Can you show what you put in the ini file?

---

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [10 May 2022 02:18 UTC](https://pyfr.discourse.group/t/function-in-pyfr/593/13 "2022-05-10T02:18:52Z")

</div>

Thanks, I missed the something.
