1 | import datetime
|
---|
2 | import os
|
---|
3 | import shutil
|
---|
4 |
|
---|
5 | def solve(md,solutionenum,*args):
|
---|
6 | """
|
---|
7 | SOLVE - apply solution sequence for this model
|
---|
8 |
|
---|
9 | Usage:
|
---|
10 | md=solve(md,solutionenum,varargin)
|
---|
11 | where varargin is a list of paired arguments of string OR enums
|
---|
12 |
|
---|
13 | solution types available comprise:
|
---|
14 | - DiagnosticSolutionEnum
|
---|
15 | - PrognosticSolutionEnum
|
---|
16 | - ThermalSolutionEnum
|
---|
17 | - SteadystateSolutionEnum
|
---|
18 | - TransientSolutionEnum...
|
---|
19 | - BalancethicknessSolutionEnum
|
---|
20 | - BedSlopeSolutionEnum
|
---|
21 | - SurfaceSlopeSolutionEnum
|
---|
22 | - HydrologySolutionEnum
|
---|
23 | - FlaimSolutionEnum
|
---|
24 |
|
---|
25 | extra options:
|
---|
26 | - loadonly : does not solve. only load results
|
---|
27 |
|
---|
28 | Examples:
|
---|
29 | md=solve(md,DiagnosticSolutionEnum);
|
---|
30 | """
|
---|
31 |
|
---|
32 | #recover and process solve options
|
---|
33 | options=pairoptions('solution_type',solutionenum,*args)
|
---|
34 | options=process_solve_options(options)
|
---|
35 |
|
---|
36 | #recover some fields
|
---|
37 | md.private.solution=options['solution_type']
|
---|
38 | cluster=md.cluster
|
---|
39 |
|
---|
40 | #check model consistency
|
---|
41 | print "checking model consistency"
|
---|
42 | if solutionenum == FlaimSolutionEnum:
|
---|
43 | md.private.isconsistent=True
|
---|
44 | md.mesh.checkconsistency(md,solutionenum)
|
---|
45 | md.flaim.checkconsistency(md,solutionenum)
|
---|
46 | if not md.private.isconsistent:
|
---|
47 | raise RuntimeError("Model not consistent, see messages above.")
|
---|
48 | else:
|
---|
49 | ismodelselfconsistent(md)
|
---|
50 |
|
---|
51 | #First, build a runtime name that is unique
|
---|
52 | c=datetime.datetime.now()
|
---|
53 | md.private.runtimename="%s-%02i-%02i-%04i-%02i-%02i-%02i-%i" % (md.miscellaneous.name,c.month,c.day,c.year,c.hour,c.minute,c.second,os.getpid())
|
---|
54 |
|
---|
55 | #if running qmu analysis, some preprocessing of dakota files using models
|
---|
56 | #fields needs to be carried out.
|
---|
57 | if md.qmu.isdakota:
|
---|
58 | md=preqmu(md,options)
|
---|
59 |
|
---|
60 | #flaim analysis
|
---|
61 | if options['solution_type'] == FlaimSolutionEnum:
|
---|
62 | md=flaim_sol(md,options)
|
---|
63 | md.private.solution=EnumToString(options['solution_type'])
|
---|
64 | return md
|
---|
65 |
|
---|
66 | #Do we load results only?
|
---|
67 | if options['loadonly']:
|
---|
68 | md=loadresultsfromcluster(md)
|
---|
69 | return md
|
---|
70 |
|
---|
71 | #Wite all input files
|
---|
72 | marshall(md) # bin file
|
---|
73 | md.solver.PetscFile(md.miscellaneous.name+'.petsc') # petsc file
|
---|
74 | cluster.BuildQueueScript(md.miscellaneous.name,md.private.runtimename,md.private.solution,md.settings.io_gather,md.debug.valgrind,md.debug.gprof) # queue file
|
---|
75 |
|
---|
76 | #we need to make sure we have PETSC support, otherwise, we run with only one cpu:
|
---|
77 | if not ispetsc:
|
---|
78 | print "PETSC support not included, running on 1 cpu only!"
|
---|
79 | cluster.np=1
|
---|
80 |
|
---|
81 | #Stop here if batch mode
|
---|
82 | if strcmpi(options['batch'],'yes'):
|
---|
83 | print 'batch mode requested: not launching job interactively'
|
---|
84 | print 'launch solution sequence on remote cluster by hand'
|
---|
85 | return md
|
---|
86 |
|
---|
87 | #Launch job
|
---|
88 | modelname = md.miscellaneous.name
|
---|
89 | filelist = [modelname+'.bin ',modelname+'.petsc ',modelname+'.queue ']
|
---|
90 | if md.qmu.isdakota:
|
---|
91 | filelist.append(modelname+'.qmu.in')
|
---|
92 | cluster.LaunchQueueJob(md.miscellaneous.name,md.private.runtimename,filelist)
|
---|
93 |
|
---|
94 | #did we even try to run? if so, wait on lock
|
---|
95 | if strcmpi(options['upload'],'on'):
|
---|
96 | print 'solve done uploading test decks'
|
---|
97 | return md
|
---|
98 |
|
---|
99 | #wait on lock
|
---|
100 | if md.settings.waitonlock>0:
|
---|
101 | #we wait for the done file
|
---|
102 | islock=waitonlock(md)
|
---|
103 | if islock==0: #no results to be loaded
|
---|
104 | print 'The results must be loaded manually with md=loadresultsfromcluster(md).'
|
---|
105 | else: #load results
|
---|
106 | print 'loading results from cluster'
|
---|
107 | md=loadresultsfromcluster(md)
|
---|
108 |
|
---|
109 | #post processes qmu results if necessary
|
---|
110 | if md.qmu.isdakota:
|
---|
111 | if not strncmpi(options['keep'],'y',1):
|
---|
112 | shutil.rmtree('qmu'+str(os.getpid()))
|
---|
113 |
|
---|
114 | return md
|
---|
115 |
|
---|