% Last modified: 06/09/2012 by Pete

% trueshape     true shape of obstacle in system [1,5]
%                 1 = circle,
%                 2 = square,
%                 3 = upstream-pointing triangle,
%                 4 = downstream-pointing triangle,
%                 5 = diamond
% Re            Reynolds number [50,100]
% randseed      rng seed for observation noise realization (set to -1 to
%               suppress addition of noise to observations)
% shape         shape of obstacle used in stochastic model [1,5]

function Pete_RunStoch( trueshape, Re, randseed, shape )

app.toptic = tic ;
fprintf(['Stochastic flow past an obstacle: ',...
    'stochastic model.\n'])

trunk = regexp(pwd,'.*trunk','match','once') ; Pete_src
app.tag = sprintf('obstacle_trueshape%d_Re%d_randseed%d', ...
    trueshape, Re, randseed) ;
savemain = [trunk,'/Save/',app.tag] ;
addpath(genpath([trunk,'/Cases/Pete_obstacle']))

% load parameter file generated from deterministic realization
paramfile = [ savemain, '/true/param.mat' ] ;
if ( ~exist(paramfile,'file') )
    fprintf(['Deterministic realization not found.  ',...
        'Running deterministic realization first.\n'])
    Pete_RunDet( trueshape, Re, randseed )
end
load( paramfile, 'app' )

% DO PARAMETERS
app.S = 5 ;             % number of active DO modes
app.MC = 1e4 ;          % number of Monte Carlo ensemble particles
app.varscale = 1 ;      % scaling factor for initial field variance
app.Re_range = ...      % range for possible Re values
    [ 50 , 100 ] ;

% call stochastic solver
app.shape = shape ;
app.subtag = num2str(shape) ;
loglikes = Pete_StochSolver( app ) ;

save( sprintf('%s/loglikes%d.mat',savemain,shape), 'loglikes' )

fprintf( 'Phew! Total time = %02d:%02d.\n', ...
    floor(toc(app.app.toptic)/3600), floor(mod(toc(app.toptic),3600)/60) )

