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

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

CHG: cleanup

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
[25688]21
22 nargs = len(args)
23 if nargs == 0:
24 pass
25 else:
26 raise Exception('constructor not supported')
[24213]27 #}}}
28
29 def __repr__(self): # {{{
[25688]30 s = ' surface forcings parameters:\n'
31 s += '{}\n'.format(fielddisplay(self, 'mass_balance', 'surface mass balance [m/yr ice eq]'))
32 s += '{}\n'.format(fielddisplay(self, 'steps_per_step', 'number of smb steps per time step'))
[26358]33 s += '{}\n'.format(fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
[25688]34 s += '{}\n'.format(fielddisplay(self, 'averaging', 'averaging methods from short to long steps'))
35 s += '\t\t{}\n'.format('0: Arithmetic (default)')
36 s += '\t\t{}\n'.format('1: Geometric')
37 s += '\t\t{}\n'.format('2: Harmonic')
38 return s
[24213]39 #}}}
[19527]40
[24213]41 def extrude(self, md): # {{{
42 self.mass_balance = project3d(md, 'vector', self.mass_balance, 'type', 'node')
[23833]43 return self
44 #}}}
[24213]45
46 def defaultoutputs(self, md): # {{{
[27403]47 return ['SmbMassBalance']
[23833]48 #}}}
[19527]49
[24213]50 def initialize(self, md): # {{{
[23833]51 if np.all(np.isnan(self.mass_balance)):
[24213]52 self.mass_balance = np.zeros((md.mesh.numberofvertices))
[26358]53 print(" no smb.mass_balance specified: values set as zero")
[23833]54 return self
55 #}}}
[19527]56
[24213]57 def checkconsistency(self, md, solution, analyses): # {{{
[25688]58 if solution == 'TransientSolution' and not md.transient.issmb:
59 return
[23833]60 if 'MasstransportAnalysis' in analyses:
[24213]61 md = checkfield(md, 'fieldname', 'smb.mass_balance', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
[23833]62 if 'BalancethicknessAnalysis' in analyses:
[24213]63 md = checkfield(md, 'fieldname', 'smb.mass_balance', 'size', [md.mesh.numberofvertices], 'NaN', 1, 'Inf', 1)
[24240]64 md = checkfield(md, 'fieldname', 'smb.steps_per_step', '>=', 1, 'numel', [1])
[24793]65 md = checkfield(md, 'fieldname', 'smb.averaging', 'numel', [1], 'values', [0, 1, 2])
[24213]66 md = checkfield(md, 'fieldname', 'masstransport.requested_outputs', 'stringrow', 1)
[23833]67 return md
68 # }}}
[19527]69
[24240]70 def marshall(self, prefix, md, fid): # {{{
[24213]71 yts = md.constants.yts
72 WriteData(fid, prefix, 'name', 'md.smb.model', 'data', 1, 'format', 'Integer')
[26358]73 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]74 WriteData(fid, prefix, 'object', self, 'fieldname', 'steps_per_step', 'format', 'Integer')
[24793]75 WriteData(fid, prefix, 'object', self, 'fieldname', 'averaging', 'format', 'Integer')
[24213]76
[23833]77 #process requested outputs
78 outputs = self.requested_outputs
79 indices = [i for i, x in enumerate(outputs) if x == 'default']
80 if len(indices) > 0:
[24213]81 outputscopy = outputs[0:max(0, indices[0] - 1)] + self.defaultoutputs(md) + outputs[indices[0] + 1:]
82 outputs = outputscopy
83 WriteData(fid, prefix, 'data', outputs, 'name', 'md.smb.requested_outputs', 'format', 'StringArray')
[23833]84 # }}}
Note: See TracBrowser for help on using the repository browser.