# Random function in input file does not work?

**URL:** <https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761>\
**Category:** ASPECT\
**Created:** [January 11, 2023, 3:18pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761 "2023-01-11T15:18:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![cedrict](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/cedrict/32/344_2.png) [@cedrict](https://community.geodynamics.org/u/cedrict)\
**Post date:** [January 11, 2023, 3:18pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/1 "2023-01-11T15:18:08Z")

</div>

Hi all,  
I ran the continental extension prm file yesterday and I noticed that the randomized initial strain of the following function does not work (anymore). When looking at the paraview file I see that the plastic strain is constant and equal to 1.5 inside the designated area (see attached screen capture). Has the syntax changed? is this a (known) bug?  
Cheers,  
Cedric

 ![Screenshot from 2023-01-11 16-13-40](https://canada1.discourse-cdn.com/flex036/uploads/geodynamics/original/2X/7/796e9da28dd7e3dbd26a6a0eb6b8bbf9ee1768f8.png)

subsection Initial composition model  
set Model name = function  
subsection Function  
set Variable names = x,y  
set Function expression = 0;   
if(x\>50.e3 && x\<150.e3 && y\>50.e3, 0.5 + rand\_seed(1), 0);   
if(y\>=80.e3, 1, 0);   
if(y\<80.e3 && y\>=60.e3, 1, 0);   
if(y\<60.e3, 1, 0);  
end  
end

* * *

## – This is ASPECT, the Advanced Solver for Problems in Earth’s ConvecTion. – . version 2.5.0-pre (main, 50d0c5740) – . using deal.II 9.4.0 – . with 32 bit indices and vectorization level 1 (128 bits) – . using Trilinos 12.18.1 – . using p4est 2.3.2 – . running in DEBUG mode – . running with 1 MPI process

---

<div class="post-metadata">

**Author:** ![jbnaliboff](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jbnaliboff](https://community.geodynamics.org/u/jbnaliboff)\
**Post date:** [January 11, 2023, 9:07pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/2 "2023-01-11T21:07:12Z")

</div>

Hi Cedric,

Thanks for reporting the issue, that is really odd. I just ran the cookbook with the most recent ASPECT version and got the expected random distribution of initial plastic strain. This was done on an ubuntu workstation.

I’m not sure what the issue could be here? Just to be sure, can you try reloading and rescaling the color bar?

Cheers,  
John

> – This is ASPECT, the Advanced Solver for Problems in Earth’s ConvecTion.  
> – . version 2.5.0-pre (main, bb7beb982)  
> – . using deal.II 9.4.0  
> – . with 32 bit indices and vectorization level 0 (64 bits)  
> – . using Trilinos 13.2.0  
> – . using p4est 2.2.0  
> – . running in DEBUG mode  
> – . running with 4 MPI processes
> 
> ![continental_extension_plastic_strain_time0](https://canada1.discourse-cdn.com/flex036/uploads/geodynamics/original/2X/0/0634b9ee3333017eef68126539253848415943fe.png)

---

<div class="post-metadata">

**Author:** ![cedrict](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/cedrict/32/344_2.png) [@cedrict](https://community.geodynamics.org/u/cedrict)\
**Post date:** [January 12, 2023, 7:26am UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/3 "2023-01-12T07:26:15Z")

</div>

hi John,  
the strain field is really ‘flat’ I am afraid. I am also running ubuntu. I will reinstall everything from scratch on my other workstation then.  
Ce/

 ![Screenshot from 2023-01-12 08-21-59](https://canada1.discourse-cdn.com/flex036/uploads/geodynamics/original/2X/d/dc1c29581c6377816889010a90c58ac850544ace.png)

---

<div class="post-metadata">

**Author:** ![jbnaliboff](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jbnaliboff](https://community.geodynamics.org/u/jbnaliboff)\
**Post date:** [January 12, 2023, 3:26pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/4 "2023-01-12T15:26:28Z")

</div>

Hi Cedric,

Oofta, that is really weird. There issue is likely with muparser, but that is built with deal.II and we are both on 9.4.0. What versions of gnu compilers are you on?

Cheers,  
John

---

<div class="post-metadata">

**Author:** ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)\
**Post date:** [January 12, 2023, 7:54pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/5 "2023-01-12T19:54:08Z")

</div>

Cedric,  
This is indeed weird. I have not seen anything like that before and I doubt recompiling everything would fix this. To be sure, this is the unmodified .prm file from the benchmarks folder?

(is always returning 1 not a decent random number generator?) 🙂

---

<div class="post-metadata">

**Author:** ![cedrict](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/cedrict/32/344_2.png) [@cedrict](https://community.geodynamics.org/u/cedrict)\
**Post date:** [January 12, 2023, 9:05pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/6 "2023-01-12T21:05:34Z")

</div>

So I changed computer (still ubuntu machine), and installed candi from scratch today and re-compiled aspect. I ran the prm file just now without changing anything and still the same problem.

* * *

## – This is ASPECT, the Advanced Solver for Problems in Earth’s ConvecTion. – . version 2.5.0-pre (main, bb7beb982) – . using deal.II 9.4.1 – . with 32 bit indices and vectorization level 1 (128 bits) – . using Trilinos 13.2.0 – . using p4est 2.3.2 – . running in DEBUG mode – . running with 1 MPI process

gcc -v  
Using built-in specs.  
COLLECT\_GCC=gcc  
COLLECT\_LTO\_WRAPPER=/usr/lib/gcc/x86\_64-linux-gnu/11/lto-wrapper  
OFFLOAD\_TARGET\_NAMES=nvptx-none:amdgcn-amdhsa  
OFFLOAD\_TARGET\_DEFAULT=1  
Target: x86\_64-linux-gnu  
Configured with: ../src/configure -v --with-pkgversion=‘Ubuntu 11.3.0-1ubuntu1~22.04’ --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86\_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86\_64-linux-gnu --host=x86\_64-linux-gnu --target=x86\_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2  
Thread model: posix  
Supported LTO compression algorithms: zlib zstd  
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)

---

<div class="post-metadata">

**Author:** ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)\
**Post date:** [January 13, 2023, 4:50pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/7 "2023-01-13T16:50:01Z")

</div>

Thanks Cedric. I will try to reproduce.

---

<div class="post-metadata">

**Author:** ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)\
**Post date:** [January 18, 2023, 3:55pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/8 "2023-01-18T15:55:06Z")

</div>

I am not able to reproduce so far. Can you try the following small deal.II program and report the output (if it returns only 1.0 then we see the same bug):

> <https://gist.github.com/tjhei/360edba1d62bb61ecd63ebb16d82ecc0>

---

<div class="post-metadata">

**Author:** ![cedrict](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/cedrict/32/344_2.png) [@cedrict](https://community.geodynamics.org/u/cedrict)\
**Post date:** [January 18, 2023, 6:37pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/9 "2023-01-18T18:37:24Z")

</div>

Hi,  
here is the output of the code:  
./function\_parser\_09  
0.298761  
0.133475  
0.49459  
0.443015  
OK

---

<div class="post-metadata">

**Author:** ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)\
**Post date:** [January 26, 2023, 12:02am UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/10 "2023-01-26T00:02:47Z")

</div>

Hi Cedric,  
I can reproduce the bug and we are working on a fix. It seems to be inside deal.II and unrelated to ASPECT (unsurprisingly).

---

<div class="post-metadata">

**Author:** ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)\
**Post date:** [February 7, 2023, 7:18pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/11 "2023-02-07T19:18:57Z")

</div>

Here is the proposed deal.II fix:

> <https://github.com/dealii/dealii/pull/14765>
>
> A bug reported from Aspect community about random number generator. The simple …fix is we need to set optimized=false, because rand will generate different number every time.

I am still not sure why it is only sometimes incorrectly optimized. As a workaround, you can replace rand\_seed(1) by rand() (this might work) or update to the latest deal.II master once the PR is merged.

edit: Using rand() does not work either. You can go back to deal.II 9.3 and it should work too.

---

<div class="post-metadata">

**Author:** ![jbnaliboff](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jbnaliboff](https://community.geodynamics.org/u/jbnaliboff)\
**Post date:** [March 21, 2023, 6:01pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/12 "2023-03-21T18:01:35Z")

</div>

Odd model behavior that may be related to the fix Timo proposed:

- I recently updated the compilers on Ubuntu 22.04 to gcc 11.
- I reinstalled deal.II 9.4.0 via Candi. I was previously using the pre-built version of deal.II 9.4.0 for Ubuntu.
- I ran two models, which are identical aside from one using particles and one using fields to track properties.
- The model using the rand\_seed() function in to generate initial random plastic strain (0.5 + rand\_seed(1))
- The model using particles has the correct randomized distribution of strain, while the model using fields has a constant value of 1.5, indicating rand\_seed(1) always defaults to 1.

I have not tried Timo’s fix yet, but another data point to be aware of in case anyone runs into the same issue.

- John

---

<div class="post-metadata">

**Author:** ![bangerth](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/bangerth/32/52_2.png) [@bangerth](https://community.geodynamics.org/u/bangerth)\
**Post date:** [March 22, 2023, 3:24am UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/13 "2023-03-22T03:24:05Z")

</div>

Hi John,  
I think that is basically what @tjhei had observed. Can you try with an updated deal.II version?  
Best  
W.

---

<div class="post-metadata">

**Author:** ![jbnaliboff](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jbnaliboff](https://community.geodynamics.org/u/jbnaliboff)\
**Post date:** [March 22, 2023, 6:35pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/14 "2023-03-22T18:35:36Z")

</div>

Hi Wolfgang (and all)

> I think that is basically what @tjhei had observed. Can you try with an updated deal.II version?

Yep, the correct randomized field appears using the latest deal.II development (main) branch.

Cheers,  
John

---

<div class="post-metadata">

**Author:** ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)\
**Post date:** [March 22, 2023, 6:56pm UTC](https://community.geodynamics.org/t/random-function-in-input-file-does-not-work/2761/15 "2023-03-22T18:56:54Z")

</div>

Here is the issue that mentions the two ways to work around it: [rand\_seed always returns the same value · Issue #5114 · geodynamics/aspect · GitHub](https://github.com/geodynamics/aspect/issues/5114)
