[21341] | 1 | function md=solve(md,solutionstring,varargin)
|
---|
[1] | 2 | %SOLVE - apply solution sequence for this model
|
---|
| 3 | %
|
---|
| 4 | % Usage:
|
---|
[21341] | 5 | % md=solve(md,solutionstring,varargin)
|
---|
[1] | 6 | %
|
---|
[25836] | 7 | % where varargin is a lit of paired arguments of string OR enums
|
---|
[8343] | 8 | %
|
---|
[25836] | 9 | % Solution types available comprise:
|
---|
| 10 | % - 'Stressbalance' or 'sb'
|
---|
| 11 | % - 'Masstransport' or 'mt'
|
---|
| 12 | % - 'Thermal' or 'th'
|
---|
| 13 | % - 'Steadystate' or 'ss'
|
---|
| 14 | % - 'Transient' or 'tr'
|
---|
| 15 | % - 'Balancethickness' or 'mc'
|
---|
| 16 | % - 'Balancevelocity' or 'bv'
|
---|
| 17 | % - 'BedSlope' or 'bsl'
|
---|
| 18 | % - 'SurfaceSlope' or 'ssl'
|
---|
| 19 | % - 'Hydrology' or 'hy'
|
---|
| 20 | % - 'DamageEvolution' or 'da'
|
---|
| 21 | % - 'Gia' or 'gia'
|
---|
| 22 | % - 'Love' or 'lv'
|
---|
| 23 | % - 'Esa' or 'esa'
|
---|
| 24 | % - 'Sealevelrise' or 'slr'
|
---|
[9428] | 25 | %
|
---|
[25836] | 26 | % Extra options:
|
---|
| 27 | % - loadonly : does not solve. only load results
|
---|
| 28 | % - runtimename : true or false (default is true), makes name unique
|
---|
| 29 | % - checkconsistency : 'yes' or 'no' (default is 'yes'), ensures checks on
|
---|
| 30 | % consistency of model
|
---|
| 31 | % - restart : 'directory name (relative to the execution directory)
|
---|
| 32 | % where the restart file is located
|
---|
| 33 | %
|
---|
[1] | 34 | % Examples:
|
---|
[21341] | 35 | % md=solve(md,'Stressbalance');
|
---|
| 36 | % md=solve(md,'sb');
|
---|
[1] | 37 |
|
---|
[21341] | 38 | if ~ischar(solutionstring)
|
---|
| 39 | error('ISSM''s solve function only accepts strings for solution sequences. Type help solve to get a list of supported solutions');
|
---|
| 40 | end
|
---|
| 41 |
|
---|
[12351] | 42 | %recover and process solve options
|
---|
[21341] | 43 | if strcmpi(solutionstring,'sb') || strcmpi(solutionstring,'Stressbalance')
|
---|
| 44 | solutionstring = 'StressbalanceSolution';
|
---|
| 45 | elseif strcmpi(solutionstring,'mt') || strcmpi(solutionstring,'Masstransport')
|
---|
| 46 | solutionstring = 'MasstransportSolution';
|
---|
| 47 | elseif strcmpi(solutionstring,'th') || strcmpi(solutionstring,'Thermal')
|
---|
| 48 | solutionstring = 'ThermalSolution';
|
---|
| 49 | elseif strcmpi(solutionstring,'ss') || strcmpi(solutionstring,'Steadystate')
|
---|
| 50 | solutionstring = 'SteadystateSolution';
|
---|
| 51 | elseif strcmpi(solutionstring,'tr') || strcmpi(solutionstring,'Transient')
|
---|
| 52 | solutionstring = 'TransientSolution';
|
---|
| 53 | elseif strcmpi(solutionstring,'mc') || strcmpi(solutionstring,'Balancethickness')
|
---|
| 54 | solutionstring = 'BalancethicknessSolution';
|
---|
[22758] | 55 | elseif strcmpi(solutionstring,'Balancethickness2')
|
---|
| 56 | solutionstring = 'Balancethickness2Solution';
|
---|
[21729] | 57 | elseif strcmpi(solutionstring,'mcsoft') || strcmpi(solutionstring,'BalancethicknessSoft')
|
---|
| 58 | solutionstring = 'BalancethicknessSoftSolution';
|
---|
[21341] | 59 | elseif strcmpi(solutionstring,'bv') || strcmpi(solutionstring,'Balancevelocity')
|
---|
| 60 | solutionstring = 'BalancevelocitySolution';
|
---|
| 61 | elseif strcmpi(solutionstring,'bsl') || strcmpi(solutionstring,'BedSlope')
|
---|
| 62 | solutionstring = 'BedSlopeSolution';
|
---|
| 63 | elseif strcmpi(solutionstring,'ssl') || strcmpi(solutionstring,'SurfaceSlope')
|
---|
| 64 | solutionstring = 'SurfaceSlopeSolution';
|
---|
| 65 | elseif strcmpi(solutionstring,'hy') || strcmpi(solutionstring,'Hydrology')
|
---|
| 66 | solutionstring = 'HydrologySolution';
|
---|
| 67 | elseif strcmpi(solutionstring,'da') || strcmpi(solutionstring,'DamageEvolution')
|
---|
| 68 | solutionstring = 'DamageEvolutionSolution';
|
---|
| 69 | elseif strcmpi(solutionstring,'gia') || strcmpi(solutionstring,'Gia')
|
---|
| 70 | solutionstring = 'GiaSolution';
|
---|
[22758] | 71 | elseif strcmpi(solutionstring,'lv') || strcmpi(solutionstring,'Love')
|
---|
| 72 | solutionstring = 'LoveSolution';
|
---|
[21341] | 73 | elseif strcmpi(solutionstring,'esa') || strcmpi(solutionstring,'Esa')
|
---|
| 74 | solutionstring = 'EsaSolution';
|
---|
| 75 | elseif strcmpi(solutionstring,'slr') || strcmpi(solutionstring,'Sealevelrise')
|
---|
| 76 | solutionstring = 'SealevelriseSolution';
|
---|
| 77 | else
|
---|
| 78 | error(['solutionstring ' solutionstring ' not supported!']);
|
---|
[17806] | 79 | end
|
---|
[21341] | 80 | options=pairoptions(varargin{:},'solutionstring',solutionstring);
|
---|
[1] | 81 |
|
---|
[465] | 82 | %recover some fields
|
---|
[21341] | 83 | md.private.solution=solutionstring;
|
---|
[12363] | 84 | cluster=md.cluster;
|
---|
[25836] | 85 | if strcmpi(getfieldvalue(options,'batch','no'),'yes')
|
---|
| 86 | batch=1;
|
---|
| 87 | else
|
---|
| 88 | batch=0;
|
---|
| 89 | end
|
---|
[1] | 90 |
|
---|
[2326] | 91 | %check model consistency
|
---|
[18301] | 92 | if strcmpi(getfieldvalue(options,'checkconsistency','yes'),'yes'),
|
---|
| 93 | if md.verbose.solution,
|
---|
| 94 | disp('checking model consistency');
|
---|
[9882] | 95 | end
|
---|
[21341] | 96 | ismodelselfconsistent(md),
|
---|
[9882] | 97 | end
|
---|
[132] | 98 |
|
---|
[20500] | 99 | %If we are restarting, actually use the provided runtime name:
|
---|
| 100 | restart=getfieldvalue(options,'restart','');
|
---|
[12363] | 101 | %First, build a runtime name that is unique
|
---|
[20500] | 102 | if restart==1
|
---|
| 103 | %Leave the runtimename as is
|
---|
[17806] | 104 | else
|
---|
[20500] | 105 | if ~isempty(restart),
|
---|
| 106 | md.private.runtimename=restart;
|
---|
| 107 | elseif getfieldvalue(options,'runtimename',true),
|
---|
| 108 | c=clock;
|
---|
| 109 | md.private.runtimename=sprintf('%s-%02i-%02i-%04i-%02i-%02i-%02i-%i',md.miscellaneous.name,c(2),c(3),c(1),c(4),c(5),floor(c(6)),feature('GetPid'));
|
---|
| 110 | else
|
---|
| 111 | md.private.runtimename=md.miscellaneous.name;
|
---|
| 112 | end
|
---|
[17806] | 113 | end
|
---|
[12363] | 114 |
|
---|
[25836] | 115 | %if running QMU analysis, some preprocessing of Dakota files using models fields needs to be carried out.
|
---|
[9650] | 116 | if md.qmu.isdakota,
|
---|
[961] | 117 | md=preqmu(md,options);
|
---|
| 118 | end
|
---|
[2540] | 119 |
|
---|
[12351] | 120 | %Do we load results only?
|
---|
[17806] | 121 | if getfieldvalue(options,'loadonly',false),
|
---|
[12351] | 122 | md=loadresultsfromcluster(md);
|
---|
| 123 | return;
|
---|
| 124 | end
|
---|
[8330] | 125 |
|
---|
[13043] | 126 | %Write all input files
|
---|
[12988] | 127 | marshall(md); % bin file
|
---|
[15396] | 128 | ToolkitsFile(md.toolkits,[md.miscellaneous.name '.toolkits']); % toolkits file
|
---|
[21729] | 129 | BuildQueueScript(cluster,md.private.runtimename,md.miscellaneous.name,md.private.solution,md.settings.io_gather,md.debug.valgrind,md.debug.gprof,md.qmu.isdakota,md.transient.isoceancoupling); % queue file
|
---|
[12988] | 130 |
|
---|
[20500] | 131 | %Upload all required files
|
---|
[12363] | 132 | modelname = md.miscellaneous.name;
|
---|
[22758] | 133 | filelist = {[modelname '.bin'] [modelname '.toolkits']};
|
---|
[15396] | 134 | if ispc,
|
---|
[22758] | 135 | filelist{end+1}=[modelname '.bat'];
|
---|
[15396] | 136 | else
|
---|
[22758] | 137 | filelist{end+1}=[modelname '.queue'];
|
---|
[15396] | 138 | end
|
---|
| 139 |
|
---|
[12363] | 140 | if md.qmu.isdakota,
|
---|
| 141 | filelist{end+1} = [modelname '.qmu.in'];
|
---|
| 142 | end
|
---|
[12351] | 143 |
|
---|
[20500] | 144 | if isempty(restart),
|
---|
| 145 | UploadQueueJob(cluster,md.miscellaneous.name,md.private.runtimename,filelist);
|
---|
| 146 | end
|
---|
| 147 |
|
---|
| 148 | %launch queue job:
|
---|
| 149 | LaunchQueueJob(cluster,md.miscellaneous.name,md.private.runtimename,filelist,restart,batch);
|
---|
| 150 |
|
---|
| 151 | %return if batch:
|
---|
| 152 | if batch,
|
---|
| 153 | if md.verbose.solution,
|
---|
| 154 | disp('batch mode requested: not launching job interactively');
|
---|
| 155 | disp('launch solution sequence on remote cluster by hand');
|
---|
| 156 | end
|
---|
| 157 | return;
|
---|
| 158 | end
|
---|
[25836] | 159 |
|
---|
[12363] | 160 | %wait on lock
|
---|
[15396] | 161 | if isnan(md.settings.waitonlock),
|
---|
| 162 | %load when user enters 'y'
|
---|
| 163 | disp('solution launched on remote cluster. log in to detect job completion.');
|
---|
| 164 | choice=input('Is the job successfully completed? (y/n)','s');
|
---|
| 165 | if ~strcmp(choice,'y'),
|
---|
| 166 | disp('Results not loaded... exiting');
|
---|
| 167 | else
|
---|
[12363] | 168 | md=loadresultsfromcluster(md);
|
---|
[6569] | 169 | end
|
---|
[15396] | 170 | elseif md.settings.waitonlock>0,
|
---|
| 171 | %we wait for the done file
|
---|
| 172 | done=waitonlock(md);
|
---|
[17806] | 173 | if md.verbose.solution,
|
---|
| 174 | disp('loading results from cluster');
|
---|
| 175 | end
|
---|
[15396] | 176 | md=loadresultsfromcluster(md);
|
---|
| 177 | elseif md.settings.waitonlock==0,
|
---|
| 178 | disp('Model results must be loaded manually with md=loadresultsfromcluster(md);');
|
---|
[12363] | 179 | end
|
---|