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