% Lid-Driven Cavity Flow test case

% First call the setup file from the LidDrivenCavityFlow, and add the DO part.
LidDrivenCavitySetup;

% Initialize DO fields:
d0 = fileparts([pwd,filesep]);
d0 = d0(1:strfind(d0,'trunk')+4);

[ui, vi, var] = Stoch_Initial_Perturb(XU,YU,XV,YV,Nbcs,...
        length(bcsDq)+length(bcsOq),NodeP,app.S(1)+1);
if isfield(app,'var') 
   var = var*app.var(1);
else
   var = var*1e-6;
end    
display('Created initial conditions for DO simulation.')
close all;

%Set default number of Monte-Carlo samples
if ~isfield(app,'MC')
    app.MC=4000;
end

% Initialize modes

ui = ui(:,1:app.S(1));
vi = vi(:,1:app.S(1));
Pi = zeros(length(P),app.S(1));

% Initialize stochastic coefficients as normal random with variance as calculated
% in Stoch_Initial_Perturb
Yi = zeros(app.MC,app.S(1));

for i = 1:app.S(1)
    Yi(:,i) = normrnd(0,sqrt(var(i)),app.MC,1);
end

% Need these for Orthonormalization
uid = Nbcs+1:length(u);
vid = Nbcs+1:length(v);

% Ortho-Normalization of basis fields to avoid round-off errors
[Yi ui vi Pi] = DOorthnorm(app, dx, dy, Yi, ui, uid, vi, vid, Pi, pid);

