source: issm/trunk-jpl/src/c/modules/SurfaceMassBalancex/SurfaceMassBalancex.cpp@ 23066

Last change on this file since 23066 was 23066, checked in by Mathieu Morlighem, 7 years ago

CHG: removing double white lines

File size: 14.4 KB
RevLine 
[17085]1/*!\file SurfaceMassBalancex
2 * \brief: calculates SMB
3 */
4
5#include "./SurfaceMassBalancex.h"
6#include "../../shared/shared.h"
7#include "../../toolkits/toolkits.h"
8
9void SmbGradientsx(FemModel* femmodel){/*{{{*/
10
11 // void SurfaceMassBalancex(hd,agd,ni){
12 // INPUT parameters: ni: working size of arrays
13 // INPUT: surface elevation (m): hd(NA)
14 // OUTPUT: mass-balance (m/yr ice): agd(NA)
[18001]15 int v;
16 IssmDouble rho_water; // density of fresh water
17 IssmDouble rho_ice; // density of ice
[21469]18 IssmDouble yts; // conversion factor year to second
[17085]19
[18001]20 /*Loop over all the elements of this partition*/
[17085]21 for(int i=0;i<femmodel->elements->Size();i++){
[18521]22 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
[18001]23
24 /*Allocate all arrays*/
25 int numvertices = element->GetNumberOfVertices();
26 IssmDouble* Href = xNew<IssmDouble>(numvertices); // reference elevation from which deviations are used to calculate the SMB adjustment
27 IssmDouble* Smbref = xNew<IssmDouble>(numvertices); // reference SMB to which deviations are added
28 IssmDouble* b_pos = xNew<IssmDouble>(numvertices); // Hs-SMB relation parameter
29 IssmDouble* b_neg = xNew<IssmDouble>(numvertices); // Hs-SMB relation paremeter
30 IssmDouble* s = xNew<IssmDouble>(numvertices); // surface elevation (m)
31 IssmDouble* smb = xNew<IssmDouble>(numvertices);
32
33 /*Recover SmbGradients*/
[19527]34 element->GetInputListOnVertices(Href,SmbHrefEnum);
35 element->GetInputListOnVertices(Smbref,SmbSmbrefEnum);
36 element->GetInputListOnVertices(b_pos,SmbBPosEnum);
37 element->GetInputListOnVertices(b_neg,SmbBNegEnum);
[18001]38
[18266]39 /*Recover surface elevation at vertices: */
[18001]40 element->GetInputListOnVertices(s,SurfaceEnum);
41
42 /*Get material parameters :*/
[18946]43 rho_ice=element->matpar->GetMaterialParameter(MaterialsRhoIceEnum);
[18949]44 rho_water=element->matpar->GetMaterialParameter(MaterialsRhoFreshwaterEnum);
[18001]45
[21469]46 /* Get constants */
47 femmodel->parameters->FindParam(&yts,ConstantsYtsEnum);
48
[18001]49 // loop over all vertices
50 for(v=0;v<numvertices;v++){
51 if(Smbref[v]>0){
52 smb[v]=Smbref[v]+b_pos[v]*(s[v]-Href[v]);
53 }
54 else{
55 smb[v]=Smbref[v]+b_neg[v]*(s[v]-Href[v]);
56 }
[21469]57
[18266]58 smb[v]=smb[v]/1000*rho_water/rho_ice; // SMB in m/y ice
[18001]59 } //end of the loop over the vertices
60
61 /*Add input to element and Free memory*/
[19527]62 element->AddInput(SmbMassBalanceEnum,smb,P1Enum);
[18001]63 xDelete<IssmDouble>(Href);
64 xDelete<IssmDouble>(Smbref);
65 xDelete<IssmDouble>(b_pos);
66 xDelete<IssmDouble>(b_neg);
67 xDelete<IssmDouble>(s);
68 xDelete<IssmDouble>(smb);
[17085]69 }
70
71}/*}}}*/
[21469]72void SmbGradientsElax(FemModel* femmodel){/*{{{*/
73
74 // void SurfaceMassBalancex(hd,agd,ni){
75 // INPUT parameters: ni: working size of arrays
76 // INPUT: surface elevation (m): hd(NA)
77 // OUTPUT: surface mass-balance (m/yr ice): agd(NA)
78 int v;
79
80 /*Loop over all the elements of this partition*/
81 for(int i=0;i<femmodel->elements->Size();i++){
82 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
83
84 /*Allocate all arrays*/
85 int numvertices = element->GetNumberOfVertices();
86 IssmDouble* ela = xNew<IssmDouble>(numvertices); // Equilibrium Line Altitude (m a.s.l) to which deviations are used to calculate the SMB
87 IssmDouble* b_pos = xNew<IssmDouble>(numvertices); // SMB gradient above ELA (m ice eq. per m elevation change)
88 IssmDouble* b_neg = xNew<IssmDouble>(numvertices); // SMB gradient below ELA (m ice eq. per m elevation change)
89 IssmDouble* b_max = xNew<IssmDouble>(numvertices); // Upper cap on SMB rate (m/y ice eq.)
90 IssmDouble* b_min = xNew<IssmDouble>(numvertices); // Lower cap on SMB rate (m/y ice eq.)
91 IssmDouble* s = xNew<IssmDouble>(numvertices); // Surface elevation (m a.s.l.)
92 IssmDouble* smb = xNew<IssmDouble>(numvertices); // SMB (m/y ice eq.)
93
94 /*Recover ELA, SMB gradients, and caps*/
95 element->GetInputListOnVertices(ela,SmbElaEnum);
96 element->GetInputListOnVertices(b_pos,SmbBPosEnum);
97 element->GetInputListOnVertices(b_neg,SmbBNegEnum);
98 element->GetInputListOnVertices(b_max,SmbBMaxEnum);
99 element->GetInputListOnVertices(b_min,SmbBMinEnum);
100
101 /*Recover surface elevation at vertices: */
102 element->GetInputListOnVertices(s,SurfaceEnum);
103
104 /*Loop over all vertices, calculate SMB*/
105 for(v=0;v<numvertices;v++){
106 // if surface is above the ELA
107 if(s[v]>ela[v]){
108 smb[v]=b_pos[v]*(s[v]-ela[v]);
109 }
110 // if surface is below or equal to the ELA
111 else{
112 smb[v]=b_neg[v]*(s[v]-ela[v]);
113 }
114
115 // if SMB is larger than upper cap, set SMB to upper cap
116 if(smb[v]>b_max[v]){
117 smb[v]=b_max[v];
118 }
119 // if SMB is smaller than lower cap, set SMB to lower cap
120 if(smb[v]<b_min[v]){
121 smb[v]=b_min[v];
122 }
123 } //end of the loop over the vertices
124
125 /*Add input to element and Free memory*/
126 element->AddInput(SmbMassBalanceEnum,smb,P1Enum);
127 xDelete<IssmDouble>(ela);
128 xDelete<IssmDouble>(b_pos);
129 xDelete<IssmDouble>(b_neg);
130 xDelete<IssmDouble>(b_max);
131 xDelete<IssmDouble>(b_min);
132 xDelete<IssmDouble>(s);
133 xDelete<IssmDouble>(smb);
134
135 }
136
137}/*}}}*/
[17085]138void Delta18oParameterizationx(FemModel* femmodel){/*{{{*/
139
140 for(int i=0;i<femmodel->elements->Size();i++){
[18521]141 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
[17085]142 element->Delta18oParameterization();
143 }
144
145}/*}}}*/
[18968]146void MungsmtpParameterizationx(FemModel* femmodel){/*{{{*/
147
148 for(int i=0;i<femmodel->elements->Size();i++){
149 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
150 element->MungsmtpParameterization();
151 }
152
153}/*}}}*/
[19172]154void Delta18opdParameterizationx(FemModel* femmodel){/*{{{*/
155
156 for(int i=0;i<femmodel->elements->Size();i++){
157 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
158 element->Delta18opdParameterization();
159 }
160
161}/*}}}*/
[17085]162void PositiveDegreeDayx(FemModel* femmodel){/*{{{*/
163
164 // void PositiveDegreeDayx(hd,vTempsea,vPrec,agd,Tsurf,ni){
165 // note "v" prefix means 12 monthly means, ie time dimension
166 // INPUT parameters: ni: working size of arrays
167 // INPUT: surface elevation (m): hd(NA)
168 // monthly mean surface sealevel temperature (degrees C): vTempsea(NA
169 // ,NTIME)
170 // monthly mean precip rate (m/yr water equivalent): vPrec(NA,NTIME)
171 // OUTPUT: mass-balance (m/yr ice): agd(NA)
172 // mean annual surface temperature (degrees C): Tsurf(NA)
173
174 int i, it, jj, itm;
175 IssmDouble DT = 0.02, sigfac, snormfac;
176 IssmDouble signorm = 5.5; // signorm : sigma of the temperature distribution for a normal day
177 IssmDouble siglim; // sigma limit for the integration which is equal to 2.5 sigmanorm
178 IssmDouble signormc = signorm - 0.5; // sigma of the temperature distribution for cloudy day
179 IssmDouble siglimc, siglim0, siglim0c;
180 IssmDouble tstep, tsint, tint, tstepc;
181 int NPDMAX = 1504, NPDCMAX = 1454;
182 //IssmDouble pdds[NPDMAX]={0};
183 //IssmDouble pds[NPDCMAX]={0};
184 IssmDouble pddt, pd ; // pd : snow/precip fraction, precipitation falling as snow
185 IssmDouble PDup, PDCUT = 2.0; // PDcut: rain/snow cutoff temperature (C)
186 IssmDouble tstar; // monthly mean surface temp
187
[18968]188 bool ismungsm;
[22448]189 bool issetpddfac;
[18968]190
[17085]191 IssmDouble *pdds = NULL;
192 IssmDouble *pds = NULL;
193 Element *element = NULL;
194
195 pdds=xNew<IssmDouble>(NPDMAX+1);
196 pds=xNew<IssmDouble>(NPDCMAX+1);
197
[18968]198 // Get ismungsm parameter
[19527]199 femmodel->parameters->FindParam(&ismungsm,SmbIsmungsmEnum);
[18968]200
[22448]201 // Get issetpddfac parameter
202 femmodel->parameters->FindParam(&issetpddfac,SmbIssetpddfacEnum);
203
[17085]204 /* initialize PDD (creation of a lookup table)*/
205 tstep = 0.1;
206 tsint = tstep*0.5;
207 sigfac = -1.0/(2.0*pow(signorm,2));
208 snormfac = 1.0/(signorm*sqrt(2.0*acos(-1.0)));
209 siglim = 2.5*signorm;
210 siglimc = 2.5*signormc;
211 siglim0 = siglim/DT + 0.5;
212 siglim0c = siglimc/DT + 0.5;
213 PDup = siglimc+PDCUT;
214
215 itm = reCast<int,IssmDouble>((2*siglim/DT + 1.5));
216
217 if(itm >= NPDMAX) _error_("increase NPDMAX in massBalance.cpp");
218 for(it = 0; it < itm; it++){
219 // tstar = REAL(it)*DT-siglim;
220 tstar = it*DT-siglim;
221 tint = tsint;
222 pddt = 0.;
223 for ( jj = 0; jj < 600; jj++){
224 if (tint > (tstar+siglim)){break;}
225 pddt = pddt + tint*exp(sigfac*(pow((tint-tstar),2)))*tstep;
226 tint = tint+tstep;
227 }
228 pdds[it] = pddt*snormfac;
229 }
230 pdds[itm+1] = siglim + DT;
231
232 //*********compute PD(T) : snow/precip fraction. precipitation falling as snow
233 tstepc = 0.1;
234 tsint = PDCUT-tstepc*0.5;
235 signormc = signorm - 0.5;
236 sigfac = -1.0/(2.0*pow(signormc,2));
237 snormfac = 1.0/(signormc*sqrt(2.0*acos(-1.0)));
238 siglimc = 2.5*signormc ;
239 itm = reCast<int,IssmDouble>((PDCUT+2.*siglimc)/DT + 1.5);
240 if(itm >= NPDCMAX) _error_("increase NPDCMAX in p35com");
241 for(it = 0; it < itm; it++ ){
242 tstar = it*DT-siglimc;
243 // tstar = REAL(it)*DT-siglimc;
244 tint = tsint; // start against upper bound
245 pd = 0.;
246 for (jj = 0; jj < 600; jj++){
247 if (tint<(tstar-siglimc)) {break;}
248 pd = pd + exp(sigfac*(pow((tint-tstar),2)))*tstepc;
249 tint = tint-tstepc;
250 }
251 pds[it] = pd*snormfac; // gaussian integral lookup table for snow fraction
252 }
253 pds[itm+1] = 0.;
254 // *******END initialize PDD
255
256 for(i=0;i<femmodel->elements->Size();i++){
[18521]257 element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
[22448]258 element->PositiveDegreeDay(pdds,pds,signorm,ismungsm,issetpddfac);
[17085]259 }
260 /*free ressouces: */
261 xDelete<IssmDouble>(pdds);
262 xDelete<IssmDouble>(pds);
263}/*}}}*/
264void SmbHenningx(FemModel* femmodel){/*{{{*/
265
[17087]266 /*Intermediaries*/
[17403]267 IssmDouble z_critical = 1675.;
268 IssmDouble dz = 0;
269 IssmDouble a = -15.86;
270 IssmDouble b = 0.00969;
271 IssmDouble c = -0.235;
272 IssmDouble f = 1.;
273 IssmDouble g = -0.0011;
274 IssmDouble h = -1.54e-5;
275 IssmDouble smb,smbref,anomaly,yts,z;
[22249]276
277 /* Get constants */
278 femmodel->parameters->FindParam(&yts,ConstantsYtsEnum);
279 /*iomodel->FindConstant(&yts,"md.constants.yts");*/
280 /*this->parameters->FindParam(&yts,ConstantsYtsEnum);*/
281 /*Mathieu original*/
282 /*IssmDouble smb,smbref,z;*/
283
[17087]284 /*Loop over all the elements of this partition*/
[17085]285 for(int i=0;i<femmodel->elements->Size();i++){
[18521]286 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
[17087]287
288 /*Get reference SMB (uncorrected) and allocate all arrays*/
289 int numvertices = element->GetNumberOfVertices();
290 IssmDouble* surfacelist = xNew<IssmDouble>(numvertices);
291 IssmDouble* smblistref = xNew<IssmDouble>(numvertices);
292 IssmDouble* smblist = xNew<IssmDouble>(numvertices);
293 element->GetInputListOnVertices(surfacelist,SurfaceEnum);
[19527]294 element->GetInputListOnVertices(smblistref,SmbSmbrefEnum);
[17087]295
296 /*Loop over all vertices of element and correct SMB as a function of altitude z*/
297 for(int v=0;v<numvertices;v++){
298
[17403]299 /*Get vertex elevation, anoma smb*/
[17087]300 z = surfacelist[v];
[17403]301 anomaly = smblistref[v];
[17087]302
[22249]303 /* Henning edited acc. to Riannes equations*/
304 /* Set SMB maximum elevation, if dz = 0 -> z_critical = 1675 */
305 z_critical = z_critical + dz;
306
307 /* Calculate smb acc. to the surface elevation z */
308 if(z<z_critical){
[17403]309 smb = a + b*z + c;
[17087]310 }
311 else{
[22249]312 smb = (a + b*z)*(f + g*(z-z_critical) + h*(z-z_critical)*(z-z_critical)) + c;
[17087]313 }
[22249]314
[18584]315 /* Compute smb including anomaly,
316 correct for number of seconds in a year [s/yr]*/
317 smb = smb/yts + anomaly;
318
[17087]319 /*Update array accordingly*/
320 smblist[v] = smb;
321
322 }
323
324 /*Add input to element and Free memory*/
[19527]325 element->AddInput(SmbMassBalanceEnum,smblist,P1Enum);
[17087]326 xDelete<IssmDouble>(surfacelist);
327 xDelete<IssmDouble>(smblistref);
328 xDelete<IssmDouble>(smblist);
[17085]329 }
330
331}/*}}}*/
[18001]332void SmbComponentsx(FemModel* femmodel){/*{{{*/
333
334 // void SmbComponentsx(acc,evap,runoff,ni){
335 // INPUT parameters: ni: working size of arrays
336 // INPUT: surface accumulation (m/yr water equivalent): acc
337 // surface evaporation (m/yr water equivalent): evap
338 // surface runoff (m/yr water equivalent): runoff
339 // OUTPUT: mass-balance (m/yr ice): agd(NA)
340 int v;
341
342 /*Loop over all the elements of this partition*/
343 for(int i=0;i<femmodel->elements->Size();i++){
[18521]344 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
[18001]345
346 /*Allocate all arrays*/
347 int numvertices = element->GetNumberOfVertices();
348 IssmDouble* acc = xNew<IssmDouble>(numvertices);
349 IssmDouble* evap = xNew<IssmDouble>(numvertices);
350 IssmDouble* runoff = xNew<IssmDouble>(numvertices);
351 IssmDouble* smb = xNew<IssmDouble>(numvertices);
352
353 /*Recover Smb Components*/
[19527]354 element->GetInputListOnVertices(acc,SmbAccumulationEnum);
355 element->GetInputListOnVertices(evap,SmbEvaporationEnum);
356 element->GetInputListOnVertices(runoff,SmbRunoffEnum);
[18001]357
358 // loop over all vertices
359 for(v=0;v<numvertices;v++){
360 smb[v]=acc[v]-evap[v]-runoff[v];
361 } //end of the loop over the vertices
362
363 /*Add input to element and Free memory*/
[19527]364 element->AddInput(SmbMassBalanceEnum,smb,P1Enum);
[18001]365 xDelete<IssmDouble>(acc);
366 xDelete<IssmDouble>(evap);
367 xDelete<IssmDouble>(runoff);
368 xDelete<IssmDouble>(smb);
369 }
370
371}/*}}}*/
372void SmbMeltComponentsx(FemModel* femmodel){/*{{{*/
373
374 // void SmbMeltComponentsx(acc,evap,melt,refreeze,ni){
375 // INPUT parameters: ni: working size of arrays
376 // INPUT: surface accumulation (m/yr water equivalent): acc
377 // surface evaporation (m/yr water equivalent): evap
378 // surface melt (m/yr water equivalent): melt
379 // refreeze of surface melt (m/yr water equivalent): refreeze
380 // OUTPUT: mass-balance (m/yr ice): agd(NA)
381 int v;
382
383 /*Loop over all the elements of this partition*/
384 for(int i=0;i<femmodel->elements->Size();i++){
[18521]385 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
[18001]386
387 /*Allocate all arrays*/
388 int numvertices = element->GetNumberOfVertices();
389 IssmDouble* acc = xNew<IssmDouble>(numvertices);
390 IssmDouble* evap = xNew<IssmDouble>(numvertices);
391 IssmDouble* melt = xNew<IssmDouble>(numvertices);
392 IssmDouble* refreeze = xNew<IssmDouble>(numvertices);
393 IssmDouble* smb = xNew<IssmDouble>(numvertices);
394
395 /*Recover Smb Components*/
[19527]396 element->GetInputListOnVertices(acc,SmbAccumulationEnum);
397 element->GetInputListOnVertices(evap,SmbEvaporationEnum);
398 element->GetInputListOnVertices(melt,SmbMeltEnum);
399 element->GetInputListOnVertices(refreeze,SmbRefreezeEnum);
[18001]400
401 // loop over all vertices
402 for(v=0;v<numvertices;v++){
403 smb[v]=acc[v]-evap[v]-melt[v]+refreeze[v];
404 } //end of the loop over the vertices
405
406 /*Add input to element and Free memory*/
[19527]407 element->AddInput(SmbMassBalanceEnum,smb,P1Enum);
[18001]408 xDelete<IssmDouble>(acc);
409 xDelete<IssmDouble>(evap);
410 xDelete<IssmDouble>(melt);
411 xDelete<IssmDouble>(refreeze);
412 xDelete<IssmDouble>(smb);
413 }
414
415}/*}}}*/
Note: See TracBrowser for help on using the repository browser.