1 | import numpy
|
---|
2 | from fielddisplay import fielddisplay
|
---|
3 | from checkfield import checkfield
|
---|
4 | from WriteData import WriteData
|
---|
5 | from project3d import project3d
|
---|
6 |
|
---|
7 | class SMBforcing(object):
|
---|
8 | """
|
---|
9 | SMBforcing Class definition
|
---|
10 |
|
---|
11 | Usage:
|
---|
12 | SMB=SMBforcing();
|
---|
13 | """
|
---|
14 |
|
---|
15 | def __init__(self): # {{{
|
---|
16 | self.mass_balance = float('NaN')
|
---|
17 | self.requested_outputs = []
|
---|
18 | #}}}
|
---|
19 | def __repr__(self): # {{{
|
---|
20 | string=" surface forcings parameters:"
|
---|
21 | string="%s\n%s"%(string,fielddisplay(self,'mass_balance','surface mass balance [m/yr ice eq]'))
|
---|
22 | string="%s\n%s"%(string,fielddisplay(self,'requested_outputs','additional outputs requested'))
|
---|
23 | return string
|
---|
24 | #}}}
|
---|
25 | def extrude(self,md): # {{{
|
---|
26 |
|
---|
27 | self.mass_balance=project3d(md,'vector',self.mass_balance,'type','node');
|
---|
28 | return self
|
---|
29 | #}}}
|
---|
30 | def defaultoutputs(self,md): # {{{
|
---|
31 | return []
|
---|
32 | #}}}
|
---|
33 | def initialize(self,md): # {{{
|
---|
34 |
|
---|
35 | if numpy.all(numpy.isnan(self.mass_balance)):
|
---|
36 | self.mass_balance=numpy.zeros((md.mesh.numberofvertices,1))
|
---|
37 | print " no SMBforcing.mass_balance specified: values set as zero"
|
---|
38 |
|
---|
39 | return self
|
---|
40 | #}}}
|
---|
41 | def checkconsistency(self,md,solution,analyses): # {{{
|
---|
42 |
|
---|
43 | if 'MasstransportAnalysis' in analyses:
|
---|
44 | md = checkfield(md,'fieldname','smb.mass_balance','timeseries',1,'NaN',1,'Inf',1)
|
---|
45 |
|
---|
46 | if 'BalancethicknessAnalysis' in analyses:
|
---|
47 | md = checkfield(md,'fieldname','smb.mass_balance','size',[md.mesh.numberofvertices],'NaN',1,'Inf',1)
|
---|
48 |
|
---|
49 | md = checkfield(md,'fieldname','masstransport.requested_outputs','stringrow',1)
|
---|
50 | return md
|
---|
51 | # }}}
|
---|
52 | def marshall(self,prefix,md,fid): # {{{
|
---|
53 |
|
---|
54 | yts=md.constants.yts
|
---|
55 |
|
---|
56 | WriteData(fid,prefix,'name','md.smb.model','data',1,'format','Integer');
|
---|
57 | WriteData(fid,prefix,'object',self,'class','smb','fieldname','mass_balance','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts)
|
---|
58 |
|
---|
59 | #process requested outputs
|
---|
60 | outputs = self.requested_outputs
|
---|
61 | indices = [i for i, x in enumerate(outputs) if x == 'default']
|
---|
62 | if len(indices) > 0:
|
---|
63 | outputscopy=outputs[0:max(0,indices[0]-1)]+self.defaultoutputs(md)+outputs[indices[0]+1:]
|
---|
64 | outputs =outputscopy
|
---|
65 | WriteData(fid,prefix,'data',outputs,'name','md.smb.requested_outputs','format','StringArray')
|
---|
66 |
|
---|
67 | # }}}
|
---|