I am trying to create an initial condition which is:
1 + 0.05 rand(x,y)
Here rand
is a pseudorandom function distributed in the interval (-1,1). This surface represents a random disturbance that I would like to use as an initial condition for PDEs in NDSolve
.
I assume I am being very silly when I try to use RandomReal[]
as my random number generator for my random disturbance. How should I proceed with this.
L = 100;
Plot3D[
1 - 0.05 (Cos[2 π x/L] + Sin[2 π x/L]) Cos[2 π y/L] RandomReal[],
{x, 0, L}, {y, 0, L}
]
Obviously, this is wrong as this still retains the underlying Cos/Sin curve. How should I go about creating a random disturbance? $\delta\varepsilon\pi$
Working example:
$HistoryLength = 0;
Needs["VectorAnalysis`"]
Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"];
Clear[Eq0, EvapThickFilm, h, Bo, ε, K1, \[Delta], Bi, m, r]
Eq0[h_, {Bo_, ε_, K1_, δ_, Bi_, m_, r_}] := D[h, t] +
Div[-h^3 Bo Grad[h] +
h^3 Grad[Laplacian[h]] + (δ h^3)/(Bi h + K1)^3 Grad[h] +
m (h/(K1 + Bi h))^2 Grad[h]] + ε/(
Bi h + K1) + (r) D[D[(h^2/(K1 + Bi h)), x] h^3, x] == 0;
SetCoordinates[Cartesian[x, y, z]];
EvapThickFilm[Bo_, ε_, K1_, δ_, Bi_, m_, r_] :=
Eq0[h[x, y, t], {Bo, ε, K1, δ, Bi, m, r}];
TraditionalForm[
EvapThickFilm[Bo, ε, K1, δ, Bi, m, r]];
L = 2*92.389; TMax = 3100*100;
Off[NDSolve::mxsst];
Clear[Kvar];
Kvar[t_] := Piecewise[{{1, t <= 1}, {2, t > 1}}]
(* Ktemp = Array[0.001 + 0.001 #^2 &, 13] *)
hSol = h /. NDSolve[{
(*Bo,ε,K1,δ,Bi,m,r*)
EvapThickFilm[0.003, 0, 1, 0, 1, 0.025, 0],
h[0, y, t] == h[L, y, t],
h[x, 0, t] == h[x, L, t],
(*h[x,y,0] == 1.1+Cos[x] Sin[2y] *)
h[x, y, 0] == BSplineFunction[RandomReal[1, {30, 30, 1}]]
},
h,
{x, 0, L},
{y, 0, L},
{t, 0, TMax},
Method -> {"BDF", "MaxDifferenceOrder" -> 1},
MaxStepFraction -> 1/50
][[1]]
With the B-spline as suggested by Vitaliy Kaurov in the answer below, I have the following error:
NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. >>
ReplaceAll::reps: {(h^(0,0,1))[x,y,t]-0.009 h[x,y,t]^2 (h^(0,1,0))[x,y,t]^2-(0.05 h[x,y,t]^2 (h^(0,1,0))[x,y,t]^2)/(1+h[x,y,t])^3+<<13>>+h[x,y,t]^3 ((h^(0,4,0))[x,y,t]+(h^(2,2,0))[x,y,t])+3 h[x,y,t]^2 (h^(1,0,0))[x,y,t] ((h^(1,2,0))[x,y,t]+(h^(3,0,0))[x,y,t])+h[x,y,t]^3 ((h^(2,2,0))[x,y,t]+(h^(4,0,0))[x,y,t])==0,h[0,y,t]==h[184.778,y,t],h[<<1>>]==<<1>>,h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
Plot3D[1 + RandomReal[{-0.05, 0.05}], {x, 0, 1}, {y, 0, 1}]
? That would be valid as an initial condition provided it were repeatable, which can be accomplished by memoizing it:f[x_, y_] := f[x, y] = RandomReal[]; Plot3D[f[x, y], {x, 0, 1}, {y, 0, 1}]
. Just watch out for uncontrolled growth in RAM used byf
! $\endgroup$bsf = Interpolation@Flatten[ Table[{{x, y}, 1 + .05*RandomReal[{-1, 1}]}, {x, 0, L + 1}, {y, 0, L + 1}], 1];
and then have as an ich[x, y, 0] == bsf[x, y]
it works (except I didn't fix the boundary conditions correctly) $\endgroup$