source: issm/trunk/src/m/classes/SMBgradientsela.py@ 24313

Last change on this file since 24313 was 24313, checked in by Mathieu Morlighem, 5 years ago

merged trunk-jpl and trunk for revision 24310

File size: 4.4 KB
Line 
1from fielddisplay import fielddisplay
2from checkfield import checkfield
3from WriteData import WriteData
4
5
6class SMBgradientsela(object):
7 """
8 SMBgradientsela Class definition
9
10 Usage:
11 SMBgradientsela = SMBgradientsela()
12 """
13
14 def __init__(self): # {{{
15 self.ela = float('NaN')
16 self.b_pos = float('NaN')
17 self.b_neg = float('NaN')
18 self.b_max = float('NaN')
19 self.b_min = float('NaN')
20 self.steps_per_step = 1
21 self.requested_outputs = []
22 self.setdefaultparameters()
23 #}}}
24
25 def __repr__(self): # {{{
26 string = " surface forcings parameters:"
27 string += '\n SMB gradients ela parameters:'
28
29 string = "%s\n%s" % (string, fielddisplay(self, 'ela', ' equilibrium line altitude from which deviation is used to calculate smb using the smb gradients ela method [m a.s.l.]'))
30 string = "%s\n%s" % (string, fielddisplay(self, 'b_pos', ' vertical smb gradient (dB/dz) above ela'))
31 string = "%s\n%s" % (string, fielddisplay(self, 'b_neg', ' vertical smb gradient (dB/dz) below ela'))
32 string = "%s\n%s" % (string, fielddisplay(self, 'b_max', ' upper cap on smb rate, default: 9999 (no cap) [m ice eq./yr]'))
33 string = "%s\n%s" % (string, fielddisplay(self, 'b_min', ' lower cap on smb rate, default: -9999 (no cap) [m ice eq./yr]'))
34 string = "%s\n%s" % (string, fielddisplay(self, 'steps_per_step', 'number of smb steps per time step'))
35 string = "%s\n%s" % (string, fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
36 return string
37 #}}}
38
39 def extrude(self, md): # {{{
40 #Nothing for now
41 return self
42 #}}}
43
44 def defaultoutputs(self, md): # {{{
45 return []
46 #}}}
47
48 def initialize(self, md): # {{{
49 #Nothing for now
50 return self
51 #}}}
52
53 def setdefaultparameters(self): # {{{
54 self.b_max = 9999.
55 self.b_min = -9999.
56 return self
57 #}}}
58
59 def checkconsistency(self, md, solution, analyses): # {{{
60 if 'MasstransportAnalysis' in analyses:
61 md = checkfield(md, 'fieldname', 'smb.ela', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
62 md = checkfield(md, 'fieldname', 'smb.b_pos', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
63 md = checkfield(md, 'fieldname', 'smb.b_neg', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
64 md = checkfield(md, 'fieldname', 'smb.b_max', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
65 md = checkfield(md, 'fieldname', 'smb.b_min', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
66
67 md = checkfield(md, 'fieldname', 'smb.steps_per_step', '>=', 1, 'numel', [1])
68 md = checkfield(md, 'fieldname', 'smb.requested_outputs', 'stringrow', 1)
69 return md
70 # }}}
71 def marshall(self, prefix, md, fid): # {{{
72
73 yts = md.constants.yts
74
75 WriteData(fid, prefix, 'name', 'md.smb.model', 'data', 9, 'format', 'Integer')
76 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'ela', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
77 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_pos', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
78 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_neg', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
79 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_max', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
80 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_min', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
81 WriteData(fid, prefix, 'object', self, 'fieldname', 'steps_per_step', 'format', 'Integer')
82
83 #process requested outputs
84 outputs = self.requested_outputs
85 indices = [i for i, x in enumerate(outputs) if x == 'default']
86 if len(indices) > 0:
87 outputscopy = outputs[0:max(0, indices[0] - 1)] + self.defaultoutputs(md) + outputs[indices[0] + 1:]
88 outputs = outputscopy
89 WriteData(fid, prefix, 'data', outputs, 'name', 'md.smb.requested_outputs', 'format', 'StringArray')
90
91 # }}}
Note: See TracBrowser for help on using the repository browser.