source: issm/trunk/src/m/solve/solve.m@ 20500

Last change on this file since 20500 was 20500, checked in by Mathieu Morlighem, 9 years ago

merged trunk-jpl and trunk for revision 20497

File size: 4.9 KB
Line 
1function md=solve(md,solutionenum,varargin)
2%SOLVE - apply solution sequence for this model
3%
4% Usage:
5% md=solve(md,solutionenum,varargin)
6% where varargin is a lit of paired arguments of string OR enums
7%
8% solution types available comprise:
9% - StressbalanceSolutionEnum
10% - MasstransportSolutionEnum
11% - ThermalSolutionEnum
12% - SteadystateSolutionEnum
13% - TransientSolutionEnum
14% - BalancethicknessSolutionEnum
15% - BedSlopeSolutionEnum
16% - SurfaceSlopeSolutionEnum
17% - HydrologySolutionEnum
18% - FlaimSolutionEnum
19%
20% extra options:
21% - loadonly : does not solve. only load results
22% - runtimename : true or false (default is true), makes name unique
23% - checkconsistency : 'yes' or 'no' (default is 'yes'), ensures checks on consistency of model
24% - restart: 'directory name (relative to the execution directory) where the restart file is located.
25%
26% Examples:
27% md=solve(md,StressbalanceSolutionEnum);
28
29%recover and process solve options
30if ~strncmp(fliplr(EnumToString(solutionenum)),fliplr('Solution'),8),
31 error(['solutionenum ' EnumToString(solutionenum) ' not supported!']);
32end
33options=pairoptions(varargin{:},'solutionenum',solutionenum);
34
35%recover some fields
36md.private.solution=solutionenum;
37cluster=md.cluster;
38if strcmpi(getfieldvalue(options,'batch','no'),'yes') batch=1; else batch=0; end
39
40%check model consistency
41if strcmpi(getfieldvalue(options,'checkconsistency','yes'),'yes'),
42 if md.verbose.solution,
43 disp('checking model consistency');
44 end
45 if (solutionenum == FlaimSolutionEnum())
46 md.private.isconsistent=true;
47 md=checkconsistency(md.mesh,md,solutionenum);
48 md=checkconsistency(md.flaim,md,solutionenum);
49 if md.private.isconsistent==false,
50 error('Model not consistent, see messages above');
51 end
52 else
53 ismodelselfconsistent(md),
54 end
55end
56
57%If we are restarting, actually use the provided runtime name:
58restart=getfieldvalue(options,'restart','');
59%First, build a runtime name that is unique
60if restart==1
61 %Leave the runtimename as is
62else
63 if ~isempty(restart),
64 md.private.runtimename=restart;
65 elseif getfieldvalue(options,'runtimename',true),
66 c=clock;
67 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'));
68 else
69 md.private.runtimename=md.miscellaneous.name;
70 end
71end
72
73%if running qmu analysis, some preprocessing of dakota files using models
74%fields needs to be carried out.
75if md.qmu.isdakota,
76 md=preqmu(md,options);
77end
78
79%flaim analysis (To be removed?)
80if (solutionenum == FlaimSolutionEnum())
81 %fmdir = getfieldvalue(options,'fmdir',['fm' num2str(feature('GetPid'))]);
82 %overwrite = getfieldvalue(options,'overwrite','n');
83 %keep = getfieldvalue(options,'keep','y');
84 %latsgn = getfieldvalue(options,'latsgn',0);
85 %cmap = getfieldvalue(options,'cmap',[]);
86 md=flaim_sol(md,options);
87 md.private.solution=EnumToString(solutionenum);
88 return;
89end
90
91%Do we load results only?
92if getfieldvalue(options,'loadonly',false),
93 md=loadresultsfromcluster(md);
94 return;
95end
96
97%Write all input files
98marshall(md); % bin file
99ToolkitsFile(md.toolkits,[md.miscellaneous.name '.toolkits']); % toolkits file
100BuildQueueScript(cluster,md.private.runtimename,md.miscellaneous.name,md.private.solution,md.settings.io_gather,md.debug.valgrind,md.debug.gprof,md.qmu.isdakota); % queue file
101
102%Upload all required files
103modelname = md.miscellaneous.name;
104filelist = {[modelname '.bin '] [modelname '.toolkits ']};
105if ispc,
106 filelist{end+1}=[modelname '.bat '];
107else
108 filelist{end+1}=[modelname '.queue '];
109end
110
111if md.qmu.isdakota,
112 filelist{end+1} = [modelname '.qmu.in'];
113end
114
115if isempty(restart),
116 UploadQueueJob(cluster,md.miscellaneous.name,md.private.runtimename,filelist);
117end
118
119%launch queue job:
120LaunchQueueJob(cluster,md.miscellaneous.name,md.private.runtimename,filelist,restart,batch);
121
122%return if batch:
123if batch,
124 if md.verbose.solution,
125 disp('batch mode requested: not launching job interactively');
126 disp('launch solution sequence on remote cluster by hand');
127 end
128 return;
129end
130%wait on lock
131if isnan(md.settings.waitonlock),
132 %load when user enters 'y'
133 disp('solution launched on remote cluster. log in to detect job completion.');
134 choice=input('Is the job successfully completed? (y/n)','s');
135 if ~strcmp(choice,'y'),
136 disp('Results not loaded... exiting');
137 else
138 md=loadresultsfromcluster(md);
139 end
140elseif md.settings.waitonlock>0,
141 %we wait for the done file
142 done=waitonlock(md);
143 if md.verbose.solution,
144 disp('loading results from cluster');
145 end
146 md=loadresultsfromcluster(md);
147elseif md.settings.waitonlock==0,
148 disp('Model results must be loaded manually with md=loadresultsfromcluster(md);');
149end
150
151%post processes qmu results if necessary
152if md.qmu.isdakota,
153 if ~strncmpi(getfieldvalue(options,'keep','y'),'y',1)
154 system(['rm -rf qmu' num2str(feature('GetPid'))]);
155 end
156end
Note: See TracBrowser for help on using the repository browser.