[8296] | 1 | function 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
|
---|
| 13 | % - TransientSolutionEnum...
|
---|
| 14 | % - BalancethicknessSolutionEnum
|
---|
| 15 | % - BedSlopeSolutionEnum
|
---|
| 16 | % - SurfaceSlopeSolutionEnum
|
---|
| 17 | % - HydrologySolutionEnum
|
---|
| 18 | % - FlaimSolutionEnum
|
---|
[8343] | 19 | %
|
---|
[9428] | 20 | % extra options:
|
---|
| 21 | % - loadonly : does not solve. only load results
|
---|
| 22 | %
|
---|
[1] | 23 | % Examples:
|
---|
[16137] | 24 | % md=solve(md,StressbalanceSolutionEnum);
|
---|
[1] | 25 |
|
---|
[12351] | 26 | %recover and process solve options
|
---|
[8296] | 27 | options=pairoptions(varargin{:},'solution_type',solutionenum);
|
---|
[465] | 28 | options=process_solve_options(options);
|
---|
[1] | 29 |
|
---|
[465] | 30 | %recover some fields
|
---|
[9614] | 31 | md.private.solution=options.solution_type;
|
---|
[12363] | 32 | cluster=md.cluster;
|
---|
[1] | 33 |
|
---|
[2326] | 34 | %check model consistency
|
---|
[6304] | 35 | disp('checking model consistency');
|
---|
[13043] | 36 | if (solutionenum == FlaimSolutionEnum())
|
---|
[12673] | 37 | md.private.isconsistent=true;
|
---|
| 38 | md=checkconsistency(md.mesh,md,solutionenum);
|
---|
| 39 | md=checkconsistency(md.flaim,md,solutionenum);
|
---|
| 40 | if md.private.isconsistent==false,
|
---|
| 41 | error('Model not consistent, see messages above');
|
---|
[9882] | 42 | end
|
---|
| 43 | else
|
---|
| 44 | ismodelselfconsistent(md),
|
---|
| 45 | end
|
---|
[132] | 46 |
|
---|
[12363] | 47 | %First, build a runtime name that is unique
|
---|
| 48 | c=clock;
|
---|
| 49 | 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'));
|
---|
| 50 |
|
---|
[12351] | 51 | %if running qmu analysis, some preprocessing of dakota files using models
|
---|
| 52 | %fields needs to be carried out.
|
---|
[9650] | 53 | if md.qmu.isdakota,
|
---|
[961] | 54 | md=preqmu(md,options);
|
---|
| 55 | end
|
---|
[2540] | 56 |
|
---|
[7686] | 57 | %flaim analysis
|
---|
[13043] | 58 | if (options.solution_type == FlaimSolutionEnum())
|
---|
[9882] | 59 | md=flaim_sol(md,options);
|
---|
[9614] | 60 | md.private.solution=EnumToString(options.solution_type);
|
---|
[7686] | 61 | return;
|
---|
| 62 | end
|
---|
| 63 |
|
---|
[12351] | 64 | %Do we load results only?
|
---|
| 65 | if options.loadonly,
|
---|
| 66 | md=loadresultsfromcluster(md);
|
---|
| 67 | return;
|
---|
| 68 | end
|
---|
[8330] | 69 |
|
---|
[13043] | 70 | %Write all input files
|
---|
[12988] | 71 | marshall(md); % bin file
|
---|
[15396] | 72 | ToolkitsFile(md.toolkits,[md.miscellaneous.name '.toolkits']); % toolkits file
|
---|
[12988] | 73 | BuildQueueScript(cluster,md.private.runtimename,md.miscellaneous.name,md.private.solution,md.settings.io_gather,md.debug.valgrind,md.debug.gprof); % queue file
|
---|
| 74 |
|
---|
[12363] | 75 | %Stop here if batch mode
|
---|
| 76 | if strcmpi(options.batch,'yes')
|
---|
| 77 | disp('batch mode requested: not launching job interactively');
|
---|
| 78 | disp('launch solution sequence on remote cluster by hand');
|
---|
| 79 | return;
|
---|
| 80 | end
|
---|
[1] | 81 |
|
---|
[12363] | 82 | %Launch job
|
---|
| 83 | modelname = md.miscellaneous.name;
|
---|
[15396] | 84 | filelist = {[modelname '.bin '] [modelname '.toolkits ']};
|
---|
| 85 | if ispc,
|
---|
| 86 | filelist{end+1}=[modelname '.bat '];
|
---|
| 87 | else
|
---|
| 88 | filelist{end+1}=[modelname '.queue '];
|
---|
| 89 | end
|
---|
| 90 |
|
---|
[12363] | 91 | if md.qmu.isdakota,
|
---|
| 92 | filelist{end+1} = [modelname '.qmu.in'];
|
---|
| 93 | end
|
---|
| 94 | LaunchQueueJob(cluster,md.miscellaneous.name,md.private.runtimename,filelist);
|
---|
[12351] | 95 |
|
---|
[12363] | 96 | %did we even try to run? if so, wait on lock
|
---|
| 97 | if strcmpi(options.upload,'on'),
|
---|
| 98 | disp('solve done uploading test decks');
|
---|
| 99 | return;
|
---|
| 100 | end
|
---|
[12351] | 101 |
|
---|
[12363] | 102 | %wait on lock
|
---|
[15396] | 103 | if isnan(md.settings.waitonlock),
|
---|
| 104 | %load when user enters 'y'
|
---|
| 105 | disp('solution launched on remote cluster. log in to detect job completion.');
|
---|
| 106 | choice=input('Is the job successfully completed? (y/n)','s');
|
---|
| 107 | if ~strcmp(choice,'y'),
|
---|
| 108 | disp('Results not loaded... exiting');
|
---|
| 109 | else
|
---|
[12363] | 110 | md=loadresultsfromcluster(md);
|
---|
[6569] | 111 | end
|
---|
[15396] | 112 | elseif md.settings.waitonlock>0,
|
---|
| 113 | %we wait for the done file
|
---|
| 114 | done=waitonlock(md);
|
---|
| 115 | disp('loading results from cluster');
|
---|
| 116 | md=loadresultsfromcluster(md);
|
---|
| 117 | elseif md.settings.waitonlock==0,
|
---|
| 118 | disp('Model results must be loaded manually with md=loadresultsfromcluster(md);');
|
---|
[12363] | 119 | end
|
---|
[12351] | 120 |
|
---|
[12363] | 121 | %post processes qmu results if necessary
|
---|
| 122 | if md.qmu.isdakota,
|
---|
| 123 | if ~strncmpi(options.keep,'y',1)
|
---|
| 124 | system(['rm -rf qmu' num2str(feature('GetPid'))]);
|
---|
[12351] | 125 | end
|
---|
[961] | 126 | end
|
---|