1 | function 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 | % - DiagnosticSolutionEnum
|
---|
10 | % - PrognosticSolutionEnum
|
---|
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 | %
|
---|
23 | % Examples:
|
---|
24 | % md=solve(md,DiagnosticSolutionEnum);
|
---|
25 |
|
---|
26 | %recover and process solve options
|
---|
27 | options=pairoptions(varargin{:},'solution_type',solutionenum);
|
---|
28 | options=process_solve_options(options);
|
---|
29 |
|
---|
30 | %recover some fields
|
---|
31 | md.private.solution=options.solution_type;
|
---|
32 | cluster=md.cluster;
|
---|
33 |
|
---|
34 | %check model consistency
|
---|
35 | disp('checking model consistency');
|
---|
36 | if (solutionenum == FlaimSolutionEnum())
|
---|
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');
|
---|
42 | end
|
---|
43 | else
|
---|
44 | ismodelselfconsistent(md),
|
---|
45 | end
|
---|
46 |
|
---|
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 |
|
---|
51 | %if running qmu analysis, some preprocessing of dakota files using models
|
---|
52 | %fields needs to be carried out.
|
---|
53 | if md.qmu.isdakota,
|
---|
54 | md=preqmu(md,options);
|
---|
55 | end
|
---|
56 |
|
---|
57 | %flaim analysis
|
---|
58 | if (options.solution_type == FlaimSolutionEnum())
|
---|
59 | md=flaim_sol(md,options);
|
---|
60 | md.private.solution=EnumToString(options.solution_type);
|
---|
61 | return;
|
---|
62 | end
|
---|
63 |
|
---|
64 | %Do we load results only?
|
---|
65 | if options.loadonly,
|
---|
66 | md=loadresultsfromcluster(md);
|
---|
67 | return;
|
---|
68 | end
|
---|
69 |
|
---|
70 | %we need to make sure we have PETSC support, otherwise, we run with only one cpu:
|
---|
71 | if ~ispetsc(),
|
---|
72 | disp('PETSc support not included, running on 1 cpu only!');
|
---|
73 | cluster.np=1;
|
---|
74 | end
|
---|
75 |
|
---|
76 |
|
---|
77 | %Write all input files
|
---|
78 | marshall(md); % bin file
|
---|
79 | PetscFile(md.solver,[md.miscellaneous.name '.petsc']); % petsc file
|
---|
80 | BuildQueueScript(cluster,md.private.runtimename,md.miscellaneous.name,md.private.solution,md.settings.io_gather,md.debug.valgrind,md.debug.gprof); % queue file
|
---|
81 |
|
---|
82 |
|
---|
83 | %Stop here if batch mode
|
---|
84 | if strcmpi(options.batch,'yes')
|
---|
85 | disp('batch mode requested: not launching job interactively');
|
---|
86 | disp('launch solution sequence on remote cluster by hand');
|
---|
87 | return;
|
---|
88 | end
|
---|
89 |
|
---|
90 | %Launch job
|
---|
91 | modelname = md.miscellaneous.name;
|
---|
92 | filelist = {[modelname '.bin '] [modelname '.petsc '] [modelname '.queue ']};
|
---|
93 | if md.qmu.isdakota,
|
---|
94 | filelist{end+1} = [modelname '.qmu.in'];
|
---|
95 | end
|
---|
96 | LaunchQueueJob(cluster,md.miscellaneous.name,md.private.runtimename,filelist);
|
---|
97 |
|
---|
98 | %did we even try to run? if so, wait on lock
|
---|
99 | if strcmpi(options.upload,'on'),
|
---|
100 | disp('solve done uploading test decks');
|
---|
101 | return;
|
---|
102 | end
|
---|
103 |
|
---|
104 | %wait on lock
|
---|
105 | if md.settings.waitonlock>0,
|
---|
106 | %we wait for the done file
|
---|
107 | islock=waitonlock(md);
|
---|
108 | if islock==0, %no results to be loaded
|
---|
109 | disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
|
---|
110 | else %load results
|
---|
111 | disp('loading results from cluster');
|
---|
112 | md=loadresultsfromcluster(md);
|
---|
113 | end
|
---|
114 | end
|
---|
115 |
|
---|
116 | %post processes qmu results if necessary
|
---|
117 | if md.qmu.isdakota,
|
---|
118 | if ~strncmpi(options.keep,'y',1)
|
---|
119 | system(['rm -rf qmu' num2str(feature('GetPid'))]);
|
---|
120 | end
|
---|
121 | end
|
---|