time | calls | line |
---|
| 1 | 6 | if ~exist('ui','var') && (app.S(1)>0 || length(app.S)>1)
|
| | 7 | %If app.S=[0 #] we set app.S=1 and start with a very small variance
|
| | 8 |
|
| | 9 | %Choose the number of modes for the size of the basis from which new
|
| | 10 | %unstable modes will be chosen.
|
| | 11 | NUMMODESINBASIS=round(min(50,max(max(app.S)^2/2,30)));
|
| | 12 | d0=fileparts([pwd,filesep]);
|
| | 13 | d0=d0(1:strfind(d0,'trunk')+4);
|
| | 14 |
|
| | 15 | if length(app.S)>1 %adaptive
|
| | 16 | if ~isfield(app,'PlotScript')
|
| | 17 | PlotScript = 'DOAdaptGenericPlots';
|
| | 18 | end
|
| | 19 | %Need 1 extra mode to have a properly normalized basis
|
| | 20 | [ui, vi, var] = Stoch_Initial_Perturb(XU,YU,XV,YV,Nbcs,...
|
| | 21 | length(bcsDP)+length(bcsOP),NodeP,NUMMODESINBASIS+1);
|
| | 22 | if isfield(app,'var')
|
| | 23 | var = var*app.var(1);
|
| | 24 | else
|
| | 25 | var = var*1e-6;
|
| | 26 | end
|
| | 27 | %XU and YU etc. contain points that may be masked out, so we have
|
| | 28 | %to remove these. Also remove the extra mode.
|
| | 29 | ui = ui([[1:Nbcs]';Nbcs+idsu],1:NUMMODESINBASIS);
|
| | 30 | vi = vi([[1:Nbcs]';Nbcs+idsv],1:NUMMODESINBASIS);
|
| | 31 | existbasis = length(dir([d0,'/Save/DOAdaptSave/Basis/orth_basis*']));
|
| | 32 | save([d0,sprintf('/Save/DOAdaptSave/Basis/orth_basis%0.3d.mat',existbasis)],...
|
| | 33 | 'ui','vi');
|
| | 34 | close all
|
| | 35 | else %non-adaptive
|
| | 36 | if ~isfield(app,'PlotScript')
|
| | 37 | PlotScript = 'DOAdaptGenericPlots';
|
| | 38 | end
|
| | 39 | %Need to have one extra mode to have a proper orthonormalization
|
| | 40 | [ui, vi, var] = Stoch_Initial_Perturb(XU,YU,XV,YV,Nbcs,...
|
| | 41 | length(bcsDP)+length(bcsOP),NodeP,app.S + 1);
|
| | 42 | var
|
| | 43 | if isfield(app,'var')
|
| | 44 | var = var*app.var(1);
|
| | 45 | else
|
| | 46 | var = var*1e-6;
|
| | 47 | end
|
| | 48 | close all;
|
| | 49 | %XU and YU etc. contain points that may be masked out, so we have
|
| | 50 | %to remove these.
|
| | 51 | ui = ui([[1:Nbcs]';Nbcs+idsu],:);
|
| | 52 | vi = vi([[1:Nbcs]';Nbcs+idsv],:);
|
| | 53 | end
|
| | 54 |
|
| | 55 | %If the number of Monte-Carlo samples was not set by the setup script,
|
| | 56 | %arbitrarily choose 10,000
|
| | 57 | if ~isfield(app,'MC'),app.MC=10000;end
|
| | 58 |
|
| | 59 | if (app.S(1)==0)
|
| | 60 | %For app.S = [0 #] case we need to set small variance, and initialize
|
| | 61 | %arrays properly
|
| | 62 | app.S(1)=1;
|
| | 63 | var(1)=1e-6;
|
| | 64 | fui = zeros(length(uid),app.S(1));
|
| | 65 | fvi = zeros(length(vid),app.S(1));
|
| | 66 | fuij= zeros(length(uid),app.S(1)^2);
|
| | 67 | fvij= zeros(length(vid),app.S(1)^2);
|
| | 68 | end
|
| | 69 | j=1;
|
| | 70 | randn('state',0);
|
| | 71 | YYt=zeros(app.MC,app.S(1)+1);
|
| | 72 | for i=1:app.S+1
|
| | 73 | YYt(:,j)=normrnd(0,sqrt(var(i)),app.MC,1);
|
| | 74 | j=j+1;
|
| | 75 | end
|
| | 76 |
|
| | 77 | ui = ui(:,1:app.S(1)+1);
|
| | 78 | vi = vi(:,1:app.S(1)+1);
|
| | 79 | Pi=zeros(length(P),app.S(1)+1);
|
| | 80 | %Ortho-Normalization of basis fields to avoid round-off errors
|
| | 81 | [YYt ui vi Pi] = DOorthnorm(app, dx, dy, YYt, ui, uid, vi, vid, Pi, pid);
|
| | 82 |
|
| | 83 | %Only select the first S modes
|
| | 84 | ui = ui(:,1:app.S(1));
|
| | 85 | vi = vi(:,1:app.S(1));
|
| | 86 | Pi=zeros(length(P),app.S(1));
|
| | 87 | YYt = YYt(:,1:app.S(1));
|
| | 88 | end
|