9 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
14 #include "../classes.h"
15 #include "../../shared/shared.h"
16 #include "../../modules/SurfaceMassBalancex/SurfaceMassBalancex.h"
17 #include "../Inputs2/BoolInput2.h"
18 #include "../Inputs2/TransientInput2.h"
19 #include "../Inputs2/ElementInput2.h"
20 #include "../Inputs2/PentaInput2.h"
21 #include "../Inputs2/DatasetInput2.h"
22 #include "../Inputs2/ArrayInput2.h"
56 for(
int i=0;i<numnodes;i++){
57 if(
nodes[i]->fsize)
return true;
81 IssmDouble* lambdas = xNew<IssmDouble>(NUM_VERTICES);
85 for (
int iv=0;iv<NUM_VERTICES;iv++){
103 dvz[0] = 0.; dvz[1] = 0.; dvz[2] = 0.;
108 vmag = sqrt(vx*vx+vy*vy+vz*vz);
116 dvmag[0]=1./(2*sqrt(vmag))*(2*vx*dvx[0]+2*vy*dvy[0]+2*vz*dvz[0]);
117 dvmag[1]=1./(2*sqrt(vmag))*(2*vx*dvx[1]+2*vy*dvy[1]+2*vz*dvz[1]);
118 dvmag[2]=1./(2*sqrt(vmag))*(2*vx*dvx[2]+2*vy*dvy[2]+2*vz*dvz[2]);
121 eps[0][0] = dvx[0]; eps[0][1] = .5*(dvx[1]+dvy[0]); eps[0][2] = .5*(dvx[2]+dvz[0]);
122 eps[1][0] = .5*(dvx[1]+dvy[0]); eps[1][1] = dvy[1]; eps[1][2] = .5*(dvy[2]+dvz[1]);
123 eps[2][0] = .5*(dvx[2]+dvz[0]); eps[2][1] = .5*(dvy[2]+dvz[1]); eps[2][2] = dvz[2];
128 epseff = sqrt(eps[0][0]*eps[0][0] + eps[1][1]*eps[1][1] + eps[0][1]*eps[0][1] + eps[0][2]*eps[0][2] + eps[1][2]*eps[1][2] + eps[0][0]*eps[1][1]);
139 xDelete<IssmDouble>(xyz_list);
140 xDelete<IssmDouble>(lambdas);
147 IssmDouble eps_xx,eps_xy,eps_yy,eps_xz,eps_yz,eps_zz,eps_eff;
149 IssmDouble eps_0,kappa,sigma_0,B,D,n,envelopeD;
164 Input2* eps_xz_input=NULL;
165 Input2* eps_yz_input=NULL;
166 Input2* eps_zz_input=NULL;
175 IssmDouble* newD = xNew<IssmDouble>(numnodes);
179 Input2* damage_input = NULL;
194 for (
int i=0;i<numnodes;i++){
205 else{eps_xz=0; eps_yz=0; eps_zz=0;}
208 eps_eff=sqrt(eps_xx*eps_xx+eps_yy*eps_yy+eps_xy*eps_xy+eps_xz*eps_xz+eps_yz*eps_yz+eps_xx*eps_yy+epsmin*epsmin);
215 eps_0=pow(sigma_0/B,n);
219 envelopeD=1.-pow(eps_0/eps_eff,1./n)*exp(-(eps_eff-eps_0)/(eps_0*(kappa-1.)));
239 xDelete<IssmDouble>(xyz_list);
240 xDelete<IssmDouble>(newD);
261 IssmDouble* eps_xx = xNew<IssmDouble>(NUM_VERTICES);
262 IssmDouble* eps_yy = xNew<IssmDouble>(NUM_VERTICES);
263 IssmDouble* eps_zz = xNew<IssmDouble>(NUM_VERTICES);
264 IssmDouble* eps_xy = xNew<IssmDouble>(NUM_VERTICES);
265 IssmDouble* eps_xz = xNew<IssmDouble>(NUM_VERTICES);
266 IssmDouble* eps_yz = xNew<IssmDouble>(NUM_VERTICES);
267 IssmDouble* eps_ef = xNew<IssmDouble>(NUM_VERTICES);
271 for (
int iv=0;iv<NUM_VERTICES;iv++){
276 this->
StrainRateSSA(&epsilon[0],xyz_list,gauss,vx_input,vy_input);
278 this->
StrainRateFS(&epsilon[0],xyz_list,gauss,vx_input,vy_input,vz_input);
282 eps_xx[iv]=epsilon[0];
283 eps_yy[iv]=epsilon[1];
284 eps_xy[iv]=epsilon[2];
286 eps_ef[iv] = 1./sqrt(2.)*sqrt(epsilon[0]*epsilon[0] + epsilon[1]*epsilon[1] + 2.*epsilon[2]*epsilon[2]);
290 eps_xx[iv]=epsilon[0];
291 eps_yy[iv]=epsilon[1];
292 eps_zz[iv]=epsilon[2];
293 eps_xy[iv]=epsilon[3];
294 eps_xz[iv]=epsilon[4];
295 eps_yz[iv]=epsilon[5];
297 eps_ef[iv] = sqrt(epsilon[0]*epsilon[0] + epsilon[1]*epsilon[1] + epsilon[3]*epsilon[3] + epsilon[4]*epsilon[4] + epsilon[5]*epsilon[5] + epsilon[0]*epsilon[1]);
312 xDelete<IssmDouble>(xyz_list);
313 xDelete<IssmDouble>(eps_xx);
314 xDelete<IssmDouble>(eps_yy);
315 xDelete<IssmDouble>(eps_zz);
316 xDelete<IssmDouble>(eps_xy);
317 xDelete<IssmDouble>(eps_xz);
318 xDelete<IssmDouble>(eps_yz);
319 xDelete<IssmDouble>(eps_ef);
335 for(i=0;i<numnodes;i++){
338 case XYEnum: numdofs+=2;
break;
339 case XYZEnum: numdofs+=3;
break;
345 transform=xNew<IssmDouble>(numdofs*numdofs);
346 for(i=0;i<numdofs*numdofs;i++) transform[i]=0.0;
358 for(i=0;i<numnodes;i++){
363 transform[(numdofs)*(counter) + counter] = 1.;
368 norm = sqrt( coord_system[0][0]*coord_system[0][0] + coord_system[1][0]*coord_system[1][0]);
_assert_(norm>1.e-4);
369 transform[(numdofs)*(counter+0) + counter+0] = coord_system[0][0]/norm;
370 transform[(numdofs)*(counter+0) + counter+1] = - coord_system[1][0]/norm;
371 transform[(numdofs)*(counter+1) + counter+0] = coord_system[1][0]/norm;
372 transform[(numdofs)*(counter+1) + counter+1] = coord_system[0][0]/norm;
377 transform[(numdofs)*(counter+0) + counter+0] = coord_system[0][0];
378 transform[(numdofs)*(counter+0) + counter+1] = coord_system[0][1];
379 transform[(numdofs)*(counter+0) + counter+2] = coord_system[0][2];
380 transform[(numdofs)*(counter+1) + counter+0] = coord_system[1][0];
381 transform[(numdofs)*(counter+1) + counter+1] = coord_system[1][1];
382 transform[(numdofs)*(counter+1) + counter+2] = coord_system[1][2];
383 transform[(numdofs)*(counter+2) + counter+0] = coord_system[2][0];
384 transform[(numdofs)*(counter+2) + counter+1] = coord_system[2][1];
385 transform[(numdofs)*(counter+2) + counter+2] = coord_system[2][2];
394 *ptransform=transform;
400 _printf_(
" id : "<<this->
id <<
"\n");
420 else _printf_(
"parameters = NULL\n");
438 const int NUM_VERTICES_MONTHS_PER_YEAR = NUM_VERTICES * 12;
441 int* vertexlids=xNew<int>(NUM_VERTICES);
442 IssmDouble* monthlytemperatures=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
443 IssmDouble* monthlyprec=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
444 IssmDouble* TemperaturesPresentday=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
445 IssmDouble* TemperaturesLgm=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
446 IssmDouble* PrecipitationsPresentday=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
447 IssmDouble* tmp=xNew<IssmDouble>(NUM_VERTICES);
464 for(
int month=0;month<12;month++){
465 for(
int iv=0;iv<NUM_VERTICES;iv++){
467 dinput1->
GetInputValue(&TemperaturesPresentday[iv*12+month],gauss,month);
468 dinput2->
GetInputValue(&TemperaturesLgm[iv*12+month],gauss,month);
469 dinput3->
GetInputValue(&PrecipitationsPresentday[iv*12+month],gauss,month);
471 PrecipitationsPresentday[iv*12+month]=PrecipitationsPresentday[iv*12+month]*yts;
476 IssmDouble Delta18oPresent,Delta18oLgm,Delta18oTime;
477 IssmDouble Delta18oSurfacePresent,Delta18oSurfaceLgm,Delta18oSurfaceTime;
486 for(
int iv=0;iv<NUM_VERTICES;iv++){
488 Delta18oPresent, Delta18oLgm, Delta18oTime,
489 &PrecipitationsPresentday[iv*12],
490 &TemperaturesLgm[iv*12], &TemperaturesPresentday[iv*12],
491 &monthlytemperatures[iv*12], &monthlyprec[iv*12]);
495 for (
int imonth=0;imonth<12;imonth++) {
496 for(i=0;i<NUM_VERTICES;i++) tmp[i]=monthlytemperatures[i*12+imonth];
500 default:
_error_(
"Not implemented yet");
502 for(i=0;i<NUM_VERTICES;i++) tmp[i]=monthlyprec[i*12+imonth]/yts;
506 default:
_error_(
"Not implemented yet");
517 default:
_error_(
"Not implemented yet");
522 xDelete<IssmDouble>(monthlytemperatures);
523 xDelete<IssmDouble>(monthlyprec);
524 xDelete<IssmDouble>(TemperaturesPresentday);
525 xDelete<IssmDouble>(TemperaturesLgm);
526 xDelete<IssmDouble>(PrecipitationsPresentday);
527 xDelete<IssmDouble>(tmp);
528 xDelete<int>(vertexlids);
536 const int NUM_VERTICES_MONTHS_PER_YEAR = NUM_VERTICES * 12;
539 int* vertexlids=xNew<int>(NUM_VERTICES);
540 IssmDouble* monthlytemperatures=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
541 IssmDouble* monthlyprec=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
542 IssmDouble* TemperaturesPresentday=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
543 IssmDouble* PrecipitationsPresentday=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
544 IssmDouble* TemperaturesReconstructed=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
545 IssmDouble* PrecipitationsReconstructed=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
546 IssmDouble* tmp=xNew<IssmDouble>(NUM_VERTICES);
549 IssmDouble time,yts,time_yr,month,time_climt,time_climp,del_clim;
554 time_yr=floor(time/yts)*yts;
555 time_climt=ceil(time/yts + 1e-10)*yts;
556 time_climp=ceil(time/yts + 1e-10)*yts;
559 bool isTemperatureScaled,isPrecipScaled;
567 int offset_t,offset_p,N;
568 if(!isTemperatureScaled){
572 if(offset_t<0) offset_t=0;
573 xDelete<IssmDouble>(time_temp_scaled);
580 if(offset_p<0) offset_p=0;
581 xDelete<IssmDouble>(time_precip_scaled);
591 for(
int month=0;month<12;month++) {
592 for(
int iv=0;iv<NUM_VERTICES;iv++) {
594 dinput1->
GetInputValue(&TemperaturesPresentday[iv*12+month],gauss,month);
595 dinput2->
GetInputValue(&PrecipitationsPresentday[iv*12+month],gauss,month);
596 PrecipitationsPresentday[iv*12+month]=PrecipitationsPresentday[iv*12+month]*yts;
598 if(!isTemperatureScaled){
599 dinput3->
GetInputValue(&TemperaturesReconstructed[iv*12+month],gauss,offset_t*12+month);
602 dinput4->
GetInputValue(&PrecipitationsReconstructed[iv*12+month],gauss,offset_p*12+month);
603 PrecipitationsReconstructed[iv*12+month]=PrecipitationsReconstructed[iv*12+month]*yts;
612 for(
int iv=0;iv<NUM_VERTICES;iv++){
614 f,&PrecipitationsPresentday[iv*12], &TemperaturesPresentday[iv*12],
615 &PrecipitationsReconstructed[iv*12], &TemperaturesReconstructed[iv*12],
616 &monthlytemperatures[iv*12], &monthlyprec[iv*12]);
620 for (
int imonth=0;imonth<12;imonth++) {
621 for(i=0;i<NUM_VERTICES;i++) tmp[i]=monthlytemperatures[i*12+imonth];
625 default:
_error_(
"Not implemented yet");
627 for(i=0;i<NUM_VERTICES;i++) tmp[i]=monthlyprec[i*12+imonth]/yts;
631 default:
_error_(
"Not implemented yet");
642 default:
_error_(
"Not implemented yet");
647 xDelete<IssmDouble>(monthlytemperatures);
648 xDelete<IssmDouble>(monthlyprec);
649 xDelete<IssmDouble>(TemperaturesPresentday);
650 xDelete<IssmDouble>(PrecipitationsPresentday);
651 xDelete<IssmDouble>(TemperaturesReconstructed);
652 xDelete<IssmDouble>(PrecipitationsReconstructed);
653 xDelete<IssmDouble>(tmp);
654 xDelete<int>(vertexlids);
670 IssmDouble* smb = xNew<IssmDouble>(NUM_VERTICES);
671 IssmDouble* surf = xNew<IssmDouble>(NUM_VERTICES);
672 IssmDouble* accu = xNew<IssmDouble>(NUM_VERTICES);
673 IssmDouble* runoff = xNew<IssmDouble>(NUM_VERTICES);
694 for(
int iv=0;iv<NUM_VERTICES;iv++){
695 accu[iv]=
max(0.,(accuref+(surf[iv]-accualti)*accugrad));
696 runoff[iv]=
max(0.,(runoffref+(surf[iv]-runoffalti)*runoffgrad));
697 smb[iv]=(accu[iv]-runoff[iv])*rho_ice/rho_water;
711 default:
_error_(
"Not implemented yet");
714 xDelete<IssmDouble>(surf);
715 xDelete<IssmDouble>(accu);
716 xDelete<IssmDouble>(runoff);
717 xDelete<IssmDouble>(smb);
741 for(
int ig=gauss->
begin();ig<gauss->end();ig++){
749 divergence += (dvx[0]+dvy[1])*gauss->
weight*Jdet;
753 divergence += (dvx[0]+dvy[1]+dvz[2])*gauss->
weight*Jdet;
759 xDelete<IssmDouble>(xyz_list);
775 this->
StrainRateFS(&epsilon3d[0],xyz_list,gauss,vx_input,vy_input,vz_input);
776 eps_eff = sqrt(epsilon3d[0]*epsilon3d[0] + epsilon3d[1]*epsilon3d[1] + epsilon3d[3]*epsilon3d[3] + epsilon3d[4]*epsilon3d[4] + epsilon3d[5]*epsilon3d[5] + epsilon3d[0]*epsilon3d[1]+eps0*eps0);
780 this->
StrainRateSSA(&epsilon2d[0],xyz_list,gauss,vx_input,vy_input);
781 eps_eff = 1./sqrt(2.)*sqrt(epsilon2d[0]*epsilon2d[0] + epsilon2d[1]*epsilon2d[1] + 2.*epsilon2d[2]*epsilon2d[2]);
785 switch(materialstype){
792 default:
_error_(
"not supported");
812 this->
StrainRateHO(&epsilon3d[0],xyz_list,gauss,vx_input,vy_input);
813 eps_eff = sqrt(epsilon3d[0]*epsilon3d[0] + epsilon3d[1]*epsilon3d[1] + epsilon3d[2]*epsilon3d[2] + epsilon3d[3]*epsilon3d[3] + epsilon3d[4]*epsilon3d[4] + epsilon3d[0]*epsilon3d[1]+eps0*eps0);
818 eps_eff = 1./sqrt(2.)*sqrt(epsilon2d[0]*epsilon2d[0] + 2.*epsilon2d[1]*epsilon2d[1] + eps0*eps0);
822 switch(materialstype){
829 default:
_error_(
"not supported");
848 this->
StrainRateSSA(&epsilon2d[0],xyz_list,gauss,vx_input,vy_input);
849 eps_eff = sqrt(epsilon2d[0]*epsilon2d[0] + epsilon2d[1]*epsilon2d[1] + epsilon2d[2]*epsilon2d[2] + epsilon2d[0]*epsilon2d[1]);
854 eps_eff = sqrt(epsilon1d*epsilon1d/2.);
859 switch(materialstype){
866 default:
_error_(
"not supported");
884 this->
StrainRateSSA(&epsilon2d[0],xyz_list,gauss,vx_input,vy_input);
885 eps_eff = sqrt(epsilon2d[0]*epsilon2d[0] + epsilon2d[1]*epsilon2d[1] + epsilon2d[2]*epsilon2d[2] + epsilon2d[0]*epsilon2d[1]);
890 eps_eff = sqrt(epsilon1d*epsilon1d/2.);
903 _printf_(
" id : "<<this->
id <<
"\n");
914 for(
int i=0;i<numnodes;i++) {
926 else _printf_(
"parameters = NULL\n");
968 for(
int i=0;i<numnodes;i++) numberofdofs+=
nodes[i]->
GetNumberOfDofs(approximation_enum,setenum);
971 int* doflist=xNew<int>(numberofdofs);
975 for(
int i=0;i<numnodes;i++){
991 for(
int i=0;i<numnodes;i++) numberofdofs+=
nodes[i]->
GetNumberOfDofs(approximation_enum,setenum);
994 int* doflist=xNew<int>(numberofdofs);
998 for(
int i=0;i<numnodes;i++){
1018 int* doflist=xNew<int>(numberofdofs);
1022 for(
int i=vnumnodes;i<vnumnodes+pnumnodes;i++){
1041 int* doflist=xNew<int>(numberofdofs);
1045 for(
int i=0;i<numnodes;i++){
1065 int* doflist=xNew<int>(numberofdofs);
1069 for(
int i=vnumnodes;i<vnumnodes+pnumnodes;i++){
1088 int* doflist=xNew<int>(numberofdofs);
1092 for(
int i=0;i<numnodes;i++){
1124 for(
int iv=0;iv<numnodes;iv++){
1165 for(
int i=1;i<numnodes;i++){
1171 for(
int i=0;i<numnodes;i++){
1210 return this->
nodes[nodeindex];
1217 for(
int i=0;i<numnodes;i++){
1218 if(node==
nodes[i])
return i;
1220 _error_(
"Node provided not found among element nodes");
1229 for(
int i=0;i<numnodes;i++){
1239 for(
int i=0;i<numnodes;i++){
1252 epsilon_matrix[0][0]=epsilon[0];
1253 epsilon_matrix[1][0]=epsilon[3];
1254 epsilon_matrix[2][0]=epsilon[4];
1255 epsilon_matrix[0][1]=epsilon[3];
1256 epsilon_matrix[1][1]=epsilon[1];
1257 epsilon_matrix[2][1]=epsilon[5];
1258 epsilon_matrix[0][2]=epsilon[4];
1259 epsilon_matrix[1][2]=epsilon[5];
1260 epsilon_matrix[2][2]=epsilon[2];
1263 epsilon_sqr[0][0]=epsilon_matrix[0][0]*epsilon_matrix[0][0];
1264 epsilon_sqr[1][0]=epsilon_matrix[1][0]*epsilon_matrix[1][0];
1265 epsilon_sqr[2][0]=epsilon_matrix[2][0]*epsilon_matrix[2][0];
1266 epsilon_sqr[0][1]=epsilon_matrix[0][1]*epsilon_matrix[0][1];
1267 epsilon_sqr[1][1]=epsilon_matrix[1][1]*epsilon_matrix[1][1];
1268 epsilon_sqr[2][1]=epsilon_matrix[2][1]*epsilon_matrix[2][1];
1269 epsilon_sqr[0][2]=epsilon_matrix[0][2]*epsilon_matrix[0][2];
1270 epsilon_sqr[1][2]=epsilon_matrix[1][2]*epsilon_matrix[1][2];
1271 epsilon_sqr[2][2]=epsilon_matrix[2][2]*epsilon_matrix[2][2];
1272 epsilon_eff=1/sqrt(2.)*sqrt(epsilon_sqr[0][0]+epsilon_sqr[0][1]+ epsilon_sqr[0][2]+ epsilon_sqr[1][0]+ epsilon_sqr[1][1]+ epsilon_sqr[1][2]+ epsilon_sqr[2][0]+ epsilon_sqr[2][1]+ epsilon_sqr[2][2]);
1278 *phi=4.*epsilon_eff*epsilon_eff*viscosity;
1283 int *doflist = NULL;
1291 IssmDouble* values = xNew<IssmDouble>(numnodes);
1298 for(
int i=0;i<numnodes;i++){
1308 xDelete<int>(doflist);
1309 xDelete<IssmDouble>(values);
1337 int* doflist = NULL;
1349 doflist = xNew<int>(NUM_VERTICES);
1350 values = xNew<IssmDouble>(NUM_VERTICES);
1357 doflist = xNew<int>(NUM_VERTICES);
1358 values = xNew<IssmDouble>(NUM_VERTICES);
1365 doflist = xNew<int>(numnodes);
1366 values = xNew<IssmDouble>(numnodes);
1373 doflist = xNew<int>(numnodes);
1374 values = xNew<IssmDouble>(numnodes);
1385 xDelete<int>(doflist);
1386 xDelete<IssmDouble>(values);
1396 int* doflist = NULL;
1401 doflist = xNew<int>(NUM_VERTICES);
1402 values = xNew<IssmDouble>(NUM_VERTICES);
1409 doflist = xNew<int>(NUM_VERTICES);
1410 values = xNew<IssmDouble>(NUM_VERTICES);
1421 xDelete<int>(doflist);
1422 xDelete<IssmDouble>(values);
1429 for(
int i=0;i<NUM_VERTICES;i++) lidlist[i]=
vertices[i]->Lid();
1436 for(
int i=0;i<NUM_VERTICES;i++) pidlist[i]=
vertices[i]->Pid();
1443 for(
int i=0;i<NUM_VERTICES;i++) connectivity[i]=this->
vertices[i]->Connectivity();
1450 IssmDouble* xyz_list = xNew<IssmDouble>(NUM_VERTICES*3);
1453 *pxyz_list = xyz_list;
1459 for(
int i=0;i<NUM_VERTICES;i++) sidlist[i]=this->
vertices[i]->
Sid();
1470 IssmDouble* x_list = xNew<IssmDouble>(NUM_VERTICES);
1472 for(
int i=0;i<NUM_VERTICES;i++) x_list[i]=xyz_list[i*3+0];
1475 xDelete<IssmDouble>(x_list);
1486 IssmDouble* y_list = xNew<IssmDouble>(NUM_VERTICES);
1488 for(
int i=0;i<NUM_VERTICES;i++) y_list[i]=xyz_list[i*3+1];
1491 xDelete<IssmDouble>(y_list);
1502 IssmDouble* z_list = xNew<IssmDouble>(NUM_VERTICES);
1504 for(
int i=0;i<NUM_VERTICES;i++) z_list[i]=xyz_list[i*3+2];
1507 xDelete<IssmDouble>(z_list);
1526 if(control_index>0) {
1527 for(
int n=0;n<control_index;n++){
1532 for(
int n=0;n<N[control_index];n++){
1533 for(
int i=0;i<NUM_VERTICES;i++){
1534 indexing[i+n*NUM_VERTICES]=this->
vertices[i]->
Sid() + start + n*M[control_index];
1542 for(
int i=0;i<NUM_VERTICES;i++){
1543 indexing[i]=this->
vertices[i]->
Sid() + (control_index)*M;
1636 int *vertexids = xNew<int>(NUM_VERTICES);
1637 int *vertexlids = xNew<int>(NUM_VERTICES);
1638 IssmDouble *values = xNew<IssmDouble>(NUM_VERTICES);
1642 for(i=0;i<NUM_VERTICES;i++){
1643 vertexids[i] =reCast<int>(iomodel->
elements[NUM_VERTICES*this->Sid()+i]);
1649 values[0]=vector[0];
1653 for(i=0;i<NUM_VERTICES;i++) values[i]=vector[vertexids[i]-1];
1654 this->
SetElementInput(inputs2,NUM_VERTICES,vertexlids,values,vector_enum);
1659 for(t=0;t<N;t++) times[t] = vector[(M-1)*N+t];
1663 for(i=0;i<NUM_VERTICES;i++) values[i]=vector[N*(vertexids[i]-1)+t];
1667 default:
_error_(
"Not implemented yet");
1670 xDelete<IssmDouble>(times);
1675 xDelete<IssmDouble>(values);
1676 values = xNew<IssmDouble>(N);
1677 for(
int j=0;j<N;j++) values[j]=vector[this->
Sid()*N+j];
1680 this->
SetElementInput(inputs2,NUM_VERTICES,vertexlids,values,vector_enum);
1692 _error_(
"Patch interpolation not supported yet");
1697 _error_(
"nodal vector is either numberofvertices or numberofvertices+1 long. Field provided (" <<
EnumToStringx(vector_enum) <<
") is " << M <<
" long");
1700 xDelete<IssmDouble>(values);
1701 xDelete<int>(vertexids);
1702 xDelete<int>(vertexlids);
1704 else if(vector_type==2){
1711 this->
SetBoolInput(inputs2,vector_enum,reCast<bool>(vector[this->
Sid()]));
1714 this->
SetIntInput(inputs2,vector_enum,reCast<int>(vector[this->
Sid()]));
1719 else _error_(
"could not recognize nature of vector from code " << code);
1724 for(t=0;t<N;t++) times[t] = vector[(M-1)*N+t];
1728 value=vector[N*this->
Sid()+t];
1732 default:
_error_(
"Not implemented yet");
1735 xDelete<IssmDouble>(times);
1737 else _error_(
"element vector is either numberofelements or numberofelements+1 long. Field provided (" <<
EnumToStringx(vector_enum) <<
") is " << M <<
" long");
1739 else if(vector_type==3){
1743 IssmDouble* layers = xNewZeroInit<IssmDouble>(N);
1744 for(t=0;t<N;t++) layers[t] = vector[N*this->
Sid()+t];
1746 xDelete<IssmDouble>(layers);
1748 else _error_(
"element vector is either numberofelements or numberofelements+1 long. Field provided (" <<
EnumToStringx(vector_enum) <<
") is " << M <<
" long");
1750 else _error_(
"Cannot add input for vector type " << vector_type <<
" (not supported)");
1758 int *vertexids = xNew<int>(numvertices);
1759 IssmDouble *values = xNew<IssmDouble>(numvertices);
1760 IssmDouble *values_min = xNew<IssmDouble>(numvertices);
1761 IssmDouble *values_max = xNew<IssmDouble>(numvertices);
1770 for(
int i=0;i<numvertices;i++){
1771 vertexids[i]=reCast<int>(iomodel->
elements[numvertices*this->Sid()+i]);
1776 for(
int i=0;i<numvertices;i++){
1777 values[i] = vector[vertexids[i]-1];
1778 values_min[i] = scale*min_vector[vertexids[i]-1];
1779 values_max[i] = scale*max_vector[vertexids[i]-1];
1822 else _error_(
"not currently supported type of M and N attempted");
1825 xDelete<IssmDouble>(values);
1826 xDelete<IssmDouble>(values_min);
1827 xDelete<IssmDouble>(values_max);
1828 xDelete<int>(vertexids);
1847 int *vertexids = xNew<int>(NUM_VERTICES);
1848 int *vertexlids = xNew<int>(NUM_VERTICES);
1849 IssmDouble *values = xNew<IssmDouble>(NUM_VERTICES);
1853 for(i=0;i<NUM_VERTICES;i++){
1854 vertexids[i] =reCast<int>(iomodel->
elements[NUM_VERTICES*this->Sid()+i]);
1860 values[0]=vector[0];
1862 _error_(
"not implemented yet");
1865 for(i=0;i<NUM_VERTICES;i++) values[i]=vector[vertexids[i]-1];
1875 for(t=0;t<N;t++) times[t] = vector[(M-1)*N+t];
1878 for(i=0;i<NUM_VERTICES;i++) values[i]=vector[N*(vertexids[i]-1)+t];
1882 default:
_error_(
"Not implemented yet");
1885 xDelete<IssmDouble>(times);
1888 _error_(
"not implemented yet (M="<<M<<
")");
1891 xDelete<IssmDouble>(values);
1892 xDelete<int>(vertexids);
1893 xDelete<int>(vertexlids);
1895 else if(vector_type==2){
1914 else _error_(
"could not recognize nature of vector from code " << code);
1934 else _error_(
"element vector is either numberofelements or numberofelements+1 long. Field provided (" <<
EnumToStringx(input_enum) <<
") is " << M <<
" long");
1936 else if(vector_type==3){
1950 _error_(
"Cannot add input for vector type " << vector_type <<
" (not supported)");
1990 int migration_style;
2007 else _error_(
"migration_style not implemented yet");
2045 int basinid,num_basins,M,N;
2046 IssmDouble tf,gamma0,base,delta_t_basin,mean_tf_basin,absval,meltanomaly;
2054 IssmDouble* basalmeltrate = xNew<IssmDouble>(numvertices);
2076 delta_t_basin = delta_t[basinid];
2077 if(!islocal) mean_tf_basin = mean_tf[basinid];
2081 for(
int i=0;i<numvertices;i++){
2086 absval = mean_tf_basin+delta_t_basin;
2087 if (absval<0) {absval = -1.*absval;}
2088 basalmeltrate[i] = gamma0*pow((rhow*cp)/(rhoi*lf),2)*(tf+delta_t_basin)*absval + meltanomaly;
2091 basalmeltrate[i] = gamma0*pow((rhow*cp)/(rhoi*lf),2)*pow(
max(tf+delta_t_basin,0.),2) + meltanomaly;
2100 xDelete<IssmDouble>(delta_t);
2101 xDelete<IssmDouble>(mean_tf);
2102 xDelete<IssmDouble>(depths);
2103 xDelete<IssmDouble>(basalmeltrate);
2110 IssmDouble deepwaterel,upperwaterel,deepwatermelt,upperwatermelt;
2111 IssmDouble *base = xNew<IssmDouble>(NUM_VERTICES);
2112 IssmDouble *values = xNew<IssmDouble>(NUM_VERTICES);
2113 IssmDouble *perturbation = xNew<IssmDouble>(NUM_VERTICES);
2121 _assert_(upperwaterel>deepwaterel);
2125 for(
int i=0;i<NUM_VERTICES;i++){
2126 if(base[i]>=upperwaterel){
2127 values[i]=upperwatermelt;
2129 else if (base[i]<deepwaterel){
2130 values[i]=deepwatermelt;
2134 values[i]=deepwatermelt*
alpha+(1.-
alpha)*upperwatermelt;
2137 values[i]+=perturbation[i];
2141 xDelete<IssmDouble>(base);
2142 xDelete<IssmDouble>(perturbation);
2143 xDelete<IssmDouble>(values);
2150 IssmDouble *deepwatermelt = xNew<IssmDouble>(NUM_VERTICES);
2151 IssmDouble *deepwaterel = xNew<IssmDouble>(NUM_VERTICES);
2152 IssmDouble *upperwaterel = xNew<IssmDouble>(NUM_VERTICES);
2153 IssmDouble *base = xNew<IssmDouble>(NUM_VERTICES);
2154 IssmDouble *values = xNew<IssmDouble>(NUM_VERTICES);
2161 for(
int i=0;i<NUM_VERTICES;i++){
2162 if(base[i]>upperwaterel[i]) values[i]=0;
2163 else if (base[i]<deepwaterel[i]) values[i]=deepwatermelt[i];
2164 else values[i]=deepwatermelt[i]*(base[i]-upperwaterel[i])/(deepwaterel[i]-upperwaterel[i]);
2168 xDelete<IssmDouble>(base);
2169 xDelete<IssmDouble>(deepwaterel);
2170 xDelete<IssmDouble>(deepwatermelt);
2171 xDelete<IssmDouble>(upperwaterel);
2172 xDelete<IssmDouble>(values);
2178 IssmDouble mantleconductivity,nusselt,dtbg,plumeradius,topplumedepth,bottomplumedepth,plumex,plumey;
2179 IssmDouble crustthickness,uppercrustthickness,uppercrustheat,lowercrustheat;
2180 IssmDouble crustheat,plumeheat,dt,middleplumedepth,a,e,eprime,A0,lambda,Alambda,dAlambda;
2182 IssmDouble* values = xNew<IssmDouble>(NUM_VERTICES);
2200 a=(bottomplumedepth-topplumedepth)/2.;
2201 e=pow(a*a-c*c,1./2.)/a;
2202 A0=(1-pow(e,2.))/pow(e,3.)*(1./2.*log((1+e)/(1-e))-e);
2203 for(
int i=0;i<NUM_VERTICES;i++){
2204 y=xyz_list[i*3+0]-plumex;
2205 z=xyz_list[i*3+1]-plumey;
2206 x=-(a+topplumedepth+crustthickness);
2207 lambda=(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2)+sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2)))))/2;
2208 dAlambda=(-8*a*pow(c,2)*x*(-2*pow(a,2)+2*pow(c,2)+sqrt(2)*sqrt((a-c)*(a+c))*sqrt(pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2)+sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2))))))*(pow(a,4)*(pow(y,2)+pow(z,2))+pow(c,4)*(pow(y,2)+pow(z,2))+pow(pow(x,2)+pow(y,2)+pow(z,2),2)*(pow(x,2)+pow(y,2)+pow(z,2)+sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2)))))+pow(c,2)*(pow(x,4)-pow(x,2)*(pow(y,2)+pow(z,2))-(pow(y,2)+pow(z,2))*(2*pow(y,2)+2*pow(z,2)+sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2))))))+pow(a,2)*(-pow(x,4)+pow(x,2)*(pow(y,2)+pow(z,2))+(pow(y,2)+pow(z,2))*(-2*pow(c,2)+2*(pow(y,2)+pow(z,2))+sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2))))))))/(sqrt((a-c)*(a+c))*sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2))))*pow(pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2)+sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2)))),3.5)*pow(-(sqrt(2)*sqrt((a-c)*(a+c)))+sqrt(pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2)+sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2))))),2)*(sqrt(2)*sqrt((a-c)*(a+c))+sqrt(pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2)+sqrt(pow(-pow(a,2)-pow(c,2)+pow(x,2)+pow(y,2)+pow(z,2),2)+4*(pow(c,2)*pow(x,2)+pow(a,2)*(-pow(c,2)+pow(y,2)+pow(z,2)))))));
2209 eprime=pow((a*a-plumeradius*plumeradius)/(a*a+lambda),1./2.);
2210 Alambda=(1.-e*e)/(e*e*e)*(1./2.*log((1.+eprime)/(1.-eprime))-eprime);
2211 dt=dtbg-(nusselt-1.)/(1.+A0*(nusselt-1.))*(Alambda*dtbg+x*dtbg*dAlambda);
2212 plumeheat=mantleconductivity*dt;
2213 crustheat=uppercrustheat*uppercrustthickness+lowercrustheat*(crustthickness-uppercrustthickness);
2214 values[i]=crustheat+plumeheat;
2218 xDelete<IssmDouble>(xyz_list);
2219 xDelete<IssmDouble>(values);
2241 int i,migration_style;
2244 IssmDouble* melting = xNew<IssmDouble>(NUM_VERTICES);
2245 IssmDouble* phi = xNew<IssmDouble>(NUM_VERTICES);
2246 IssmDouble* h = xNew<IssmDouble>(NUM_VERTICES);
2247 IssmDouble* s = xNew<IssmDouble>(NUM_VERTICES);
2248 IssmDouble* b = xNew<IssmDouble>(NUM_VERTICES);
2249 IssmDouble* r = xNew<IssmDouble>(NUM_VERTICES);
2250 IssmDouble* sl = xNew<IssmDouble>(NUM_VERTICES);
2263 density = rho_ice/rho_water;
2266 for(i=0;i<NUM_VERTICES;i++){
2270 if(phi[i]>=0.) b[i]=r[i];
2274 else if(phi[i]<=0.){
2283 bed_hydro=-density*h[i]+sl[i];
2284 if (bed_hydro>r[i]){
2287 s[i] = (1-density)*h[i]+sl[i];
2288 b[i] = -density*h[i]+sl[i];
2291 s[i] = (1-density)*h[i]+sl[i];
2292 b[i] = -density*h[i]+sl[i];
2302 for(i=0;i<NUM_VERTICES;i++){
2304 bed_hydro=-density*h[i]+sl[i];
2305 if(phi[i]<0. || bed_hydro<=r[i] || phi_ungrounding[
vertices[i]->Pid()]<0.){
2306 phi[i]=h[i]+(r[i]-sl[i])/density;
2309 else if(migration_style!=
ContactEnum) phi[i]=h[i]+(r[i]-sl[i])/density;
2321 xDelete<IssmDouble>(melting);
2322 xDelete<IssmDouble>(phi);
2323 xDelete<IssmDouble>(r);
2324 xDelete<IssmDouble>(b);
2325 xDelete<IssmDouble>(s);
2326 xDelete<IssmDouble>(sl);
2327 xDelete<IssmDouble>(h);
2334 IssmDouble meltratefactor,thresholdthickness,upperdepthmelt;
2335 IssmDouble* base = xNew<IssmDouble>(NUM_VERTICES);
2336 IssmDouble* bed = xNew<IssmDouble>(NUM_VERTICES);
2337 IssmDouble* values = xNew<IssmDouble>(NUM_VERTICES);
2345 for(
int i=0;i<NUM_VERTICES;i++){
2346 if(base[i]>upperdepthmelt){
2350 values[i]=meltratefactor*tanh((base[i]-bed[i])/thresholdthickness)*(upperdepthmelt-base[i]);
2355 xDelete<IssmDouble>(base);
2356 xDelete<IssmDouble>(bed);
2357 xDelete<IssmDouble>(values);
2363 IssmDouble meltratefactor,T_f,ocean_heat_flux;
2370 IssmDouble* base = xNew<IssmDouble>(numvertices);
2371 IssmDouble* values = xNew<IssmDouble>(numvertices);
2372 IssmDouble* oceansalinity = xNew<IssmDouble>(numvertices);
2373 IssmDouble* oceantemp = xNew<IssmDouble>(numvertices);
2381 for(
int i=0;i<numvertices;i++){
2382 T_f=(0.0939 - 0.057 * oceansalinity[i] + 7.64e-4 * base[i]);
2386 ocean_heat_flux = meltratefactor * rho_water * mixed_layer_capacity * thermal_exchange_vel * (oceantemp[i] - T_f);
2390 values[i] = ocean_heat_flux / (latentheat * rho_ice);
2394 xDelete<IssmDouble>(base);
2395 xDelete<IssmDouble>(values);
2396 xDelete<IssmDouble>(oceantemp);
2397 xDelete<IssmDouble>(oceansalinity);
2405 const int NUM_VERTICES_MONTHS_PER_YEAR = NUM_VERTICES * 12;
2408 int* vertexlids=xNew<int>(NUM_VERTICES);
2409 IssmDouble* monthlytemperatures=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2410 IssmDouble* monthlyprec=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2411 IssmDouble* TemperaturesPresentday=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2412 IssmDouble* TemperaturesLgm=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2413 IssmDouble* PrecipitationsPresentday=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2414 IssmDouble* PrecipitationsLgm=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2415 IssmDouble* tmp=xNew<IssmDouble>(NUM_VERTICES);
2423 time_yr=floor(time/yts)*yts;
2433 for(
int month=0;month<12;month++) {
2434 for(
int iv=0;iv<NUM_VERTICES;iv++) {
2436 dinput1->
GetInputValue(&TemperaturesPresentday[iv*12+month],gauss,month);
2437 dinput2->
GetInputValue(&TemperaturesLgm[iv*12+month],gauss,month);
2438 dinput3->
GetInputValue(&PrecipitationsPresentday[iv*12+month],gauss,month);
2439 dinput4->
GetInputValue(&PrecipitationsLgm[iv*12+month],gauss,month);
2441 PrecipitationsPresentday[iv*12+month]=PrecipitationsPresentday[iv*12+month]*yts;
2442 PrecipitationsLgm[iv*12+month]=PrecipitationsLgm[iv*12+month]*yts;
2451 for(
int iv=0;iv<NUM_VERTICES;iv++){
2453 &PrecipitationsLgm[iv*12],&PrecipitationsPresentday[iv*12],
2454 &TemperaturesLgm[iv*12], &TemperaturesPresentday[iv*12],
2455 &monthlytemperatures[iv*12], &monthlyprec[iv*12]);
2459 for (
int imonth=0;imonth<12;imonth++) {
2460 for(i=0;i<NUM_VERTICES;i++) tmp[i]=monthlytemperatures[i*12+imonth];
2464 default:
_error_(
"Not implemented yet");
2466 for(i=0;i<NUM_VERTICES;i++) tmp[i]=monthlyprec[i*12+imonth]/yts;
2470 default:
_error_(
"Not implemented yet");
2481 default:
_error_(
"Not implemented yet");
2486 xDelete<IssmDouble>(monthlytemperatures);
2487 xDelete<IssmDouble>(monthlyprec);
2488 xDelete<IssmDouble>(TemperaturesPresentday);
2489 xDelete<IssmDouble>(TemperaturesLgm);
2490 xDelete<IssmDouble>(PrecipitationsPresentday);
2491 xDelete<IssmDouble>(PrecipitationsLgm);
2492 xDelete<IssmDouble>(tmp);
2493 xDelete<int>(vertexlids);
2517 IssmDouble boxid_max=reCast<IssmDouble>(max_boxid_basin_list[basin_id])+1.;
2529 dist_gl = fabs(dist_gl);
2530 dist_cf = fabs(dist_cf);
2533 IssmDouble rel_dist_gl=dist_gl/(dist_gl+dist_cf);
2538 IssmDouble lowbound = 1. -sqrt((boxid_max-i )/boxid_max);
2539 IssmDouble highbound = 1. -sqrt((boxid_max-i-1.)/boxid_max);
2540 if(rel_dist_gl>=lowbound && rel_dist_gl<=highbound){
2541 boxid=reCast<int>(i);
2545 if(boxid==-1)
_error_(
"No boxid found for element " << this->
Sid() <<
"!");
2556 if(loopboxid!=boxid)
return;
2560 int basinid, maxbox, num_basins, numnodes, M;
2561 IssmDouble gamma_T, overturning_coeff, thickness;
2562 IssmDouble pressure, T_star,p_coeff, q_coeff;
2593 IssmDouble area_boxi = boxareas[basinid*maxbox+boxid];
2596 IssmDouble* basalmeltrates_shelf = xNew<IssmDouble>(NUM_VERTICES);
2597 IssmDouble* potential_pressure_melting_point = xNew<IssmDouble>(NUM_VERTICES);
2598 IssmDouble* Tocs = xNew<IssmDouble>(NUM_VERTICES);
2599 IssmDouble* Socs = xNew<IssmDouble>(NUM_VERTICES);
2609 IssmDouble* overturnings = xNew<IssmDouble>(NUM_VERTICES);
2614 for(
int i=0;i<NUM_VERTICES;i++){
2617 overturningC_input->
GetInputValue(&overturning_coeff,gauss);
2618 pressure = (rhoi*earth_grav*1e-4)*thickness;
2619 T_star = a*soc_farocean+b-c*pressure-toc_farocean;
2620 p_coeff = g1/(overturning_coeff*rho_star*(Beta*s1-
alpha));
2621 q_coeff = T_star*(g1/(overturning_coeff*rho_star*(Beta*s1-
alpha)));
2624 if((0.25*pow(p_coeff,2)-q_coeff)<0) q_coeff = 0.25*p_coeff*p_coeff;
2626 Tocs[i] = toc_farocean-(-0.5*p_coeff+sqrt(0.25*pow(p_coeff,2)-q_coeff));
2627 Socs[i] = soc_farocean-(soc_farocean/(nu*lambda))*(toc_farocean-Tocs[i]);
2628 potential_pressure_melting_point[i] = a*Socs[i]+b-c*pressure;
2629 if(!isplume) basalmeltrates_shelf[i] = (-gamma_T/(nu*lambda))*(potential_pressure_melting_point[i]-Tocs[i]);
2630 overturnings[i] = overturning_coeff*rho_star*(Beta*(soc_farocean-Socs[i])-
alpha*(toc_farocean-Tocs[i]));
2651 IssmDouble mean_toc = toc_weighted_avg[basinid];
2652 IssmDouble mean_soc = soc_weighted_avg[basinid];
2653 IssmDouble mean_overturning = overturning_weighted_avg[basinid];
2658 for(
int i=0;i<NUM_VERTICES;i++){
2661 pressure = (rhoi*earth_grav*1.e-4)*thickness;
2662 T_star = a*mean_soc+b-c*pressure-mean_toc;
2663 Tocs[i] = mean_toc+T_star*(g1/(mean_overturning+g1-g2*a*mean_soc));
2664 Socs[i] = mean_soc-mean_soc*((mean_toc-Tocs[i])/(nu*lambda));
2665 potential_pressure_melting_point[i] = a*Socs[i]+b-c*pressure;
2666 if(!isplume) basalmeltrates_shelf[i] = (-gamma_T/(nu*lambda))*(potential_pressure_melting_point[i]-Tocs[i]);
2674 xDelete<IssmDouble>(toc_weighted_avg);
2675 xDelete<IssmDouble>(soc_weighted_avg);
2676 xDelete<IssmDouble>(overturning_weighted_avg);
2681 xDelete<IssmDouble>(boxareas);
2690 IssmDouble E0, Cd, CdT, YT, lam1, lam2, lam3, M0, CdTS0, y1, y2, x0;
2691 IssmDouble Tf_gl, YTS, CdTS, G1, G2, G3, g_alpha, M, l, X_hat, M_hat;
2709 IssmDouble* basalmeltrates_shelf = xNew<IssmDouble>(NUM_VERTICES);
2713 p[0] = 0.1371330075095435;
2714 p[1] = 5.527656234709359E1;
2715 p[2] = -8.951812433987858E2;
2716 p[3] = 8.927093637594877E3;
2717 p[4] = -5.563863123811898E4;
2718 p[5] = 2.218596970948727E5;
2719 p[6] = -5.820015295669482E5;
2720 p[7] = 1.015475347943186E6;
2721 p[8] = -1.166290429178556E6;
2722 p[9] = 8.466870335320488E5;
2723 p[10] = -3.520598035764990E5;
2724 p[11] = 6.387953795485420E4;
2737 for(
int i=0;i<NUM_VERTICES;i++){
2749 alpha = atan(sqrt(slopex*slopex + slopey*slopey));
2754 if(zgl>z_base) zgl=z_base;
2757 if(Toc<lam1*Soc+lam2) Toc=lam1*Soc+lam2;
2760 Tf_gl = lam1*Soc+lam2+lam3*zgl;
2761 YTS = YT*(y1+y2*(((Toc-Tf_gl)*E0*sin(
alpha))/(lam3*(CdTS0+E0*sin(
alpha)))));
2762 CdTS = sqrt(Cd)*YTS;
2764 G2 = sqrt(CdTS/(CdTS+E0*sin(
alpha)));
2767 M = M0*g_alpha*pow((Toc-Tf_gl),2);
2768 l = ((Toc-Tf_gl)*(x0*CdTS+E0*sin(
alpha)))/(lam3*x0*(CdTS+E0*sin(
alpha)));
2769 X_hat = (z_base-zgl)/l;
2773 for(
int ii=0;ii<12;ii++) {
2774 M_hat += p[ii]*pow(X_hat,ii);
2778 basalmeltrates_shelf[i] = (M*M_hat)/yts;
2791 const int NUM_VERTICES_MONTHS_PER_YEAR = NUM_VERTICES * 12;
2794 IssmDouble* agd=xNew<IssmDouble>(NUM_VERTICES);
2796 IssmDouble* accu=xNew<IssmDouble>(NUM_VERTICES);
2797 IssmDouble* monthlytemperatures=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2798 IssmDouble* monthlyprec=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2799 IssmDouble* yearlytemperatures=xNew<IssmDouble>(NUM_VERTICES); memset(yearlytemperatures, 0., NUM_VERTICES*
sizeof(
IssmDouble));
2800 IssmDouble* tmp=xNew<IssmDouble>(NUM_VERTICES);
2801 IssmDouble* h=xNew<IssmDouble>(NUM_VERTICES);
2802 IssmDouble* s=xNew<IssmDouble>(NUM_VERTICES);
2803 IssmDouble* s0p=xNew<IssmDouble>(NUM_VERTICES);
2804 IssmDouble* s0t=xNew<IssmDouble>(NUM_VERTICES);
2807 IssmDouble rho_water,rho_ice,desfac,rlaps,rlapslgm;
2826 time_yr=floor(time/yts)*yts;
2834 for(
int month=0;month<12;month++) {
2837 for(
int iv=0;iv<NUM_VERTICES;iv++) {
2839 dinput->
GetInputValue(&monthlytemperatures[iv*12+month],gauss,month);
2841 monthlytemperatures[iv*12+month]=monthlytemperatures[iv*12+month]-273.15;
2842 dinput2->
GetInputValue(&monthlyprec[iv*12+month],gauss,month);
2843 monthlyprec[iv*12+month]=monthlyprec[iv*12+month]*yts;
2876 for(
int iv = 0; iv<NUM_VERTICES; iv++){
2885 pdds, pds, &
melt[iv], &accu[iv], signorm, yts, h[iv], s[iv],
2886 desfac, s0t[iv], s0p[iv],rlaps,rlapslgm,TdiffTime,sealevTime,
2887 pddsnowfac,pddicefac,rho_water,rho_ice);
2889 for(
int month=0;month<12;month++) {
2890 yearlytemperatures[iv]=yearlytemperatures[iv]+(monthlytemperatures[iv*12+month]+273.15)*mavg;
2957 default:
_error_(
"Not implemented yet");
2962 xDelete<IssmDouble>(monthlytemperatures);
2963 xDelete<IssmDouble>(monthlyprec);
2964 xDelete<IssmDouble>(agd);
2965 xDelete<IssmDouble>(
melt);
2966 xDelete<IssmDouble>(accu);
2967 xDelete<IssmDouble>(yearlytemperatures);
2968 xDelete<IssmDouble>(h);
2969 xDelete<IssmDouble>(s);
2970 xDelete<IssmDouble>(s0t);
2971 xDelete<IssmDouble>(s0p);
2972 xDelete<IssmDouble>(tmp);
2980 const int NUM_VERTICES_MONTHS_PER_YEAR = NUM_VERTICES * 12;
2983 IssmDouble* smb=xNew<IssmDouble>(NUM_VERTICES);
2985 IssmDouble* accu=xNew<IssmDouble>(NUM_VERTICES);
2986 IssmDouble* melt_star=xNew<IssmDouble>(NUM_VERTICES);
2987 IssmDouble* monthlytemperatures=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2988 IssmDouble* monthlyprec=xNew<IssmDouble>(NUM_VERTICES_MONTHS_PER_YEAR);
2989 IssmDouble* yearlytemperatures=xNew<IssmDouble>(NUM_VERTICES); memset(yearlytemperatures, 0., NUM_VERTICES*
sizeof(
IssmDouble));
2990 IssmDouble* s=xNew<IssmDouble>(NUM_VERTICES);
2991 IssmDouble* s0p=xNew<IssmDouble>(NUM_VERTICES);
2992 IssmDouble* s0t=xNew<IssmDouble>(NUM_VERTICES);
2993 IssmDouble* smbcorr=xNew<IssmDouble>(NUM_VERTICES);
2994 IssmDouble* p_ampl=xNew<IssmDouble>(NUM_VERTICES);
2995 IssmDouble* t_ampl=xNew<IssmDouble>(NUM_VERTICES);
3014 time_yr=floor(time/yts)*yts;
3018 IssmDouble mu = MU_0*(1000.0*86400.0)*(rho_ice/rho_water);
3026 for(
int month=0;month<12;month++){
3028 for(
int iv=0;iv<NUM_VERTICES;iv++){
3030 dinput->
GetInputValue(&monthlytemperatures[iv*12+month],gauss,month);
3031 monthlytemperatures[iv*12+month]=monthlytemperatures[iv*12+month]-273.15;
3032 dinput2->
GetInputValue(&monthlyprec[iv*12+month],gauss,month);
3033 monthlyprec[iv*12+month]=monthlyprec[iv*12+month]*yts;
3046 for (
int iv = 0; iv<NUM_VERTICES; iv++){
3048 &
melt[iv], &accu[iv], &melt_star[iv], &t_ampl[iv], &p_ampl[iv], yts, s[iv],
3049 desfac, s0t[iv], s0p[iv],rlaps,rho_water,rho_ice);
3052 smb[iv] = smb[iv]+smbcorr[iv];
3054 for(
int month=0;month<12;month++) yearlytemperatures[iv]=yearlytemperatures[iv]+((monthlytemperatures[iv*12+month]+273.15)+t_ampl[iv])*inv_twelve;
3057 if(melt_star[iv]>=
melt[iv]){
3058 yearlytemperatures[iv]= yearlytemperatures[iv]+mu*(melt_star[iv]-
melt[iv]);
3061 yearlytemperatures[iv]= yearlytemperatures[iv];
3064 if (yearlytemperatures[iv]>273.15) yearlytemperatures[iv]=273.15;
3142 default:
_error_(
"Not implemented yet");
3147 xDelete<IssmDouble>(monthlytemperatures);
3148 xDelete<IssmDouble>(monthlyprec);
3149 xDelete<IssmDouble>(smb);
3150 xDelete<IssmDouble>(
melt);
3151 xDelete<IssmDouble>(accu);
3152 xDelete<IssmDouble>(yearlytemperatures);
3153 xDelete<IssmDouble>(s);
3154 xDelete<IssmDouble>(s0t);
3155 xDelete<IssmDouble>(s0p);
3156 xDelete<IssmDouble>(t_ampl);
3157 xDelete<IssmDouble>(p_ampl);
3158 xDelete<IssmDouble>(smbcorr);
3159 xDelete<IssmDouble>(melt_star);
3165 switch(output_enum){
3244 *pinterpolation =
P0Enum;
3245 *pnodesperelement = 1;
3249 *pinterpolation =
P0Enum;
3250 *pnodesperelement = 1;
3257 *pnodesperelement = 1;
3280 ElementInput2* element_input = xDynamicCast<ElementInput2*>(input);
3284 _assert_(numnodes==nodesperelement);
3287 for(
int i=0;i<numnodes;i++) values[this->
sid*numnodes + i] = element_input->
element_values[i];
3295 for(
int i=0;i<m;i++) values[this->
Sid()*ncols + i] = array[i];
3296 xDelete<IssmDouble>(array);
3331 for(
int i=0;i<NUM_VERTICES;i++) values[i] = values[i]/reCast<IssmDouble>(connectivity[i]);
3379 for(
int i=0;i<numnodes;i++){
3381 if(!flags[this->
nodes[i]->Lid()]){
3387 while(flagsindices[counter]>=0) counter++;
3388 flagsindices[counter]=this->nodes[i]->Lid();
3393 if(
nodes[i]->fsize){
3394 if(this->nodes[i]->IsClone())
3401 if(
nodes[i]->gsize){
3402 if(this->nodes[i]->IsClone())
3409 if(
nodes[i]->ssize){
3410 if(this->nodes[i]->IsClone())
3416 default:
_error_(
"not supported");
3423 int analysis_type,approximation,numlayers;
3429 o_nz += numlayers*3;
3430 d_nz += numlayers*3;
3446 const int NUM_VERTICES_DAYS_PER_YEAR = NUM_VERTICES * 365;
3448 IssmDouble* s=xNew<IssmDouble>(NUM_VERTICES);
3449 IssmDouble* s0gcm=xNew<IssmDouble>(NUM_VERTICES);
3450 IssmDouble* st=xNew<IssmDouble>(NUM_VERTICES);
3453 IssmDouble* dailyrainfall=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3454 IssmDouble* dailysnowfall=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3455 IssmDouble* dailydlradiation=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3456 IssmDouble* dailydsradiation=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3457 IssmDouble* dailywindspeed=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3458 IssmDouble* dailypressure=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3459 IssmDouble* dailyairdensity=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3460 IssmDouble* dailyairhumidity=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3461 IssmDouble* dailytemperature=xNew<IssmDouble>(NUM_VERTICES_DAYS_PER_YEAR);
3463 IssmDouble* tsurf_out=xNew<IssmDouble>(NUM_VERTICES); memset(tsurf_out, 0., NUM_VERTICES*
sizeof(
IssmDouble));
3464 IssmDouble* smb_out=xNew<IssmDouble>(NUM_VERTICES); memset(smb_out, 0., NUM_VERTICES*
sizeof(
IssmDouble));
3465 IssmDouble* saccu_out=xNew<IssmDouble>(NUM_VERTICES); memset(saccu_out, 0., NUM_VERTICES*
sizeof(
IssmDouble));
3466 IssmDouble* smelt_out=xNew<IssmDouble>(NUM_VERTICES); memset(smelt_out, 0., NUM_VERTICES*
sizeof(
IssmDouble));
3468 IssmDouble rho_water,rho_ice,desfac,rlaps,rdl;
3474 time_yr=floor(time/yts)*yts;
3489 for (
int iday = 0; iday < 365; iday++){
3501 for(
int iv=0;iv<NUM_VERTICES;iv++){
3504 dailyrainfall_input->
GetInputValue(&dailyrainfall[iv*365+iday],gauss);
3505 dailysnowfall_input->
GetInputValue(&dailysnowfall[iv*365+iday],gauss);
3506 dailydlradiation_input->
GetInputValue(&dailydlradiation[iv*365+iday],gauss);
3507 dailydsradiation_input->
GetInputValue(&dailydsradiation[iv*365+iday],gauss);
3508 dailywindspeed_input->
GetInputValue(&dailywindspeed[iv*365+iday],gauss);
3509 dailypressure_input->
GetInputValue(&dailypressure[iv*365+iday],gauss);
3510 dailyairdensity_input->
GetInputValue(&dailyairdensity[iv*365+iday],gauss);
3511 dailyairhumidity_input->
GetInputValue(&dailyairhumidity[iv*365+iday],gauss);
3512 dailytemperature_input->
GetInputValue(&dailytemperature[iv*365+iday],gauss);
3515 st[iv]=(s[iv]-s0gcm[iv])/1000.;
3516 dailytemperature[iv*365+iday]=dailytemperature[iv*365+iday]-rlaps *st[iv];
3519 if (s0gcm[iv] < 2000.0) {
3520 dailysnowfall[iv*365+iday] = dailysnowfall[iv*365+iday]*exp(desfac*(
max(s[iv],2000.0)-2000.0));
3521 dailyrainfall[iv*365+iday] = dailyrainfall[iv*365+iday]*exp(desfac*(
max(s[iv],2000.0)-2000.0));
3523 dailysnowfall[iv*365+iday] = dailysnowfall[iv*365+iday]*exp(desfac*(
max(s[iv],2000.0)-s0gcm[iv]));
3524 dailyrainfall[iv*365+iday] = dailyrainfall[iv*365+iday]*exp(desfac*(
max(s[iv],2000.0)-s0gcm[iv]));
3528 st[iv]=(s[iv]-s0gcm[iv])/1000.;
3529 dailydlradiation[iv*365+iday]=dailydlradiation[iv*365+iday]+rdl*st[iv];
3533 for (
int iv = 0; iv<NUM_VERTICES; iv++){
3535 run_semic_(&dailysnowfall[iv*365], &dailyrainfall[iv*365], &dailydsradiation[iv*365], &dailydlradiation[iv*365],
3536 &dailywindspeed[iv*365], &dailypressure[iv*365], &dailyairdensity[iv*365], &dailyairhumidity[iv*365], &dailytemperature[iv*365],
3537 &tsurf_out[iv], &smb_out[iv], &saccu_out[iv], &smelt_out[iv]);
3553 default:
_error_(
"Not implemented yet");
3558 xDelete<IssmDouble>(dailysnowfall);
3559 xDelete<IssmDouble>(dailyrainfall);
3560 xDelete<IssmDouble>(dailydlradiation);
3561 xDelete<IssmDouble>(dailydsradiation);
3562 xDelete<IssmDouble>(dailywindspeed);
3563 xDelete<IssmDouble>(dailypressure);
3564 xDelete<IssmDouble>(dailyairdensity);
3565 xDelete<IssmDouble>(dailyairhumidity);
3566 xDelete<IssmDouble>(dailypressure);
3567 xDelete<IssmDouble>(dailytemperature);
3568 xDelete<IssmDouble>(smb_out);
3569 xDelete<IssmDouble>(smelt_out);
3570 xDelete<IssmDouble>(saccu_out);
3571 xDelete<IssmDouble>(tsurf_out);
3572 xDelete<IssmDouble>(s);
3573 xDelete<IssmDouble>(st);
3574 xDelete<IssmDouble>(s0gcm);
3577 #endif // _HAVE_SEMIC_
3631 bool isgraingrowth,isalbedo,isshortwave,isthermal,isaccumulation,ismelt,isdensification,isturbulentflux;
3632 bool isclimatology=
false;
3633 bool isconstrainsurfaceT=
false;
3759 d = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)d[i]=dini[0];
3760 re = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)re[i]=reini[0];
3761 gdn = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)gdn[i]=gdnini[0];
3762 gsp = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)gsp[i]=gspini[0];
3763 W = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)W[i]=Wini[0];
3764 a = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)a[i]=aini[0];
3765 T = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)T[i]=Tmean;
3776 dz = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)dz[i]=dzini[i];
3777 d = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)d[i]=dini[i];
3778 re = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)re[i]=reini[i];
3779 gdn = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)gdn[i]=gdnini[i];
3780 gsp = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)gsp[i]=gspini[i];
3781 W = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)W[i]=Wini[i];
3782 a = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)a[i]=aini[i];
3783 T = xNew<IssmDouble>(m);
for(
int i=0;i<m;i++)T[i]=Tini[i];
3812 initMass=0;
for(
int i=0;i<m;i++) initMass += dz[i]*d[i] + W[i];
3815 sumR = 0; sumM = 0; sumEC = 0; sumP = 0; sumMassAdd = 0; sumMsurf = 0;
3821 if(
VerboseSmb() && this->
Sid()==0 &&
IssmComm::GetRank()==0)
_printf0_(
"Time: t=" << setprecision(8) << timeinputs/365.0/24.0/3600.0 <<
" yr/" << (time+dt)/365.0/24.0/3600.0 <<
" yr" << setprecision(3) <<
" Step: " << count <<
"\n");
3846 sumMassAdd=sumMassAdd*dt;
3849 sumEC=sumEC*dt*rho_ice;
3851 sumM=sumM*dt*rho_ice;
3853 sumMsurf=sumMsurf*dt*rho_ice;
3855 sumR=sumR*dt*rho_ice;
3857 sumP=sumP*dt*rho_ice;
3886 if(isgraingrowth)
grainGrowth(&re, &gdn, &gsp, T, dz, d, W, smb_dt, m, aIdx,this->
Sid());
3889 if(isalbedo)
albedo(&a,aIdx,re,dz,d,cldFrac,aIce,aSnow,aValue,adThresh,T,W,P,EC,Msurf,t0wet,t0dry,K,smb_dt,rho_ice,m,this->
Sid());
3892 if(isshortwave)
shortwave(&swf, swIdx, aIdx, dsw, a[0], d, dz, re,rho_ice,m,this->
Sid());
3895 netSW = netSW +
cellsum(swf,m)*smb_dt/dt;
3897 if(isconstrainsurfaceT){
3902 if(isthermal)
thermo(&EC, &T, &ulw, dz, d, swf, dlw, Ta, V, eAir, pAir, teValue, W[0], smb_dt, m, Vz, Tz, thermo_scaling,rho_ice,this->
Sid(),isconstrainsurfaceT);
3906 dz[0] = dz[0] + EC / d[0];
3909 if(isaccumulation)
accumulation(&T, &dz, &d, &W, &a, &re, &gdn, &gsp, &m, aIdx, dsnowIdx, Tmean, Ta, P, dzMin, aSnow, C, V, Vmean, rho_ice,this->
Sid());
3913 if(ismelt)
melt(&M, &Msurf, &
R, &mAdd, &dz_add, &T, &d, &dz, &W, &a, &re, &gdn, &gsp, &m, dzMin, zMax, zMin, zTop, zY, rho_ice,this->
Sid());
3916 if(isdensification)
densification(&d,&dz, T, re, denIdx, C, smb_dt, Tmean,rho_ice,m,this->
Sid());
3923 meanULW = meanULW + ulw*smb_dt/dt;
3924 netLW = netLW + (dlw - ulw)*smb_dt/dt;
3927 if(isturbulentflux)
turbulentFlux(&shf, &lhf, &dayEC, Ta, T[0], V, eAir, pAir, d[0], W[0], Vz, Tz,rho_ice,this->
Sid());
3931 _printf_(
"smb log: count[" << count <<
"] m[" << m <<
"] "
3932 << setprecision(16) <<
"T[" <<
cellsum(T,m) <<
"] "
3933 <<
"d[" <<
cellsum(d,m) <<
"] "
3934 <<
"dz[" <<
cellsum(dz,m) <<
"] "
3935 <<
"a[" <<
cellsum(a,m) <<
"] "
3936 <<
"W[" <<
cellsum(W,m) <<
"] "
3937 <<
"re[" <<
cellsum(re,m) <<
"] "
3938 <<
"gdn[" <<
cellsum(gdn,m) <<
"] "
3939 <<
"gsp[" <<
cellsum(gsp,m) <<
"] "
3940 <<
"swf[" << netSW <<
"] "
3941 <<
"lwf[" << netLW <<
"] "
3942 <<
"a[" << a <<
"] "
3943 <<
"te[" << teValue <<
"] "
3947 meanLHF = meanLHF + lhf*smb_dt/dt;
3948 meanSHF = meanSHF + shf*smb_dt/dt;
3951 sumMassAdd = mAdd + sumMassAdd;
3953 sumMsurf = Msurf + sumMsurf;
3962 for(
int i=0;i<m;i++){
3963 sumMass += dz[i]*d[i];
3964 if (d[i] > 0) fac += dz[i]*(rho_ice - fmin(d[i],rho_ice));
3967 #if defined(_HAVE_AD_)
3969 _error_(
"not implemented yet");
3971 dMass = sumMass + sumR + sumW - sumP - sumEC - initMass - sumMassAdd;
3972 dMass = round(dMass * 100.0)/100.0;
3976 _printf_(
"total system mass not conserved in MB function \n");
3982 if (T[m-1]!=T_bottom)
_printf_(
"T(end)~=T_bottom" <<
"\n");
4013 if(dz) xDelete<IssmDouble>(dz);
4014 if(d) xDelete<IssmDouble>(d);
4015 if(re) xDelete<IssmDouble>(re);
4016 if(gdn) xDelete<IssmDouble>(gdn);
4017 if(gsp) xDelete<IssmDouble>(gsp);
4018 if(W) xDelete<IssmDouble>(W);
4019 if(a) xDelete<IssmDouble>(a);
4020 if(T) xDelete<IssmDouble>(T);
4021 if(dzini) xDelete<IssmDouble>(dzini);
4022 if(dini) xDelete<IssmDouble>(dini);
4023 if(reini) xDelete<IssmDouble>(reini);
4024 if(gdnini) xDelete<IssmDouble>(gdnini);
4025 if(gspini) xDelete<IssmDouble>(gspini);
4026 if(Wini) xDelete<IssmDouble>(Wini);
4027 if(aini) xDelete<IssmDouble>(aini);
4028 if(Tini) xDelete<IssmDouble>(Tini);
4029 if(swf) xDelete<IssmDouble>(swf);
4042 if(!vx_input || !vy_input){
4043 _error_(
"Input missing. Here are the input pointers we have for vx: " << vx_input <<
", vy: " << vy_input <<
"\n");
4049 epsilon[0] = dvx[0];
4050 epsilon[1] = dvy[1];
4051 epsilon[2] = 0.5*(dvx[1] + dvy[0]);
4052 epsilon[3] = 0.5*(dvx[1] - dvy[0]);
4067 if (!vx_input || !vy_input || !vz_input){
4068 _error_(
"Input missing. Here are the input pointers we have for vx: " << vx_input <<
", vy: " << vy_input <<
", vz: " << vz_input <<
"\n");
4076 epsilon[0] = dvx[0];
4077 epsilon[1] = dvy[1];
4078 epsilon[2] = dvz[2];
4079 epsilon[3] = 0.5*(dvx[1] + dvy[0]);
4080 epsilon[4] = 0.5*(dvx[2] + dvz[0]);
4081 epsilon[5] = 0.5*(dvy[2] + dvz[1]);
4100 if (!vx_input || !vy_input){
4101 _error_(
"Input missing. Here are the input pointers we have for vx: " << vx_input <<
", vy: " << vy_input <<
"\n");
4107 epsilon[0] = dvx[0];
4108 epsilon[1] = dvy[1];
4109 epsilon[2] = 0.5*(dvx[1] + dvy[0]);
4110 epsilon[3] = 0.5*dvx[2];
4111 epsilon[4] = 0.5*dvy[2];
4129 _error_(
"Input missing. Here are the input pointers we have for vx: " << vx_input <<
"\n");
4134 epsilon[0] = dvx[0];
4135 epsilon[1] = 0.5*dvx[1];
4145 if(!vx_input || !vy_input){
4146 _error_(
"Input missing. Here are the input pointers we have for vx: " << vx_input <<
", vy: " << vy_input <<
"\n");
4152 epsilon[0] = dvx[0];
4153 epsilon[1] = dvy[1];
4154 epsilon[2] = 0.5*(dvx[1] + dvy[0]);
4164 _error_(
"Input missing. Here are the input pointers we have for vx: " << vx_input <<
"\n");
4176 IssmDouble sigma_xx,sigma_yy,sigma_zz,sigma_xy,sigma_xz,sigma_yz;
4189 IssmDouble* maxprincipal = xNew<IssmDouble>(NUM_VERTICES);
4196 Input2* sigma_xz_input = NULL;
4197 Input2* sigma_yz_input = NULL;
4198 Input2* sigma_zz_input = NULL;
4207 for (
int iv=0;iv<NUM_VERTICES;iv++){
4222 c = -sigma_yy -sigma_xx;
4223 d = sigma_xx*sigma_yy - sigma_xy*sigma_xy;
4227 b = sigma_xx+sigma_yy+sigma_zz;
4228 c = -sigma_xx*sigma_yy -sigma_xx*sigma_zz -sigma_yy*sigma_zz + sigma_xy*sigma_xy +sigma_xz*sigma_xz +sigma_yz*sigma_yz;
4229 d = sigma_xx*sigma_yy*sigma_zz - sigma_xx*sigma_yz*sigma_yz -sigma_yy*sigma_xz*sigma_xz - sigma_zz*sigma_xy*sigma_xy + 2.*sigma_xy*sigma_xz*sigma_yz;
4233 cubic(a,b,c,d,x,&numroots);
4240 _error_(
"No eigen value found");
4244 for(
int i=1;i<numroots;i++){
4245 if(fabs(x[i])>
max)
max = fabs(x[i]);
4248 maxprincipal[iv]=
max;
4255 xDelete<IssmDouble>(maxprincipal);
4256 xDelete<IssmDouble>(xyz_list);
4303 int* cs_array = xNew<int>(numnodes);
4304 for(
int i=0;i<numnodes;i++) cs_array[i]=transformenum;
4310 xDelete<int>(cs_array);
4320 for(i=0;i<numnodes;i++){
4321 switch(cs_array[i]){
4323 case XYEnum: numdofs+=2;
break;
4324 case XYZEnum: numdofs+=3;
break;
4330 values=xNew<IssmDouble>(Ke->
nrows*Ke->
ncols);
4339 transform,numdofs,numdofs,1,
4343 xDelete<IssmDouble>(transform);
4344 xDelete<IssmDouble>(values);
4350 int* cs_array = xNew<int>(numnodes);
4351 for(
int i=0;i<numnodes;i++) cs_array[i]=transformenum;
4357 xDelete<int>(cs_array);
4372 for(i=0;i<numnodes;i++){
4373 switch(cs_array[i]){
4375 case XYEnum: numdofs+=2;
break;
4376 case XYZEnum: numdofs+=3;
break;
4382 values=xNew<IssmDouble>(pe->
nrows);
4390 values,pe->
nrows,1,0,
4394 xDelete<IssmDouble>(transform);
4395 xDelete<IssmDouble>(values);
4401 int* cs_array = xNew<int>(numnodes);
4402 for(
int i=0;i<numnodes;i++) cs_array[i]=transformenum;
4408 xDelete<int>(cs_array);
4416 int* cs_array = xNew<int>(numnodes);
4417 for(
int i=0;i<numnodes;i++) cs_array[i]=transformenum;
4423 xDelete<int>(cs_array);
4431 int* cs_array = xNew<int>(numnodes);
4432 for(
int i=0;i<numnodes;i++) cs_array[i]=transformenum;
4438 xDelete<int>(cs_array);
4448 for(i=0;i<numnodes;i++){
4449 switch(cs_array[i]){
4451 case XYEnum: numdofs+=2;
break;
4452 case XYZEnum: numdofs+=3;
break;
4458 values=xNew<IssmDouble>(numdofs);
4459 for(i=0;i<numdofs;i++) values[i]=solution[i];
4470 xDelete<IssmDouble>(transform);
4471 xDelete<IssmDouble>(values);
4477 int* cs_array = xNew<int>(numnodes);
4478 for(
int i=0;i<numnodes;i++) cs_array[i]=transformenum;
4484 xDelete<int>(cs_array);
4496 for(
int i=0;i<numnodes;i++){
4497 switch(cs_array[i]){
4499 case XYEnum: numdofs+=2;
break;
4500 case XYZEnum: numdofs+=3;
break;
4506 values=xNew<IssmDouble>(Ke->
nrows*Ke->
ncols);
4515 transform,numdofs,numdofs,0,
4519 xDelete<IssmDouble>(transform);
4520 xDelete<IssmDouble>(values);
4532 IssmDouble* viscousheating = xNew<IssmDouble>(NUM_VERTICES);
4542 for (
int iv=0;iv<NUM_VERTICES;iv++){
4545 this->
ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
4547 viscousheating[iv]=phi;
4554 xDelete<IssmDouble>(viscousheating);
4555 xDelete<IssmDouble>(xyz_list);
4567 IssmDouble latentheat,referencetemperature,heatcapacity;
4573 enthalpy=heatcapacity*(temperature-referencetemperature);
4580 *penthalpy=enthalpy;
4590 return meltingpoint-beta*pressure;
4599 IssmDouble latentheat,referencetemperature,heatcapacity;
4605 temperature=referencetemperature+enthalpy/heatcapacity;
4614 *pwaterfraction=waterfraction;
4615 *ptemperature=temperature;
4621 IssmDouble heatcapacity,thermalconductivity,temperateiceconductivity;
4627 return thermalconductivity/heatcapacity;
4630 return temperateiceconductivity/heatcapacity;
4639 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
4640 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
4642 for(
int iv=0; iv<numvertices; iv++){
4644 dHpmp[iv]=enthalpy[iv]-PIE[iv];
4647 bool allequalsign=
true;
4649 for(
int iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0));
4652 for(
int iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0));
4664 for(
int iv=0; iv<numvertices;iv++){
4665 if(enthalpy[iv]<PIE[iv])
4666 Hc+=(PIE[iv]-enthalpy[iv]);
4668 Ht+=(enthalpy[iv]-PIE[iv]);
4671 lambda = Hc/(Hc+Ht);
4672 kappa = 1./(lambda/kappa_c + (1.-lambda)/kappa_t);
4676 xDelete<IssmDouble>(PIE);
4677 xDelete<IssmDouble>(dHpmp);
4684 IssmDouble referencetemperature,heatcapacity;
4688 return heatcapacity*(
TMeltingPoint(pressure)-referencetemperature);