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
RevLine 
[8296]1function md=solve(md,solutionenum,varargin)
[1]2%SOLVE - apply solution sequence for this model
3%
4% Usage:
[8296]5% md=solve(md,solutionenum,varargin)
[3923]6% where varargin is a lit of paired arguments of string OR enums
[1]7%
[9218]8% solution types available comprise:
[16137]9% - StressbalanceSolutionEnum
10% - MasstransportSolutionEnum
[9401]11% - ThermalSolutionEnum
12% - SteadystateSolutionEnum
[17806]13% - TransientSolutionEnum
[9401]14% - BalancethicknessSolutionEnum
15% - BedSlopeSolutionEnum
16% - SurfaceSlopeSolutionEnum
17% - HydrologySolutionEnum
18% - FlaimSolutionEnum
[8343]19%
[9428]20% extra options:
[17806]21% - loadonly : does not solve. only load results
22% - runtimename : true or false (default is true), makes name unique
[18301]23% - checkconsistency : 'yes' or 'no' (default is 'yes'), ensures checks on consistency of model
[20500]24% - restart: 'directory name (relative to the execution directory) where the restart file is located.
[9428]25%
[1]26% Examples:
[16137]27% md=solve(md,StressbalanceSolutionEnum);
[1]28
[12351]29%recover and process solve options
[17806]30if ~strncmp(fliplr(EnumToString(solutionenum)),fliplr('Solution'),8),
31 error(['solutionenum ' EnumToString(solutionenum) ' not supported!']);
32end
33options=pairoptions(varargin{:},'solutionenum',solutionenum);
[1]34
[465]35%recover some fields
[17806]36md.private.solution=solutionenum;
[12363]37cluster=md.cluster;
[20500]38if strcmpi(getfieldvalue(options,'batch','no'),'yes') batch=1; else batch=0; end
[1]39
[2326]40%check model consistency
[18301]41if strcmpi(getfieldvalue(options,'checkconsistency','yes'),'yes'),
42 if md.verbose.solution,
43 disp('checking model consistency');
[9882]44 end
[18301]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
[9882]55end
[132]56
[20500]57%If we are restarting, actually use the provided runtime name:
58restart=getfieldvalue(options,'restart','');
[12363]59%First, build a runtime name that is unique
[20500]60if restart==1
61 %Leave the runtimename as is
[17806]62else
[20500]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
[17806]71end
[12363]72
[12351]73%if running qmu analysis, some preprocessing of dakota files using models
74%fields needs to be carried out.
[9650]75if md.qmu.isdakota,
[961]76 md=preqmu(md,options);
77end
[2540]78
[17806]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',[]);
[9882]86 md=flaim_sol(md,options);
[17806]87 md.private.solution=EnumToString(solutionenum);
[7686]88 return;
89end
90
[12351]91%Do we load results only?
[17806]92if getfieldvalue(options,'loadonly',false),
[12351]93 md=loadresultsfromcluster(md);
94 return;
95end
[8330]96
[13043]97%Write all input files
[12988]98marshall(md); % bin file
[15396]99ToolkitsFile(md.toolkits,[md.miscellaneous.name '.toolkits']); % toolkits file
[20500]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
[12988]101
[20500]102%Upload all required files
[12363]103modelname = md.miscellaneous.name;
[15396]104filelist = {[modelname '.bin '] [modelname '.toolkits ']};
105if ispc,
106 filelist{end+1}=[modelname '.bat '];
107else
108 filelist{end+1}=[modelname '.queue '];
109end
110
[12363]111if md.qmu.isdakota,
112 filelist{end+1} = [modelname '.qmu.in'];
113end
[12351]114
[20500]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
[12363]130%wait on lock
[15396]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
[12363]138 md=loadresultsfromcluster(md);
[6569]139 end
[15396]140elseif md.settings.waitonlock>0,
141 %we wait for the done file
142 done=waitonlock(md);
[17806]143 if md.verbose.solution,
144 disp('loading results from cluster');
145 end
[15396]146 md=loadresultsfromcluster(md);
147elseif md.settings.waitonlock==0,
148 disp('Model results must be loaded manually with md=loadresultsfromcluster(md);');
[12363]149end
[12351]150
[12363]151%post processes qmu results if necessary
152if md.qmu.isdakota,
[17806]153 if ~strncmpi(getfieldvalue(options,'keep','y'),'y',1)
[12363]154 system(['rm -rf qmu' num2str(feature('GetPid'))]);
[12351]155 end
[961]156end
Note: See TracBrowser for help on using the repository browser.