source: issm/branches/trunk-larour-NatGeoScience2016/src/m/classes/SMBd18opdd.py@ 21243

Last change on this file since 21243 was 21049, checked in by agscott1, 9 years ago

CHG: Replaced Enums with Strings in matlab and python. Updated corresponding cpp code.

File size: 6.6 KB
Line 
1import numpy
2from fielddisplay import fielddisplay
3from checkfield import checkfield
4from WriteData import WriteData
5from project3d import project3d
6
7class SMBd18opdd(object):
8 """
9 SMBd18opdd Class definition
10
11 Usage:
12 SMBd18opdd=SMBd18opdd();
13 """
14
15 def __init__(self): # {{{
16 self.desfac = 0.
17 self.s0p = float('NaN')
18 self.s0t = float('NaN')
19 self.rlaps = 0.
20 self.rlapslgm = 0.
21 self.dpermil = 0.
22 self.Tdiff = float('NaN')
23 self.sealev = float('NaN')
24 self.ismungsm = 0
25 self.isd18opd = 0
26 self.delta18o = float('NaN')
27 self.delta18o_surface = float('NaN')
28 self.temperatures_presentday = float('NaN')
29 self.precipitations_presentday = float('NaN')
30
31 #set defaults
32 self.setdefaultparameters()
33 self.requested_outputs = []
34 #}}}
35 def __repr__(self): # {{{
36 string=" surface forcings parameters:"
37
38 string="%s\n%s"%(string,fielddisplay(self,'isd18opd','is delta18o parametrisation from present day temperature and precipitation activated (0 or 1, default is 0)'))
39 string="%s\n%s"%(string,fielddisplay(self,'desfac','desertification elevation factor (between 0 and 1, default is 0.5) [m]'))
40 string="%s\n%s"%(string,fielddisplay(self,'s0p','should be set to elevation from precip source (between 0 and a few 1000s m, default is 0) [m]'))
41 string="%s\n%s"%(string,fielddisplay(self,'s0t','should be set to elevation from temperature source (between 0 and a few 1000s m, default is 0) [m]'))
42 string="%s\n%s"%(string,fielddisplay(self,'rlaps','present day lapse rate [degree/km]'))
43 if self.isd18opd:
44 string="%s\n%s"%(string,fielddisplay(self,'temperatures_presentday','monthly present day surface temperatures [K], required if delta18o/mungsm is activated'))
45 string="%s\n%s"%(string,fielddisplay(self,'precipitations_presentday','monthly surface precipitation [m/yr water eq], required if delta18o or mungsm is activated'))
46 string="%s\n%s"%(string,fielddisplay(self,'delta18o','delta18o [per mil], required if pdd is activated and delta18o activated'))
47 string="%s\n%s"%(string,fielddisplay(self,'dpermil','degree per mil, required if d18opd is activated'))
48 string="%s\n%s"%(string,fielddisplay(self,'requested_outputs','additional outputs requested'))
49
50 return string
51 #}}}
52 def extrude(self,md): # {{{
53
54 if self.isd18opd: self.temperatures_presentday=project3d(md,'vector',self.temperatures_presentday,'type','node')
55 if self.isd18opd: self.precipitations_presentday=project3d(md,'vector',self.precipitations_presentday,'type','node')
56 self.s0p=project3d(md,'vector',self.s0p,'type','node')
57 self.s0t=project3d(md,'vector',self.s0t,'type','node')
58
59 return self
60 #}}}
61 def defaultoutputs(self,md): # {{{
62 return []
63 #}}}
64 def initialize(self,md): # {{{
65
66 if numpy.all(numpy.isnan(self.s0p)):
67 self.s0p=numpy.zeros((md.mesh.numberofvertices,1))
68 print " no SMBd18opdd.s0p specified: values set as zero"
69
70 if numpy.all(numpy.isnan(self.s0t)):
71 self.s0t=numpy.zeros((md.mesh.numberofvertices,1))
72 print " no SMBd18opdd.s0t specified: values set as zero"
73
74 return self
75 # }}}
76 def setdefaultparameters(self): # {{{
77
78 #pdd method not used in default mode
79 self.ismungsm = 0
80 self.isd18opd = 1
81 self.desfac = 0.5
82 self.rlaps = 6.5
83 self.rlapslgm = 6.5
84 self.dpermil = 2.4
85
86 return self
87 #}}}
88 def checkconsistency(self,md,solution,analyses): # {{{
89
90 if 'MasstransportAnalysis' in analyses:
91 md = checkfield(md,'fieldname','smb.desfac','<=',1,'numel',[1])
92 md = checkfield(md,'fieldname','smb.s0p','>=',0,'NaN',1,'Inf',1,'size',[md.mesh.numberofvertices,1])
93 md = checkfield(md,'fieldname','smb.s0t','>=',0,'NaN',1,'Inf',1,'size',[md.mesh.numberofvertices,1])
94 md = checkfield(md,'fieldname','smb.rlaps','>=',0,'numel',[1])
95 md = checkfield(md,'fieldname','smb.rlapslgm','>=',0,'numel',[1])
96
97 if self.isd18opd:
98 md = checkfield(md,'fieldname','smb.temperatures_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1,'Inf',1,'timeseries',1)
99 md = checkfield(md,'fieldname','smb.precipitations_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1,'Inf',1,'timeseries',1)
100 md = checkfield(md,'fieldname','smb.delta18o','NaN',1,'Inf',1,'size',[2,numpy.nan],'singletimeseries',1)
101 md = checkfield(md,'fieldname','smb.dpermil','>=',0,'numel',[1])
102
103 md = checkfield(md,'fieldname','masstransport.requested_outputs','stringrow',1)
104
105 return md
106 # }}}
107 def marshall(self,prefix,md,fid): # {{{
108
109 yts=md.constants.yts
110
111 WriteData(fid,prefix,'name','md.smb.model','data',5,'format','Integer')
112
113 WriteData(fid,prefix,'object',self,'class','smb','fieldname','ismungsm','format','Boolean')
114 WriteData(fid,prefix,'object',self,'class','smb','fieldname','isd18opd','format','Boolean')
115 WriteData(fid,prefix,'object',self,'class','smb','fieldname','desfac','format','Double')
116 WriteData(fid,prefix,'object',self,'class','smb','fieldname','s0p','format','DoubleMat','mattype',1);
117 WriteData(fid,prefix,'object',self,'class','smb','fieldname','s0t','format','DoubleMat','mattype',1);
118 WriteData(fid,prefix,'object',self,'class','smb','fieldname','rlaps','format','Double')
119 WriteData(fid,prefix,'object',self,'class','smb','fieldname','rlapslgm','format','Double')
120 WriteData(fid,prefix,'object',self,'class','smb','fieldname','Tdiff','format','DoubleMat','mattype',1,'timeserieslength',2,'yts',md.constants.yts)
121 WriteData(fid,prefix,'object',self,'class','smb','fieldname','sealev','format','DoubleMat','mattype',1,'timeserieslength',2,'yts',md.constants.yts)
122
123 if self.isd18opd:
124 WriteData(fid,prefix,'object',self,'class','smb','fieldname','temperatures_presentday','format','DoubleMat','mattype',1,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts)
125 WriteData(fid,prefix,'object',self,'class','smb','fieldname','precipitations_presentday','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts)
126 WriteData(fid,prefix,'object',self,'class','smb','fieldname','delta18o','format','DoubleMat','mattype',1,'timeserieslength',2,'yts',md.constants.yts)
127 WriteData(fid,prefix,'object',self,'class','smb','fieldname','dpermil','format','Double')
128
129 #process requested outputs
130 outputs = self.requested_outputs
131 indices = [i for i, x in enumerate(outputs) if x == 'default']
132 if len(indices) > 0:
133 outputscopy=outputs[0:max(0,indices[0]-1)]+self.defaultoutputs(md)+outputs[indices[0]+1:]
134 outputs =outputscopy
135 WriteData(fid,prefix,'data',outputs,'name','md.smb.requested_outputs','format','StringArray')
136
137 # }}}
Note: See TracBrowser for help on using the repository browser.