[Dune] question about initial condition

Christian Engwer christian.engwer at uni-muenster.de
Mon Aug 24 12:31:18 CEST 2020


Dear Rana,

On Mon, Aug 24, 2020 at 11:31:41AM +0500, Rana Abdul Rauf wrote:
> Hello DUNE developers, I am working on phase field modeling. For the
> numerical simulations, I am using Dune PEDlab. Now I am solving the
> Cahn-Hilliard equation to see the spinodal decomposition. For this I want
> to generate random numbers between -1 to 1. Kindly help me how to put
> rand(x,y) as a initial condition, where rand(x,y) is random number between
> -1 to 1.

you can cast any lambda into a discrete function in
PDELab. Interpolation aloows then to use this function as an initial
value.

- use your favorite random number generator, depending on your needs.
- for simpliity I assume a uniform distribution between -1 and 1 is OK
  and I'll use std::uniform_real_distribution (https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution)
- you can now create a random scalar function using, working in global coordinates:
  ```
   std::random_device rd;  //Will be used to obtain a seed for the random number engine
   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
   std::uniform_real_distribution<> dis(-1.0, 1.0);
   auto r = [dis&,gen&](const auto & x){ return dis(gen); };
  ```
  and cast it into a grid function, using infrastruture from dune-functions
  ```
  auto f = Dune::makeAnalyticGridViewFunction(r, gridView);
  ```
- this function `f` an now interpolated into your stating vector using PDELab's `interplate`.

If you know how to interprate your coeffiients you can further
simplify this approach and perhas even use these random values
directly as coefficients.

Ciao
Christian




More information about the Dune mailing list