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

Last change on this file since 21759 was 21759, checked in by Eric.Larour, 8 years ago

CHG: merged branch back to trunk-jpl 21754.

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