source: issm/trunk-jpl/src/m/model/solve.py@ 12755

Last change on this file since 12755 was 12755, checked in by jschierm, 13 years ago

Preliminary python versions of ismodelselfconsistent and solve.

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