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