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