| 1 | import numpy
|
|---|
| 2 | from fielddisplay import fielddisplay
|
|---|
| 3 | from EnumDefinitions import *
|
|---|
| 4 | from checkfield import checkfield
|
|---|
| 5 | from WriteData import WriteData
|
|---|
| 6 | from project3d import project3d
|
|---|
| 7 |
|
|---|
| 8 | class SMBforcing(object):
|
|---|
| 9 | """
|
|---|
| 10 | SMBforcing Class definition
|
|---|
| 11 |
|
|---|
| 12 | Usage:
|
|---|
| 13 | SMB=SMBforcing();
|
|---|
| 14 | """
|
|---|
| 15 |
|
|---|
| 16 | def __init__(self): # {{{
|
|---|
| 17 | self.mass_balance = float('NaN')
|
|---|
| 18 | self.requested_outputs = []
|
|---|
| 19 | #}}}
|
|---|
| 20 | def __repr__(self): # {{{
|
|---|
| 21 | string=" surface forcings parameters:"
|
|---|
| 22 | string="%s\n%s"%(string,fielddisplay(self,'mass_balance','surface mass balance [m/yr ice eq]'))
|
|---|
| 23 | string="%s\n%s"%(string,fielddisplay(self,'requested_outputs','additional outputs requested'))
|
|---|
| 24 | return string
|
|---|
| 25 | #}}}
|
|---|
| 26 | def extrude(self,md): # {{{
|
|---|
| 27 |
|
|---|
| 28 | self.mass_balance=project3d(md,'vector',self.mass_balance,'type','node');
|
|---|
| 29 | return self
|
|---|
| 30 | #}}}
|
|---|
| 31 | def defaultoutputs(self,md): # {{{
|
|---|
| 32 | return []
|
|---|
| 33 | #}}}
|
|---|
| 34 | def initialize(self,md): # {{{
|
|---|
| 35 |
|
|---|
| 36 | if numpy.all(numpy.isnan(self.mass_balance)):
|
|---|
| 37 | self.mass_balance=numpy.zeros((md.mesh.numberofvertices,1))
|
|---|
| 38 | print " no SMBforcing.mass_balance specified: values set as zero"
|
|---|
| 39 |
|
|---|
| 40 | return self
|
|---|
| 41 | #}}}
|
|---|
| 42 | def checkconsistency(self,md,solution,analyses): # {{{
|
|---|
| 43 |
|
|---|
| 44 | if MasstransportAnalysisEnum() in analyses:
|
|---|
| 45 | md = checkfield(md,'fieldname','smb.mass_balance','timeseries',1,'NaN',1,'Inf',1)
|
|---|
| 46 |
|
|---|
| 47 | if BalancethicknessAnalysisEnum() in analyses:
|
|---|
| 48 | md = checkfield(md,'fieldname','smb.mass_balance','size',[md.mesh.numberofvertices],'NaN',1,'Inf',1)
|
|---|
| 49 |
|
|---|
| 50 | md = checkfield(md,'fieldname','masstransport.requested_outputs','stringrow',1)
|
|---|
| 51 | return md
|
|---|
| 52 | # }}}
|
|---|
| 53 | def marshall(self,prefix,md,fid): # {{{
|
|---|
| 54 |
|
|---|
| 55 | yts=md.constants.yts
|
|---|
| 56 |
|
|---|
| 57 | WriteData(fid,prefix,'name','md.smb.model','data',1,'format','Integer');
|
|---|
| 58 | WriteData(fid,prefix,'object',self,'class','smb','fieldname','mass_balance','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts)
|
|---|
| 59 |
|
|---|
| 60 | #process requested outputs
|
|---|
| 61 | outputs = self.requested_outputs
|
|---|
| 62 | indices = [i for i, x in enumerate(outputs) if x == 'default']
|
|---|
| 63 | if len(indices) > 0:
|
|---|
| 64 | outputscopy=outputs[0:max(0,indices[0]-1)]+self.defaultoutputs(md)+outputs[indices[0]+1:]
|
|---|
| 65 | outputs =outputscopy
|
|---|
| 66 | WriteData(fid,prefix,'data',outputs,'name','md.smb.requested_outputs','format','StringArray')
|
|---|
| 67 |
|
|---|
| 68 | # }}}
|
|---|