source: issm/trunk-jpl/src/m/classes/SMBforcing.py@ 26358

Last change on this file since 26358 was 26358, checked in by jdquinn, 4 years ago

CHG: Completed MATLAB -> Python updates for SE; archive updates now that GMSH can be used on macOS and Linux; various minor bug fixes; formatting; cleanup

File size: 3.5 KB
Line 
1import numpy as np
2
3from checkfield import checkfield
4from fielddisplay import fielddisplay
5from project3d import project3d
6from WriteData import WriteData
7
8
9class SMBforcing(object):
10 """SMBFORCING class definition
11
12 Usage:
13 SMB = SMBforcing()
14 """
15
16 def __init__(self, *args): # {{{
17 self.mass_balance = np.nan
18 self.steps_per_step = 1
19 self.requested_outputs = []
20 self.averaging = 0
21 self.isclimatology = np.nan
22
23 nargs = len(args)
24 if nargs == 0:
25 pass
26 else:
27 raise Exception('constructor not supported')
28 #}}}
29
30 def __repr__(self): # {{{
31 s = ' surface forcings parameters:\n'
32 s += '{}\n'.format(fielddisplay(self, 'mass_balance', 'surface mass balance [m/yr ice eq]'))
33 s += '{}\n'.format(fielddisplay(self, 'steps_per_step', 'number of smb steps per time step'))
34 s += '{}\n'.format(fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
35 s += '{}\n'.format(fielddisplay(self, 'averaging', 'averaging methods from short to long steps'))
36 s += '\t\t{}\n'.format('0: Arithmetic (default)')
37 s += '\t\t{}\n'.format('1: Geometric')
38 s += '\t\t{}\n'.format('2: Harmonic')
39 return s
40 #}}}
41
42 def extrude(self, md): # {{{
43 self.mass_balance = project3d(md, 'vector', self.mass_balance, 'type', 'node')
44 return self
45 #}}}
46
47 def defaultoutputs(self, md): # {{{
48 return []
49 #}}}
50
51 def initialize(self, md): # {{{
52 if np.all(np.isnan(self.mass_balance)):
53 self.mass_balance = np.zeros((md.mesh.numberofvertices))
54 print(" no smb.mass_balance specified: values set as zero")
55 return self
56 #}}}
57
58 def checkconsistency(self, md, solution, analyses): # {{{
59 if solution == 'TransientSolution' and not md.transient.issmb:
60 return
61 if 'MasstransportAnalysis' in analyses:
62 md = checkfield(md, 'fieldname', 'smb.mass_balance', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
63 if 'BalancethicknessAnalysis' in analyses:
64 md = checkfield(md, 'fieldname', 'smb.mass_balance', 'size', [md.mesh.numberofvertices], 'NaN', 1, 'Inf', 1)
65 md = checkfield(md, 'fieldname', 'smb.steps_per_step', '>=', 1, 'numel', [1])
66 md = checkfield(md, 'fieldname', 'smb.averaging', 'numel', [1], 'values', [0, 1, 2])
67 md = checkfield(md, 'fieldname', 'masstransport.requested_outputs', 'stringrow', 1)
68 return md
69 # }}}
70
71 def marshall(self, prefix, md, fid): # {{{
72 yts = md.constants.yts
73 WriteData(fid, prefix, 'name', 'md.smb.model', 'data', 1, 'format', 'Integer')
74 WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'mass_balance', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1 / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
75 WriteData(fid, prefix, 'object', self, 'fieldname', 'steps_per_step', 'format', 'Integer')
76 WriteData(fid, prefix, 'object', self, 'fieldname', 'averaging', 'format', 'Integer')
77
78 #process requested outputs
79 outputs = self.requested_outputs
80 indices = [i for i, x in enumerate(outputs) if x == 'default']
81 if len(indices) > 0:
82 outputscopy = outputs[0:max(0, indices[0] - 1)] + self.defaultoutputs(md) + outputs[indices[0] + 1:]
83 outputs = outputscopy
84 WriteData(fid, prefix, 'data', outputs, 'name', 'md.smb.requested_outputs', 'format', 'StringArray')
85 # }}}
Note: See TracBrowser for help on using the repository browser.