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

Last change on this file since 27403 was 27403, checked in by Mathieu Morlighem, 2 years ago

CHG: moved SmbMassBalance from transient requested outputs to SMB classes, as it should be

File size: 3.5 KB
RevLine 
[21303]1import numpy as np
[25688]2
3from checkfield import checkfield
[19527]4from fielddisplay import fielddisplay
[25688]5from project3d import project3d
[19527]6from WriteData import WriteData
7
[24213]8
[19527]9class SMBforcing(object):
[25688]10 """SMBFORCING class definition
[19527]11
[25688]12 Usage:
13 SMB = SMBforcing()
[23833]14 """
[19527]15
[25688]16 def __init__(self, *args): # {{{
17 self.mass_balance = np.nan
[24240]18 self.steps_per_step = 1
[25688]19 self.requested_outputs = []
[24793]20 self.averaging = 0
[26358]21 self.isclimatology = np.nan
[25688]22
23 nargs = len(args)
24 if nargs == 0:
25 pass
26 else:
27 raise Exception('constructor not supported')
[24213]28 #}}}
29
30 def __repr__(self): # {{{
[25688]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'))
[26358]34 s += '{}\n'.format(fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
[25688]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
[24213]40 #}}}
[19527]41
[24213]42 def extrude(self, md): # {{{
43 self.mass_balance = project3d(md, 'vector', self.mass_balance, 'type', 'node')
[23833]44 return self
45 #}}}
[24213]46
47 def defaultoutputs(self, md): # {{{
[27403]48 return ['SmbMassBalance']
[23833]49 #}}}
[19527]50
[24213]51 def initialize(self, md): # {{{
[23833]52 if np.all(np.isnan(self.mass_balance)):
[24213]53 self.mass_balance = np.zeros((md.mesh.numberofvertices))
[26358]54 print(" no smb.mass_balance specified: values set as zero")
[23833]55 return self
56 #}}}
[19527]57
[24213]58 def checkconsistency(self, md, solution, analyses): # {{{
[25688]59 if solution == 'TransientSolution' and not md.transient.issmb:
60 return
[23833]61 if 'MasstransportAnalysis' in analyses:
[24213]62 md = checkfield(md, 'fieldname', 'smb.mass_balance', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
[23833]63 if 'BalancethicknessAnalysis' in analyses:
[24213]64 md = checkfield(md, 'fieldname', 'smb.mass_balance', 'size', [md.mesh.numberofvertices], 'NaN', 1, 'Inf', 1)
[24240]65 md = checkfield(md, 'fieldname', 'smb.steps_per_step', '>=', 1, 'numel', [1])
[24793]66 md = checkfield(md, 'fieldname', 'smb.averaging', 'numel', [1], 'values', [0, 1, 2])
[24213]67 md = checkfield(md, 'fieldname', 'masstransport.requested_outputs', 'stringrow', 1)
[23833]68 return md
69 # }}}
[19527]70
[24240]71 def marshall(self, prefix, md, fid): # {{{
[24213]72 yts = md.constants.yts
73 WriteData(fid, prefix, 'name', 'md.smb.model', 'data', 1, 'format', 'Integer')
[26358]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)
[24240]75 WriteData(fid, prefix, 'object', self, 'fieldname', 'steps_per_step', 'format', 'Integer')
[24793]76 WriteData(fid, prefix, 'object', self, 'fieldname', 'averaging', 'format', 'Integer')
[24213]77
[23833]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:
[24213]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')
[23833]85 # }}}
Note: See TracBrowser for help on using the repository browser.