# Random intial conditions using finite element method

How can we define the initial value for Cahn-Hilliard problem (links) using FEM in MMA?

Complete test code (I am using MIXED formulation for C1 Problem):

Needs["NDSolveFEM"]
\[CapitalOmega]=ImplicitRegion[{0<=x<=1,0<=y<=1},{x,y}];
RegionPlot[\[CapitalOmega],PlotRange->{{0,1},{0,1}}]
Mobi = 1.0; lame = 0.01;
op1 = \!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]$$u[t, x, y]$$\) - Mobi.\!$$\*SubsuperscriptBox[\(\[Del]$$, $${x, y}$$, $$2$$]$$v[t, x, y]$$\)

op2 = v[t, x, y] -
200 u[t, x, y] (1 - 3 u[t, x, y] + 2 u[t, x, y]^2) + lame.\!$$\*SubsuperscriptBox[\(\[Del]$$, $${x, y}$$, $$2$$]$$u[t, x, y]$$$$\$$\)

Subscript[\[CapitalGamma], N1] =
NeumannValue[Mobi* lame.u[t, x, y], {0 <= x <= 1, 0 <= y <= 1}]

{nufun, nvfun} =
NDSolveValue[{op1 == Subscript[\[CapitalGamma], N1], op2 == 0}, {u,
v}, {t, 0, 100}, {x, y} \[Element] \[CapitalOmega]];

• There are also other problems in your code: The Dots after Mobi and lame have to be removed and you have not specified boundary conditions for v. – Henrik Schumacher Jul 20 '19 at 1:27
• @HenrikSchumacher I have checked the bcs, you may see Eq 5.1 from fenicsproject.org/olddocs/dolfin/1.3.0/python/demo/documented/… – ABCDEMMM Jul 20 '19 at 1:33
• Yeah, so you have to specify them also in the call to NDSolve. – Henrik Schumacher Jul 20 '19 at 1:36

## 1 Answer

This is one of many ways to create "random" initial value conditions:

Ωdisc = ToElementMesh[Ω];
n = Length[Ωdisc["Coordinates"]];
u0 = ElementMeshInterpolation[{Ωdisc}, RandomReal[{-2, 2}, n]];
Plot3D[u0[x, y], {x, y} ∈ Ωdisc]


It might be a good idea to use Ωdisc] also in the call to NDSolveValues instead of Ω.

• @Herik Schumacher, this initial value definition not works. $0.625107,0.634007,<42>>, 0.639777,0.627036,0.625157, \ll 3151>>\},\{\text { Automatic }\} ]$ should be a rank 2 tensor of machine-size real numbers. – ABCDEMMM Jul 20 '19 at 9:55
• That's probably because this is only an initial condition for u, not for v. – Henrik Schumacher Jul 20 '19 at 12:37
• u[0, x, y] == u0[x, y]??? – ABCDEMMM Jul 20 '19 at 12:40
• Yes, that's how you should use it. But v needs also initial conditions. And boundary conditions. – Henrik Schumacher Jul 20 '19 at 12:43