source: issm/trunk/src/m/classes/SMBgradients.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.0 KB
Line 
1from fielddisplay import fielddisplay
2from checkfield import checkfield
3from WriteData import WriteData
4
5
6class SMBgradients(object):
7 """
8 SMBgradients Class definition
9
10 Usage:
11 SMBgradients = SMBgradients();
12 """
13
14 def __init__(self): # {{{
15 self.href = float('NaN')
16 self.smbref = float('NaN')
17 self.b_pos = float('NaN')
18 self.b_neg = float('NaN')
19 self.steps_per_step = 1
20 self.requested_outputs = []
21 #}}}
22
23 def __repr__(self): # {{{
24 string = " surface forcings parameters:"
25
26 string = "%s\n%s" % (string, fielddisplay(self, 'issmbgradients', 'is smb gradients method activated (0 or 1, default is 0)'))
27 string = "%s\n%s" % (string, fielddisplay(self, 'href', ' reference elevation from which deviation is used to calculate SMB adjustment in smb gradients method'))
28 string = "%s\n%s" % (string, fielddisplay(self, 'smbref', ' reference smb from which deviation is calculated in smb gradients method'))
29 string = "%s\n%s" % (string, fielddisplay(self, 'b_pos', ' slope of hs - smb regression line for accumulation regime required if smb gradients is activated'))
30 string = "%s\n%s" % (string, fielddisplay(self, 'b_neg', ' slope of hs - smb regression line for ablation regime required if smb gradients is activated'))
31 string = "%s\n%s" % (string, fielddisplay(self, 'steps_per_step', 'number of smb steps per time step'))
32 string = "%s\n%s" % (string, fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
33
34 return string
35 #}}}
36
37 def extrude(self, md): # {{{
38 #Nothing for now
39 return self
40 #}}}
41
42 def defaultoutputs(self, md): # {{{
43 return []
44 #}}}
45
46 def initialize(self, md): # {{{
47 #Nothing for now
48 return self
49 #}}}
50
51 def checkconsistency(self, md, solution, analyses): # {{{
52 if 'MasstransportAnalysis' in analyses:
53 md = checkfield(md, 'fieldname', 'smb.href', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
54 md = checkfield(md, 'fieldname', 'smb.smbref', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
55 md = checkfield(md, 'fieldname', 'smb.b_pos', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
56 md = checkfield(md, 'fieldname', 'smb.b_neg', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
57
58 md = checkfield(md, 'fieldname', 'smb.steps_per_step', '>=', 1, 'numel', [1])
59 md = checkfield(md, 'fieldname', 'masstransport.requested_outputs', 'stringrow', 1)
60 return md
61 # }}}
62
63 def marshall(self, prefix, md, fid): # {{{
64 yts = md.constants.yts
65
66 WriteData(fid, prefix, 'name', 'md.smb.model', 'data', 6, 'format', 'Integer')
67 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'href', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
68 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'smbref', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
69 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_pos', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
70 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_neg', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
71 WriteData(fid, prefix, 'object', self, 'fieldname', 'steps_per_step', 'format', 'Integer')
72
73 #process requested outputs
74 outputs = self.requested_outputs
75 indices = [i for i, x in enumerate(outputs) if x == 'default']
76 if len(indices) > 0:
77 outputscopy = outputs[0:max(0, indices[0] - 1)] + self.defaultoutputs(md) + outputs[indices[0] + 1:]
78 outputs = outputscopy
79 WriteData(fid, prefix, 'data', outputs, 'name', 'md.smb.requested_outputs', 'format', 'StringArray')
80
81 # }}}
Note: See TracBrowser for help on using the repository browser.