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