Changeset 25905
- Timestamp:
- 12/20/20 13:01:58 (4 years ago)
- Location:
- issm/trunk-jpl/src/c/classes/Elements
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/Elements/Element.cpp
r25807 r25905 651 651 const int NUM_VERTICES = this->GetNumberOfVertices(); 652 652 653 int i; 654 IssmDouble accuref, runoffref; //reference values at given altitude 655 IssmDouble accualti, runoffalti; //reference altitudes 653 IssmDouble accuref, runoffref; //reference values at given altitude 656 654 IssmDouble accugrad, runoffgrad; //gradients from reference altitude 657 IssmDouble rho_water, rho_ice; 658 IssmDouble time; 659 660 IssmDouble* smb = xNew<IssmDouble>(NUM_VERTICES); 661 IssmDouble* surf = xNew<IssmDouble>(NUM_VERTICES); 662 IssmDouble* accu = xNew<IssmDouble>(NUM_VERTICES); 663 IssmDouble* runoff = xNew<IssmDouble>(NUM_VERTICES); 655 656 IssmDouble smb[MAXVERTICES]; 657 IssmDouble surf[MAXVERTICES]; 658 IssmDouble accu[MAXVERTICES]; 659 IssmDouble runoff[MAXVERTICES]; 664 660 665 661 /*Get material parameters :*/ 666 rho_water=this->FindParam(MaterialsRhoSeawaterEnum);667 rho_ice=this->FindParam(MaterialsRhoIceEnum);662 IssmDouble rho_water = this->FindParam(MaterialsRhoSeawaterEnum); 663 IssmDouble rho_ice = this->FindParam(MaterialsRhoIceEnum); 668 664 669 665 /*Recover parameters*/ 670 parameters->FindParam(&time,TimeEnum);671 parameters->FindParam(&accualti,SmbAccualtiEnum);672 parameters->FindParam(&runoffalti,SmbRunoffaltiEnum);666 IssmDouble time = this->FindParam(TimeEnum); 667 IssmDouble accualti = this->FindParam(SmbAccualtiEnum); 668 IssmDouble runoffalti = this->FindParam(SmbRunoffaltiEnum); 673 669 674 670 /*Recover reference values at current time*/ … … 683 679 /*Compute the temperature and precipitation*/ 684 680 for(int iv=0;iv<NUM_VERTICES;iv++){ 685 accu[iv] =max(0.,(accuref+(surf[iv]-accualti)*accugrad));686 runoff[iv] =max(0.,(runoffref+(surf[iv]-runoffalti)*runoffgrad));687 smb[iv] =(accu[iv]-runoff[iv])*rho_ice/rho_water;681 accu[iv] = max(0.,(accuref+(surf[iv]-accualti)*accugrad)); 682 runoff[iv] = max(0.,(runoffref+(surf[iv]-runoffalti)*runoffgrad)); 683 smb[iv] = (accu[iv]-runoff[iv])*rho_ice/rho_water; 688 684 } 689 685 … … 701 697 default: _error_("Not implemented yet"); 702 698 } 703 /*clean-up*/704 xDelete<IssmDouble>(surf);705 xDelete<IssmDouble>(accu);706 xDelete<IssmDouble>(runoff);707 xDelete<IssmDouble>(smb);708 699 } 709 700 /*}}}*/ … … 1293 1284 } 1294 1285 /*}}}*/ 1295 /* void Element::GetVectorFromInputs(Vector<IssmDouble>* vector,int input_enum){/\*{{{*\/ */1296 1297 /* /\*Fetch number vertices for this element and allocate arrays*\/ */1298 /* const int NUM_VERTICES = this->GetNumberOfVertices(); */1299 /* int* vertexpidlist = xNew<int>(NUM_VERTICES); */1300 /* IssmDouble* values = xNew<IssmDouble>(NUM_VERTICES); */1301 1302 /* /\*Fill in values*\/ */1303 /* this->GetVerticesPidList(vertexpidlist); */1304 /* this->GetInputListOnVertices(values,input_enum); */1305 /* vector->SetValues(NUM_VERTICES,vertexpidlist,values,INS_VAL); */1306 1307 /* /\*Clean up*\/ */1308 /* xDelete<int>(vertexpidlist); */1309 /* xDelete<IssmDouble>(values); */1310 1311 /* } */1312 /* /\*}}}*\/ */1313 1286 void Element::GetVectorFromInputs(Vector<IssmDouble>* vector,int input_enum,int type){/*{{{*/ 1314 1287 1315 /*Fetch number vertices for this element and allocate arrays*/1316 const int NUM_VERTICES = this->GetNumberOfVertices();1317 1318 int numnodes = this->GetNumberOfNodes();1319 int* doflist = NULL;1320 IssmDouble value;1321 IssmDouble* values = NULL;1322 Input* input = NULL;1323 1288 1324 1289 switch(type){ 1325 case ElementSIdEnum: 1326 input=this->GetInput(input_enum); _assert_(input); 1290 case ElementSIdEnum:{ 1291 IssmDouble value; 1292 Input* input=this->GetInput(input_enum); _assert_(input); 1327 1293 input->GetInputAverage(&value); 1328 1294 vector->SetValue(this->sid,value,INS_VAL); 1295 } 1329 1296 break; 1330 case VertexPIdEnum: 1331 doflist = xNew<int>(NUM_VERTICES); 1332 values = xNew<IssmDouble>(NUM_VERTICES); 1297 case VertexPIdEnum:{ 1298 int doflist[MAXVERTICES]; 1299 IssmDouble values[MAXVERTICES]; 1300 const int NUM_VERTICES = this->GetNumberOfVertices(); 1333 1301 /*Fill in values*/ 1334 this->GetVerticesPidList( doflist);1335 this->GetInputListOnVertices( values,input_enum);1302 this->GetVerticesPidList(&doflist[0]); 1303 this->GetInputListOnVertices(&values[0],input_enum); 1336 1304 vector->SetValues(NUM_VERTICES,doflist,values,INS_VAL); 1305 } 1337 1306 break; 1338 case VertexSIdEnum: 1339 doflist = xNew<int>(NUM_VERTICES); 1340 values = xNew<IssmDouble>(NUM_VERTICES); 1307 case VertexSIdEnum:{ 1308 int doflist[MAXVERTICES]; 1309 IssmDouble values[MAXVERTICES]; 1310 const int NUM_VERTICES = this->GetNumberOfVertices(); 1341 1311 /*Fill in values*/ 1342 1312 this->GetVerticesSidList(doflist); 1343 1313 this->GetInputListOnVertices(values,input_enum); 1344 1314 vector->SetValues(NUM_VERTICES,doflist,values,INS_VAL); 1315 } 1345 1316 break; 1346 case NodesEnum: 1347 doflist = xNew<int>(numnodes); 1348 values = xNew<IssmDouble>(numnodes); 1317 case NodesEnum:{ 1318 int numnodes = this->GetNumberOfNodes(); 1319 int *doflist = xNew<int>(numnodes); 1320 IssmDouble *values = xNew<IssmDouble>(numnodes); 1349 1321 /*Fill in values*/ 1350 1322 this->GetInputListOnNodes(values,input_enum); 1351 1323 this->GetDofList(&doflist,NoneApproximationEnum,GsetEnum); 1352 1324 vector->SetValues(numnodes,doflist,values,INS_VAL); 1325 xDelete<int>(doflist); 1326 xDelete<IssmDouble>(values); 1327 } 1353 1328 break; 1354 case NodeSIdEnum: 1355 doflist = xNew<int>(numnodes); 1356 values = xNew<IssmDouble>(numnodes); 1329 case NodeSIdEnum:{ 1330 int numnodes = this->GetNumberOfNodes(); 1331 int *doflist = xNew<int>(numnodes); 1332 IssmDouble *values = xNew<IssmDouble>(numnodes); 1357 1333 /*Fill in values*/ 1358 1334 this->GetNodesSidList(doflist); 1359 1335 this->GetInputListOnNodes(values,input_enum); 1360 1336 vector->SetValues(numnodes,doflist,values,INS_VAL); 1337 xDelete<int>(doflist); 1338 xDelete<IssmDouble>(values); 1339 } 1361 1340 break; 1362 1341 default: … … 1364 1343 } 1365 1344 1366 /*Clean up*/ 1367 xDelete<int>(doflist); 1368 xDelete<IssmDouble>(values); 1369 1370 } 1371 /*}}}*/ 1345 }/*}}}*/ 1372 1346 void Element::GetVectorFromInputs(Vector<IssmDouble>* vector,int input_enum,int type, IssmDouble time){/*{{{*/ 1373 1347 1374 /*Fetch number vertices for this element and allocate arrays*/1375 const int NUM_VERTICES = this->GetNumberOfVertices();1376 1377 int numnodes = this->GetNumberOfNodes();1378 int* doflist = NULL;1379 IssmDouble* values = NULL;1380 1381 1348 switch(type){ 1382 case VertexPIdEnum: 1383 doflist = xNew<int>(NUM_VERTICES); 1384 values = xNew<IssmDouble>(NUM_VERTICES); 1349 case VertexPIdEnum:{ 1350 int doflist[MAXVERTICES]; 1351 IssmDouble values[MAXVERTICES]; 1352 const int NUM_VERTICES = this->GetNumberOfVertices(); 1385 1353 /*Fill in values*/ 1386 1354 this->GetVerticesPidList(doflist); 1387 1355 this->GetInputListOnVerticesAtTime(values,input_enum,time); 1388 vector->SetValues(NUM_VERTICES,doflist,values,INS_VAL); 1356 vector->SetValues(NUM_VERTICES,doflist,&values[0],INS_VAL); 1357 } 1389 1358 break; 1390 case VertexSIdEnum: 1391 doflist = xNew<int>(NUM_VERTICES); 1392 values = xNew<IssmDouble>(NUM_VERTICES); 1359 case VertexSIdEnum:{ 1360 int doflist[MAXVERTICES]; 1361 IssmDouble values[MAXVERTICES]; 1362 const int NUM_VERTICES = this->GetNumberOfVertices(); 1393 1363 /*Fill in values*/ 1394 1364 this->GetVerticesSidList(doflist); 1395 1365 this->GetInputListOnVerticesAtTime(values,input_enum,time); 1396 vector->SetValues(NUM_VERTICES,doflist,values,INS_VAL); 1366 vector->SetValues(NUM_VERTICES,doflist,&values[0],INS_VAL); 1367 } 1397 1368 break; 1398 1369 default: 1399 1370 _error_("type " << type << " (" << EnumToStringx(type) << ") not implemented yet"); 1400 1371 } 1401 1402 /*Clean up*/1403 xDelete<int>(doflist);1404 xDelete<IssmDouble>(values);1405 1406 1372 } 1407 1373 /*}}}*/ … … 1449 1415 /*Create list of x*/ 1450 1416 const int NUM_VERTICES = this->GetNumberOfVertices(); 1451 1452 IssmDouble* x_list = xNew<IssmDouble>(NUM_VERTICES); 1453 1417 IssmDouble x_list[MAXVERTICES]; 1454 1418 for(int i=0;i<NUM_VERTICES;i++) x_list[i]=xyz_list[i*3+0]; 1455 ValueP1OnGauss(&x,x_list,gauss); 1456 1457 xDelete<IssmDouble>(x_list);1419 1420 /*Get value at gauss point*/ 1421 ValueP1OnGauss(&x,&x_list[0],gauss); 1458 1422 return x; 1459 1423 }/*}}}*/ … … 1465 1429 /*Create list of y*/ 1466 1430 const int NUM_VERTICES = this->GetNumberOfVertices(); 1467 1468 IssmDouble* y_list = xNew<IssmDouble>(NUM_VERTICES); 1469 1431 IssmDouble y_list[MAXVERTICES]; 1470 1432 for(int i=0;i<NUM_VERTICES;i++) y_list[i]=xyz_list[i*3+1]; 1471 ValueP1OnGauss(&y,y_list,gauss); 1472 1473 xDelete<IssmDouble>(y_list);1433 1434 /*Get value at gauss point*/ 1435 ValueP1OnGauss(&y,&y_list[0],gauss); 1474 1436 return y; 1475 1437 }/*}}}*/ … … 1481 1443 /*Create list of z*/ 1482 1444 const int NUM_VERTICES = this->GetNumberOfVertices(); 1483 1484 IssmDouble* z_list = xNew<IssmDouble>(NUM_VERTICES); 1485 1445 IssmDouble z_list[MAXVERTICES]; 1486 1446 for(int i=0;i<NUM_VERTICES;i++) z_list[i]=xyz_list[i*3+2]; 1487 ValueP1OnGauss(&z,z_list,gauss); 1488 1489 xDelete<IssmDouble>(z_list);1447 1448 /*Get value at gauss point*/ 1449 ValueP1OnGauss(&z,&z_list[0],gauss); 1490 1450 return z; 1491 1451 }/*}}}*/ … … 1612 1572 void Element::InputCreate(IssmDouble* vector,Inputs* inputs,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){/*{{{*/ 1613 1573 1614 /*Intermediaries*/1615 int i,t;1616 1617 1574 /*Branch on type of vector: nodal or elementary: */ 1618 1575 if(vector_type==1){ //nodal vector … … 1620 1577 const int NUM_VERTICES = this->GetNumberOfVertices(); 1621 1578 1622 int *vertexids = xNew<int>(NUM_VERTICES);1623 int *vertexlids = xNew<int>(NUM_VERTICES);1624 IssmDouble *values = xNew<IssmDouble>(NUM_VERTICES);1579 int vertexids[MAXVERTICES]; 1580 int vertexlids[MAXVERTICES]; 1581 IssmDouble values[MAXVERTICES]; 1625 1582 1626 1583 /*Recover vertices ids needed to initialize inputs*/ 1627 1584 _assert_(iomodel->elements); 1628 for(i =0;i<NUM_VERTICES;i++){1585 for(int i=0;i<NUM_VERTICES;i++){ 1629 1586 vertexids[i] =reCast<int>(iomodel->elements[NUM_VERTICES*this->Sid()+i]); //ids for vertices are in the elements array from Matlab 1630 1587 vertexlids[i]=iomodel->my_vertices_lids[vertexids[i]-1]; … … 1637 1594 } 1638 1595 else if(M==iomodel->numberofvertices){ 1639 for(i =0;i<NUM_VERTICES;i++) values[i]=vector[vertexids[i]-1];1596 for(int i=0;i<NUM_VERTICES;i++) values[i]=vector[vertexids[i]-1]; 1640 1597 this->SetElementInput(inputs,NUM_VERTICES,vertexlids,values,vector_enum); 1641 1598 } … … 1643 1600 /*create transient input: */ 1644 1601 IssmDouble* times = xNew<IssmDouble>(N); 1645 for( t=0;t<N;t++) times[t] = vector[(M-1)*N+t];1602 for(int t=0;t<N;t++) times[t] = vector[(M-1)*N+t]; 1646 1603 inputs->SetTransientInput(vector_enum,times,N); 1647 1604 TransientInput* transientinput = inputs->GetTransientInput(vector_enum); 1648 for( t=0;t<N;t++){1649 for(i =0;i<NUM_VERTICES;i++) values[i]=vector[N*(vertexids[i]-1)+t];1605 for(int t=0;t<N;t++){ 1606 for(int i=0;i<NUM_VERTICES;i++) values[i]=vector[N*(vertexids[i]-1)+t]; 1650 1607 switch(this->ObjectEnum()){ 1651 case TriaEnum: transientinput->AddTriaTimeInput( t,NUM_VERTICES,vertexlids, values,P1Enum); break;1652 case PentaEnum: transientinput->AddPentaTimeInput(t,NUM_VERTICES,vertexlids, values,P1Enum); break;1608 case TriaEnum: transientinput->AddTriaTimeInput( t,NUM_VERTICES,vertexlids,&values[0],P1Enum); break; 1609 case PentaEnum: transientinput->AddPentaTimeInput(t,NUM_VERTICES,vertexlids,&values[0],P1Enum); break; 1653 1610 default: _error_("Not implemented yet"); 1654 1611 } … … 1659 1616 1660 1617 /*This is a Patch!*/ 1661 xDelete<IssmDouble>(values); 1662 values = xNew<IssmDouble>(N); 1663 for(int j=0;j<N;j++) values[j]=vector[this->Sid()*N+j]; 1618 IssmDouble* evalues = xNew<IssmDouble>(N); 1619 for(int j=0;j<N;j++) evalues[j]=vector[this->Sid()*N+j]; 1664 1620 1665 1621 if (N==this->GetNumberOfNodes(P1Enum)){ 1666 this->SetElementInput(inputs,NUM_VERTICES,vertexlids, values,vector_enum);1622 this->SetElementInput(inputs,NUM_VERTICES,vertexlids,evalues,vector_enum); 1667 1623 } 1668 1624 else if(N==this->GetNumberOfNodes(P0Enum)){ 1669 this->SetElementInput(inputs,vector_enum, values[0]);1625 this->SetElementInput(inputs,vector_enum,evalues[0]); 1670 1626 } 1671 1627 else if(N==this->GetNumberOfNodes(P1xP2Enum)){ _assert_(this->ObjectEnum()==PentaEnum); 1672 inputs->SetPentaInput(vector_enum,P1xP2Enum,this->lid,N, values);1628 inputs->SetPentaInput(vector_enum,P1xP2Enum,this->lid,N,evalues); 1673 1629 } 1674 1630 else if(N==this->GetNumberOfNodes(P1xP3Enum)){ _assert_(this->ObjectEnum()==PentaEnum); 1675 inputs->SetPentaInput(vector_enum,P1xP3Enum,this->lid,N, values);1631 inputs->SetPentaInput(vector_enum,P1xP3Enum,this->lid,N,evalues); 1676 1632 } 1677 1633 else{ 1678 1634 _error_("Patch interpolation not supported yet"); 1679 1635 } 1636 xDelete<IssmDouble>(evalues); 1680 1637 1681 1638 } … … 1683 1640 _error_("nodal vector is either numberofvertices or numberofvertices+1 long. Field provided (" << EnumToStringx(vector_enum) << ") is " << M << " long"); 1684 1641 } 1685 1686 xDelete<IssmDouble>(values);1687 xDelete<int>(vertexids);1688 xDelete<int>(vertexlids);1689 1642 } 1690 1643 else if(vector_type==2){ //element vector … … 1708 1661 /*create transient input: */ 1709 1662 IssmDouble* times = xNew<IssmDouble>(N); 1710 for( t=0;t<N;t++) times[t] = vector[(M-1)*N+t];1663 for(int t=0;t<N;t++) times[t] = vector[(M-1)*N+t]; 1711 1664 inputs->SetTransientInput(vector_enum,times,N); 1712 1665 TransientInput* transientinput = inputs->GetTransientInput(vector_enum); 1713 for( t=0;t<N;t++){1666 for(int t=0;t<N;t++){ 1714 1667 value=vector[N*this->Sid()+t]; 1715 1668 switch(this->ObjectEnum()){ … … 1728 1681 if(M==iomodel->numberofelements){ 1729 1682 IssmDouble* layers = xNewZeroInit<IssmDouble>(N); 1730 for( t=0;t<N;t++) layers[t] = vector[N*this->Sid()+t];1683 for(int t=0;t<N;t++) layers[t] = vector[N*this->Sid()+t]; 1731 1684 inputs->SetArrayInput(vector_enum,this->lid,layers,N); 1732 1685 xDelete<IssmDouble>(layers); … … 1850 1803 */ 1851 1804 1852 /*Intermediaries*/1853 int i,t;1854 1855 1805 /*Branch on type of vector: nodal or elementary: */ 1856 1806 if(vector_type==1){ //nodal vector … … 1858 1808 const int NUM_VERTICES = this->GetNumberOfVertices(); 1859 1809 1860 int *vertexids = xNew<int>(NUM_VERTICES);1861 int *vertexlids = xNew<int>(NUM_VERTICES);1862 IssmDouble *values = xNew<IssmDouble>(NUM_VERTICES);1810 int vertexids[MAXVERTICES]; 1811 int vertexlids[MAXVERTICES]; 1812 IssmDouble values[MAXVERTICES]; 1863 1813 1864 1814 /*Recover vertices ids needed to initialize inputs*/ 1865 1815 _assert_(iomodel->elements); 1866 for(i =0;i<NUM_VERTICES;i++){1816 for(int i=0;i<NUM_VERTICES;i++){ 1867 1817 vertexids[i] =reCast<int>(iomodel->elements[NUM_VERTICES*this->Sid()+i]); //ids for vertices are in the elements array from Matlab 1868 1818 vertexlids[i]=iomodel->my_vertices_lids[vertexids[i]-1]; … … 1876 1826 } 1877 1827 else if(M==iomodel->numberofvertices){ 1878 for(i =0;i<NUM_VERTICES;i++) values[i]=vector[vertexids[i]-1];1828 for(int i=0;i<NUM_VERTICES;i++) values[i]=vector[vertexids[i]-1]; 1879 1829 switch(this->ObjectEnum()){ 1880 1830 case TriaEnum: inputs->SetTriaDatasetInput(enum_type,input_id,P1Enum,NUM_VERTICES,vertexlids,values); break; … … 1886 1836 /*create transient input: */ 1887 1837 IssmDouble* times = xNew<IssmDouble>(N); 1888 for( t=0;t<N;t++) times[t] = vector[(M-1)*N+t];1838 for(int t=0;t<N;t++) times[t] = vector[(M-1)*N+t]; 1889 1839 TransientInput* transientinput = inputs->SetDatasetTransientInput(enum_type,input_id,times,N); 1890 for( t=0;t<N;t++){1891 for(i =0;i<NUM_VERTICES;i++) values[i]=vector[N*(vertexids[i]-1)+t];1840 for(int t=0;t<N;t++){ 1841 for(int i=0;i<NUM_VERTICES;i++) values[i]=vector[N*(vertexids[i]-1)+t]; 1892 1842 switch(this->ObjectEnum()){ 1893 1843 case TriaEnum: transientinput->AddTriaTimeInput( t,NUM_VERTICES,vertexlids,values,P1Enum); break; … … 1901 1851 _error_("not implemented yet (M="<<M<<")"); 1902 1852 } 1903 1904 xDelete<IssmDouble>(values);1905 xDelete<int>(vertexids);1906 xDelete<int>(vertexlids);1907 1853 } 1908 1854 else if(vector_type==2){ //element vector … … 2065 2011 /*Allocate some arrays*/ 2066 2012 const int numvertices = this->GetNumberOfVertices(); 2067 IssmDouble * basalmeltrate = xNew<IssmDouble>(numvertices);2013 IssmDouble basalmeltrate[MAXVERTICES]; 2068 2014 2069 2015 /*Get variables*/ … … 2114 2060 xDelete<IssmDouble>(mean_tf); 2115 2061 xDelete<IssmDouble>(depths); 2116 xDelete<IssmDouble>(basalmeltrate);2117 2062 2118 2063 }/*}}}*/ … … 2121 2066 const int NUM_VERTICES = this->GetNumberOfVertices(); 2122 2067 2123 IssmDouble 2124 IssmDouble *base = xNew<IssmDouble>(NUM_VERTICES);2125 IssmDouble *values = xNew<IssmDouble>(NUM_VERTICES);2126 IssmDouble *perturbation = xNew<IssmDouble>(NUM_VERTICES);2127 IssmDouble 2068 IssmDouble deepwaterel,upperwaterel,deepwatermelt,upperwatermelt; 2069 IssmDouble base[MAXVERTICES]; 2070 IssmDouble values[MAXVERTICES]; 2071 IssmDouble perturbation[MAXVERTICES]; 2072 IssmDouble time; 2128 2073 2129 2074 parameters->FindParam(&time,TimeEnum); … … 2134 2079 _assert_(upperwaterel>deepwaterel); 2135 2080 2136 this->GetInputListOnVertices( base,BaseEnum);2137 this->GetInputListOnVertices( perturbation,BasalforcingsPerturbationMeltingRateEnum);2081 this->GetInputListOnVertices(&base[0],BaseEnum); 2082 this->GetInputListOnVertices(&perturbation[0],BasalforcingsPerturbationMeltingRateEnum); 2138 2083 for(int i=0;i<NUM_VERTICES;i++){ 2139 2084 if(base[i]>=upperwaterel){ … … 2152 2097 2153 2098 this->AddInput(BasalforcingsFloatingiceMeltingRateEnum,values,P1Enum); 2154 xDelete<IssmDouble>(base);2155 xDelete<IssmDouble>(perturbation);2156 xDelete<IssmDouble>(values);2157 2099 2158 2100 }/*}}}*/ … … 2161 2103 const int NUM_VERTICES = this->GetNumberOfVertices(); 2162 2104 2163 IssmDouble *deepwatermelt = xNew<IssmDouble>(NUM_VERTICES);2164 IssmDouble *deepwaterel = xNew<IssmDouble>(NUM_VERTICES);2165 IssmDouble *upperwaterel = xNew<IssmDouble>(NUM_VERTICES);2166 IssmDouble *base = xNew<IssmDouble>(NUM_VERTICES);2167 IssmDouble *values = xNew<IssmDouble>(NUM_VERTICES);2168 2169 this->GetInputListOnVertices( base,BaseEnum);2170 this->GetInputListOnVertices( deepwatermelt,BasalforcingsDeepwaterMeltingRateEnum);2171 this->GetInputListOnVertices( deepwaterel,BasalforcingsDeepwaterElevationEnum);2172 this->GetInputListOnVertices( upperwaterel,BasalforcingsUpperwaterElevationEnum);2105 IssmDouble deepwatermelt[MAXVERTICES]; 2106 IssmDouble deepwaterel[MAXVERTICES];; 2107 IssmDouble upperwaterel[MAXVERTICES]; 2108 IssmDouble base[MAXVERTICES]; 2109 IssmDouble values[MAXVERTICES]; 2110 2111 this->GetInputListOnVertices(&base[0],BaseEnum); 2112 this->GetInputListOnVertices(&deepwatermelt[0],BasalforcingsDeepwaterMeltingRateEnum); 2113 this->GetInputListOnVertices(&deepwaterel[0],BasalforcingsDeepwaterElevationEnum); 2114 this->GetInputListOnVertices(&upperwaterel[0],BasalforcingsUpperwaterElevationEnum); 2173 2115 2174 2116 for(int i=0;i<NUM_VERTICES;i++){ … … 2178 2120 } 2179 2121 2180 this->AddInput(BasalforcingsFloatingiceMeltingRateEnum,values,P1Enum); 2181 xDelete<IssmDouble>(base); 2182 xDelete<IssmDouble>(deepwaterel); 2183 xDelete<IssmDouble>(deepwatermelt); 2184 xDelete<IssmDouble>(upperwaterel); 2185 xDelete<IssmDouble>(values); 2186 2122 this->AddInput(BasalforcingsFloatingiceMeltingRateEnum,&values[0],P1Enum); 2187 2123 }/*}}}*/ 2188 2124 void Element::MantlePlumeGeothermalFlux(){/*{{{*/ … … 2193 2129 IssmDouble crustheat,plumeheat,dt,middleplumedepth,a,e,eprime,A0,lambda,Alambda,dAlambda; 2194 2130 IssmDouble x,y,z,c; 2195 IssmDouble * values = xNew<IssmDouble>(NUM_VERTICES);2131 IssmDouble values[MAXVERTICES]; 2196 2132 IssmDouble *xyz_list = NULL; 2197 2133 … … 2228 2164 } 2229 2165 2230 this->AddInput(BasalforcingsGeothermalfluxEnum, values,P1Enum);2166 this->AddInput(BasalforcingsGeothermalfluxEnum,&values[0],P1Enum); 2231 2167 xDelete<IssmDouble>(xyz_list); 2232 xDelete<IssmDouble>(values);2233 2168 2234 2169 }/*}}}*/ … … 2253 2188 2254 2189 const int NUM_VERTICES = this->GetNumberOfVertices(); 2255 int i,migration_style;2190 int migration_style; 2256 2191 IssmDouble bed_hydro,yts; 2257 IssmDouble rho_water,rho_ice,density; 2258 IssmDouble* melting = xNew<IssmDouble>(NUM_VERTICES); 2259 IssmDouble* phi = xNew<IssmDouble>(NUM_VERTICES); 2260 IssmDouble* h = xNew<IssmDouble>(NUM_VERTICES); 2261 IssmDouble* s = xNew<IssmDouble>(NUM_VERTICES); 2262 IssmDouble* b = xNew<IssmDouble>(NUM_VERTICES); 2263 IssmDouble* r = xNew<IssmDouble>(NUM_VERTICES); 2264 IssmDouble* sl = xNew<IssmDouble>(NUM_VERTICES); 2192 IssmDouble melting[MAXVERTICES]; 2193 IssmDouble phi[MAXVERTICES]; 2194 IssmDouble h[MAXVERTICES]; 2195 IssmDouble s[MAXVERTICES]; 2196 IssmDouble b[MAXVERTICES]; 2197 IssmDouble r[MAXVERTICES]; 2198 IssmDouble sl[MAXVERTICES]; 2265 2199 2266 2200 /*Recover info at the vertices: */ … … 2273 2207 GetInputListOnVertices(&sl[0],SealevelEnum); 2274 2208 GetInputListOnVertices(&phi[0],MaskOceanLevelsetEnum); 2275 rho_water = FindParam(MaterialsRhoSeawaterEnum);2276 rho_ice = FindParam(MaterialsRhoIceEnum);2277 density = rho_ice/rho_water;2209 IssmDouble rho_water = FindParam(MaterialsRhoSeawaterEnum); 2210 IssmDouble rho_ice = FindParam(MaterialsRhoIceEnum); 2211 IssmDouble density = rho_ice/rho_water; 2278 2212 2279 2213 /*go through vertices, and update inputs, considering them to be TriaVertex type: */ 2280 for(i =0;i<NUM_VERTICES;i++){2214 for(int i=0;i<NUM_VERTICES;i++){ 2281 2215 /* Contact FS*/ 2282 2216 if(migration_style == ContactEnum){ … … 2284 2218 if(phi[i]>=0.) b[i]=r[i]; 2285 2219 } 2286 else if(migration_style == GroundingOnlyEnum && b[i]<r[i]) b[i]=r[i]; 2287 /*Ice shelf: if bed below bathymetry, impose it at the bathymetry and update surface, elso do nothing */ 2220 else if(migration_style == GroundingOnlyEnum && b[i]<r[i]){ 2221 /*Ice shelf: if bed below bathymetry, impose it at the bathymetry and update surface, elso do nothing */ 2222 b[i]=r[i]; 2223 } 2288 2224 else if(phi[i]<=0.){ 2289 2225 if(b[i]<=r[i]){ … … 2299 2235 /*Unground only if the element is connected to the ice shelf*/ 2300 2236 if(migration_style==AggressiveMigrationEnum || migration_style==SubelementMigrationEnum){ 2301 s[i] = (1-density)*h[i]+sl[i];2302 b[i] 2237 s[i] = (1.-density)*h[i]+sl[i]; 2238 b[i] = -density*h[i]+sl[i]; 2303 2239 } 2304 2240 else if(migration_style==SoftMigrationEnum && phi_ungrounding[vertices[i]->Pid()]<0.){ 2305 s[i] = (1-density)*h[i]+sl[i];2306 b[i] 2241 s[i] = (1.-density)*h[i]+sl[i]; 2242 b[i] = -density*h[i]+sl[i]; 2307 2243 } 2308 2244 else{ … … 2314 2250 2315 2251 /*Recalculate phi*/ 2316 for(i =0;i<NUM_VERTICES;i++){2252 for(int i=0;i<NUM_VERTICES;i++){ 2317 2253 if(migration_style==SoftMigrationEnum){ 2318 2254 bed_hydro=-density*h[i]+sl[i]; … … 2321 2257 } 2322 2258 } 2323 else if(migration_style!=ContactEnum) phi[i]=h[i]+(r[i]-sl[i])/density; 2259 else if(migration_style!=ContactEnum){ 2260 phi[i]=h[i]+(r[i]-sl[i])/density; 2261 } 2324 2262 else{ 2325 2263 /*do nothing*/ … … 2332 2270 this->AddInput(BaseEnum,&b[0],P1Enum); 2333 2271 2334 /*Delete*/ 2335 xDelete<IssmDouble>(melting); 2336 xDelete<IssmDouble>(phi); 2337 xDelete<IssmDouble>(r); 2338 xDelete<IssmDouble>(b); 2339 xDelete<IssmDouble>(s); 2340 xDelete<IssmDouble>(sl); 2341 xDelete<IssmDouble>(h); 2342 2343 } 2344 /*}}}*/ 2272 }/*}}}*/ 2345 2273 void Element::MismipFloatingiceMeltingRate(){/*{{{*/ 2346 2274 … … 2566 2494 2567 2495 const int NUM_VERTICES = this->GetNumberOfVertices(); 2568 2569 2496 int basinid, maxbox, num_basins, numnodes, M; 2570 2497 IssmDouble gamma_T, overturning_coeff, thickness; … … 2593 2520 this->GetInputValue(&basinid,BasalforcingsPicoBasinIdEnum); 2594 2521 this->parameters->FindParam(&isplume, BasalforcingsPicoIsplumeEnum); 2595 Input *thickness_input = this->GetInput(ThicknessEnum); _assert_(thickness_input); 2596 _assert_(basinid<=num_basins); 2522 Input *thickness_input = this->GetInput(ThicknessEnum); 2523 _assert_(basinid<=num_basins); 2524 _assert_(thickness_input); 2597 2525 2598 2526 IssmDouble* boxareas = NULL; … … 2603 2531 IssmDouble g1 = area_boxi*gamma_T; 2604 2532 2605 IssmDouble * basalmeltrates_shelf = xNew<IssmDouble>(NUM_VERTICES);2606 IssmDouble * potential_pressure_melting_point = xNew<IssmDouble>(NUM_VERTICES);2607 IssmDouble * Tocs = xNew<IssmDouble>(NUM_VERTICES);2608 IssmDouble * Socs = xNew<IssmDouble>(NUM_VERTICES);2533 IssmDouble basalmeltrates_shelf[MAXVERTICES]; 2534 IssmDouble potential_pressure_melting_point[MAXVERTICES]; 2535 IssmDouble Tocs[MAXVERTICES]; 2536 IssmDouble Socs[MAXVERTICES]; 2609 2537 2610 2538 /* First box calculations */ … … 2612 2540 /* Get box1 parameters and inputs */ 2613 2541 IssmDouble time, toc_farocean, soc_farocean; 2542 IssmDouble overturnings[MAXVERTICES]; 2614 2543 this->parameters->FindParam(&time,TimeEnum); 2615 2544 this->parameters->FindParam(&toc_farocean, basinid, time, BasalforcingsPicoFarOceantemperatureEnum); 2616 2545 this->parameters->FindParam(&soc_farocean, basinid, time, BasalforcingsPicoFarOceansalinityEnum); 2617 IssmDouble s1 = soc_farocean/(nu*lambda); 2618 IssmDouble* overturnings = xNew<IssmDouble>(NUM_VERTICES); 2546 IssmDouble s1 = soc_farocean/(nu*lambda); 2619 2547 Input *overturningC_input = this->GetInput(BasalforcingsPicoOverturningCoeffEnum); _assert_(overturningC_input); 2620 2548 … … 2640 2568 } 2641 2569 2642 if(!isplume) this->AddInput(BasalforcingsFloatingiceMeltingRateEnum, basalmeltrates_shelf,P1DGEnum);2643 this->AddInput(BasalforcingsPicoSubShelfOceanTempEnum, Tocs,P1DGEnum);2644 this->AddInput(BasalforcingsPicoSubShelfOceanSalinityEnum, Socs,P1DGEnum);2645 this->AddInput(BasalforcingsPicoSubShelfOceanOverturningEnum, overturnings,P1DGEnum);2570 if(!isplume) this->AddInput(BasalforcingsFloatingiceMeltingRateEnum,&basalmeltrates_shelf[0],P1DGEnum); 2571 this->AddInput(BasalforcingsPicoSubShelfOceanTempEnum,&Tocs[0],P1DGEnum); 2572 this->AddInput(BasalforcingsPicoSubShelfOceanSalinityEnum,&Socs[0],P1DGEnum); 2573 this->AddInput(BasalforcingsPicoSubShelfOceanOverturningEnum,&overturnings[0],P1DGEnum); 2646 2574 2647 2575 /*Cleanup and return*/ … … 2716 2644 2717 2645 /*Define arrays*/ 2718 IssmDouble * basalmeltrates_shelf = xNew<IssmDouble>(NUM_VERTICES); //Basal melt-rate2646 IssmDouble basalmeltrates_shelf[MAXVERTICES]; 2719 2647 2720 2648 /*Polynomial coefficients*/ … … 2789 2717 2790 2718 /*Save computed melt-rate*/ 2791 this->AddInput(BasalforcingsFloatingiceMeltingRateEnum, basalmeltrates_shelf,P1DGEnum);2719 this->AddInput(BasalforcingsFloatingiceMeltingRateEnum,&basalmeltrates_shelf[0],P1DGEnum); 2792 2720 2793 2721 /*Cleanup and return*/ 2794 2722 delete gauss; 2795 2796 2723 }/*}}}*/ 2797 2724 void Element::PositiveDegreeDay(IssmDouble* pdds,IssmDouble* pds,IssmDouble signorm,bool ismungsm,bool issetpddfac){/*{{{*/ … … 4232 4159 /*Fetch number vertices and allocate memory*/ 4233 4160 const int NUM_VERTICES = this->GetNumberOfVertices(); 4234 4235 IssmDouble* maxprincipal = xNew<IssmDouble>(NUM_VERTICES); 4161 IssmDouble maxprincipal[MAXVERTICES]; 4236 4162 4237 4163 /*Retrieve all inputs and parameters*/ … … 4251 4177 /*loop over vertices: */ 4252 4178 Gauss* gauss=this->NewGauss(); 4253 for 4179 for(int iv=0;iv<NUM_VERTICES;iv++){ 4254 4180 gauss->GaussVertex(iv); 4255 4181 … … 4296 4222 4297 4223 /*Create input*/ 4298 this->AddInput(StressMaxPrincipalEnum, maxprincipal,P1Enum);4224 this->AddInput(StressMaxPrincipalEnum,&maxprincipal[0],P1Enum); 4299 4225 4300 4226 /*Clean up and return*/ 4301 xDelete<IssmDouble>(maxprincipal);4302 4227 xDelete<IssmDouble>(xyz_list); 4303 4228 delete gauss; … … 4575 4500 /*Fetch number vertices and allocate memory*/ 4576 4501 const int NUM_VERTICES = this->GetNumberOfVertices(); 4577 4578 IssmDouble* viscousheating = xNew<IssmDouble>(NUM_VERTICES); 4502 IssmDouble viscousheating[MAXVERTICES]; 4579 4503 4580 4504 /*Retrieve all inputs and parameters*/ … … 4595 4519 4596 4520 /*Create PentaVertex input, which will hold the basal friction:*/ 4597 this->AddInput(ViscousHeatingEnum, viscousheating,P1Enum);4521 this->AddInput(ViscousHeatingEnum,&viscousheating[0],P1Enum); 4598 4522 4599 4523 /*Clean up and return*/ 4600 xDelete<IssmDouble>(viscousheating);4601 4524 xDelete<IssmDouble>(xyz_list); 4602 4525 delete gauss; … … 4683 4606 IssmDouble kappa,kappa_c,kappa_t; //enthalpy conductivities 4684 4607 IssmDouble Hc,Ht; 4685 IssmDouble * PIE = xNew<IssmDouble>(numvertices);4686 IssmDouble * dHpmp = xNew<IssmDouble>(numvertices);4608 IssmDouble PIE[MAXVERTICES]; 4609 IssmDouble dHpmp[MAXVERTICES]; 4687 4610 4688 4611 for(int iv=0; iv<numvertices; iv++){ … … 4720 4643 4721 4644 /*Clean up and return*/ 4722 xDelete<IssmDouble>(PIE);4723 xDelete<IssmDouble>(dHpmp);4724 4645 return kappa; 4725 4646 } -
issm/trunk-jpl/src/c/classes/Elements/Tria.cpp
r25839 r25905 2222 2222 2223 2223 /*Intermediaries*/ 2224 int i,numiceverts, numnoiceverts;2224 int numiceverts, numnoiceverts; 2225 2225 int ind0, ind1, lastindex; 2226 2226 int indices_ice[NUMVERTICES],indices_noice[NUMVERTICES]; … … 2234 2234 * Exploit: ice/no-ice parts are connected, so find starting vertex of segment*/ 2235 2235 lastindex=0; 2236 for(i =0;i<NUMVERTICES;i++){ // go backwards along vertices, and check for sign change2236 for(int i=0;i<NUMVERTICES;i++){ // go backwards along vertices, and check for sign change 2237 2237 ind0=(NUMVERTICES-i)%NUMVERTICES; 2238 2238 ind1=(ind0-1+NUMVERTICES)%NUMVERTICES; … … 2248 2248 numiceverts=0; 2249 2249 numnoiceverts=0; 2250 for(i =0;i<NUMVERTICES;i++){2250 for(int i=0;i<NUMVERTICES;i++){ 2251 2251 ind0=(lastindex+i)%NUMVERTICES; 2252 2252 if(lsf[i]<=level){ … … 2260 2260 } 2261 2261 //merge indices 2262 for(i=0;i<numiceverts;i++){indices[i]=indices_ice[i];} 2263 for(i=0;i<numnoiceverts;i++){indices[numiceverts+i]=indices_noice[i];} 2264 2265 switch (numiceverts){ 2262 for(int i=0;i<numiceverts; i++){ 2263 indices[i]=indices_ice[i]; 2264 } 2265 for(int i=0;i<numnoiceverts;i++){ 2266 indices[numiceverts+i]=indices_noice[i]; 2267 } 2268 2269 switch(numiceverts){ 2266 2270 case 0: // no vertex has ice: element is ice free, no intersection 2267 for(i =0;i<2;i++)2271 for(int i=0;i<2;i++) 2268 2272 fraction[i]=0.; 2269 2273 break; 2270 2274 case 1: // one vertex has ice: 2271 for(i =0;i<2;i++){2275 for(int i=0;i<2;i++){ 2272 2276 fraction[i]=(level-lsf[indices[0]])/(lsf[indices[numiceverts+i]]-lsf[indices[0]]); 2273 2277 } 2274 2278 break; 2275 2279 case 2: // two vertices have ice: fraction is computed from first ice vertex to last in CCW fashion 2276 for(i =0;i<2;i++){2280 for(int i=0;i<2;i++){ 2277 2281 fraction[i]=(level-lsf[indices[i]])/(lsf[indices[numiceverts]]-lsf[indices[i]]); 2278 2282 } 2279 2283 break; 2280 2284 case NUMVERTICES: // all vertices have ice: return triangle area 2281 for(i =0;i<2;i++)2285 for(int i=0;i<2;i++) 2282 2286 fraction[i]=1.; 2283 2287 break; … … 3257 3261 3258 3262 /*intermediary: */ 3259 IssmDouble* values=NULL;3260 Input* thickness_input=NULL;3261 3263 IssmDouble thickness; 3262 IssmDouble weight;3263 3264 IssmDouble Jdet; 3264 IssmDouble volume;3265 IssmDouble rho_ice;3266 3265 int point1; 3267 3266 IssmDouble fraction1,fraction2; 3268 3267 bool mainlynegative=true; 3269 3268 3270 /*Output:*/3271 volume=0;3272 3273 3269 /* Get node coordinates and dof list: */ 3274 3270 IssmDouble xyz_list[NUMVERTICES][3]; … … 3276 3272 3277 3273 /*Retrieve inputs required:*/ 3278 thickness_input=this->GetInput(ThicknessEnum); _assert_(thickness_input);3274 Input* thickness_input=this->GetInput(ThicknessEnum); _assert_(thickness_input); 3279 3275 3280 3276 /*Retrieve material parameters: */ 3281 rho_ice=FindParam(MaterialsRhoIceEnum);3277 IssmDouble rho_ice=FindParam(MaterialsRhoIceEnum); 3282 3278 3283 3279 /*Retrieve values of the levelset defining the masscon: */ 3284 values = xNew<IssmDouble>(NUMVERTICES);3280 IssmDouble values[NUMVERTICES]; 3285 3281 for(int i=0;i<NUMVERTICES;i++){ 3286 3282 values[i]=levelset[this->vertices[i]->Sid()]; … … 3288 3284 3289 3285 /*Ok, use the level set values to figure out where we put our gaussian points:*/ 3290 this->GetLevelsetPositivePart(&point1,&fraction1,&fraction2,&mainlynegative, values);3286 this->GetLevelsetPositivePart(&point1,&fraction1,&fraction2,&mainlynegative,&values[0]); 3291 3287 Gauss* gauss = this->NewGauss(point1,fraction1,fraction2,mainlynegative,4); 3292 3288 3293 volume=0; 3294 3289 IssmDouble volume=0.; 3295 3290 while(gauss->next()){ 3296 3297 3291 this->JacobianDeterminant(&Jdet,&xyz_list[0][0],gauss); 3298 3292 thickness_input->GetInputValue(&thickness, gauss); 3299 3300 3293 volume+=thickness*gauss->weight*Jdet; 3301 3294 } 3302 3295 3303 3296 /* clean up and Return: */ 3304 xDelete<IssmDouble>(values);3305 3297 delete gauss; 3306 3298 return rho_ice*volume;
Note:
See TracChangeset
for help on using the changeset viewer.