Changeset 9275


Ignore:
Timestamp:
Jul 21, 2014, 2:26:51 PM (11 years ago)
Author:
davies
Message:

Optimizations for dry edges or beta_tmp=0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/shallow_water/swDE1_domain_ext.c

    r9261 r9275  
    133133  static double q_left_rotated[3], q_right_rotated[3], flux_right[3], flux_left[3];
    134134
     135
    135136  // Copy conserved quantities to protect from modification
    136137  q_left_rotated[0] = q_left[0];
     
    308309  static double q_left_rotated[3], q_right_rotated[3], flux_right[3], flux_left[3];
    309310
     311  if(h_left==0. && h_right==0.){
     312    // Quick exit
     313    memset(edgeflux, 0, 3*sizeof(double));
     314    *max_speed = 0.0;
     315    *pressure_flux = 0.;
     316    return 0;
     317  }
    310318  // Copy conserved quantities to protect from modification
    311319  q_left_rotated[0] = q_left[0];
     
    729737            edgeflux[2] *= length;
    730738
    731 
    732739            //// Don't allow an outward advective flux if the cell centroid
    733740            ////   stage is < the edge value. Is this important (??). Seems not
     
    10751082  double dqv[3], qmin, qmax, hmin, hmax, bedmax,bedmin, stagemin;
    10761083  double hc, h0, h1, h2, beta_tmp, hfactor, xtmp, ytmp, weight, tmp;
    1077   double dk, dv0, dv1, dv2, de[3], demin, dcmax, r0scale, vel_norm, l1, l2, a_tmp, b_tmp, c_tmp,d_tmp;
     1084  double dk, dk_inv,dv0, dv1, dv2, de[3], demin, dcmax, r0scale, vel_norm, l1, l2, a_tmp, b_tmp, c_tmp,d_tmp;
    10781085 
    10791086
     
    10921099          dk = height_centroid_values[k];
    10931100          if(dk>minimum_allowed_height){
     1101              dk_inv=1.0/dk;
    10941102              x_centroid_work[k] = xmom_centroid_values[k];
    1095               xmom_centroid_values[k] = xmom_centroid_values[k]/dk;
     1103              xmom_centroid_values[k] = xmom_centroid_values[k]*dk_inv;
    10961104
    10971105              y_centroid_work[k] = ymom_centroid_values[k];
    1098               ymom_centroid_values[k] = ymom_centroid_values[k]/dk;
     1106              ymom_centroid_values[k] = ymom_centroid_values[k]*dk_inv;
    10991107          }else{
    11001108              x_centroid_work[k] = 0.;
     
    11271135
    11281136      }
     1137
     1138      //if((elevation_centroid_values[k0] > stage_centroid_values[k] | k0==k) &
     1139      //   (elevation_centroid_values[k1] > stage_centroid_values[k] | k1==k) &
     1140      //   (elevation_centroid_values[k2] > stage_centroid_values[k] | k2==k)){
     1141      //        x_centroid_work[k] = 0.;
     1142      //        xmom_centroid_values[k] = 0.;
     1143      //        y_centroid_work[k] = 0.;
     1144      //        ymom_centroid_values[k] = 0.;
     1145
     1146      //}
    11291147  }
    11301148
     
    13001318      hfactor=min( 1.2*max(hmin-minimum_allowed_height,0.)/(max(hmin,0.)+1.*minimum_allowed_height), hfactor);
    13011319
     1320      inv_area2 = 1.0/area2;
    13021321      //-----------------------------------
    13031322      // stage
    13041323      //-----------------------------------     
    13051324     
    1306       // Calculate the difference between vertex 0 of the auxiliary
    1307       // triangle and the centroid of triangle k
    1308       dq0 = stage_centroid_values[k0] - stage_centroid_values[k];
    1309      
    1310       // Calculate differentials between the vertices
    1311       // of the auxiliary triangle (centroids of neighbouring triangles)
    1312       dq1 = stage_centroid_values[k1] - stage_centroid_values[k0];
    1313       dq2 = stage_centroid_values[k2] - stage_centroid_values[k0];
     1325      beta_tmp = beta_w_dry + (beta_w - beta_w_dry) * hfactor;
    13141326     
    1315       inv_area2 = 1.0/area2;
    1316       // Calculate the gradient of stage on the auxiliary triangle
    1317       a = dy2*dq1 - dy1*dq2;
    1318       a *= inv_area2;
    1319       b = dx1*dq2 - dx2*dq1;
    1320       b *= inv_area2;
    1321       // Calculate provisional jumps in stage from the centroid
    1322       // of triangle k to its vertices, to be limited
    1323       dqv[0] = a*dxv0 + b*dyv0;
    1324       dqv[1] = a*dxv1 + b*dyv1;
    1325       dqv[2] = a*dxv2 + b*dyv2;
    1326    
    1327       // Now we want to find min and max of the centroid and the
    1328       // vertices of the auxiliary triangle and compute jumps
    1329       // from the centroid to the min and max
    1330       find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
    1331    
    1332       beta_tmp = beta_w_dry + (beta_w - beta_w_dry) * hfactor;
    1333      
    1334       // Limit the gradient
    1335       limit_gradient(dqv, qmin, qmax, beta_tmp);
    1336 
    1337       stage_edge_values[k3+0] = stage_centroid_values[k] + dqv[0];
    1338       stage_edge_values[k3+1] = stage_centroid_values[k] + dqv[1];
    1339       stage_edge_values[k3+2] = stage_centroid_values[k] + dqv[2];
     1327      if(beta_tmp>0.){
     1328          // Calculate the difference between vertex 0 of the auxiliary
     1329          // triangle and the centroid of triangle k
     1330          dq0 = stage_centroid_values[k0] - stage_centroid_values[k];
     1331         
     1332          // Calculate differentials between the vertices
     1333          // of the auxiliary triangle (centroids of neighbouring triangles)
     1334          dq1 = stage_centroid_values[k1] - stage_centroid_values[k0];
     1335          dq2 = stage_centroid_values[k2] - stage_centroid_values[k0];
     1336         
     1337          // Calculate the gradient of stage on the auxiliary triangle
     1338          a = dy2*dq1 - dy1*dq2;
     1339          a *= inv_area2;
     1340          b = dx1*dq2 - dx2*dq1;
     1341          b *= inv_area2;
     1342          // Calculate provisional jumps in stage from the centroid
     1343          // of triangle k to its vertices, to be limited
     1344          dqv[0] = a*dxv0 + b*dyv0;
     1345          dqv[1] = a*dxv1 + b*dyv1;
     1346          dqv[2] = a*dxv2 + b*dyv2;
     1347       
     1348          // Now we want to find min and max of the centroid and the
     1349          // vertices of the auxiliary triangle and compute jumps
     1350          // from the centroid to the min and max
     1351          find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     1352         
     1353          // Limit the gradient
     1354          limit_gradient(dqv, qmin, qmax, beta_tmp);
     1355
     1356          stage_edge_values[k3+0] = stage_centroid_values[k] + dqv[0];
     1357          stage_edge_values[k3+1] = stage_centroid_values[k] + dqv[1];
     1358          stage_edge_values[k3+2] = stage_centroid_values[k] + dqv[2];
     1359      }else{
     1360          // Fast alternative when beta_tmp==0
     1361          stage_edge_values[k3+0] = stage_centroid_values[k];
     1362          stage_edge_values[k3+1] = stage_centroid_values[k];
     1363          stage_edge_values[k3+2] = stage_centroid_values[k];
     1364      }
    13401365
    13411366
     
    13431368      // height
    13441369      //-----------------------------------
     1370     
     1371      if(beta_tmp>0.){
     1372          // Calculate the difference between vertex 0 of the auxiliary
     1373          // triangle and the centroid of triangle k
     1374          dq0 = height_centroid_values[k0] - height_centroid_values[k];
     1375         
     1376          // Calculate differentials between the vertices
     1377          // of the auxiliary triangle (centroids of neighbouring triangles)
     1378          dq1 = height_centroid_values[k1] - height_centroid_values[k0];
     1379          dq2 = height_centroid_values[k2] - height_centroid_values[k0];
     1380         
     1381          // Calculate the gradient of height on the auxiliary triangle
     1382          a = dy2*dq1 - dy1*dq2;
     1383          a *= inv_area2;
     1384          b = dx1*dq2 - dx2*dq1;
     1385          b *= inv_area2;
     1386          // Calculate provisional jumps in height from the centroid
     1387          // of triangle k to its vertices, to be limited
     1388          dqv[0] = a*dxv0 + b*dyv0;
     1389          dqv[1] = a*dxv1 + b*dyv1;
     1390          dqv[2] = a*dxv2 + b*dyv2;
     1391       
     1392          // Now we want to find min and max of the centroid and the
     1393          // vertices of the auxiliary triangle and compute jumps
     1394          // from the centroid to the min and max
     1395          find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
    13451396       
    1346       // Calculate the difference between vertex 0 of the auxiliary
    1347       // triangle and the centroid of triangle k
    1348       dq0 = height_centroid_values[k0] - height_centroid_values[k];
    1349      
    1350       // Calculate differentials between the vertices
    1351       // of the auxiliary triangle (centroids of neighbouring triangles)
    1352       dq1 = height_centroid_values[k1] - height_centroid_values[k0];
    1353       dq2 = height_centroid_values[k2] - height_centroid_values[k0];
    1354      
    1355       inv_area2 = 1.0/area2;
    1356       // Calculate the gradient of height on the auxiliary triangle
    1357       a = dy2*dq1 - dy1*dq2;
    1358       a *= inv_area2;
    1359       b = dx1*dq2 - dx2*dq1;
    1360       b *= inv_area2;
    1361       // Calculate provisional jumps in height from the centroid
    1362       // of triangle k to its vertices, to be limited
    1363       dqv[0] = a*dxv0 + b*dyv0;
    1364       dqv[1] = a*dxv1 + b*dyv1;
    1365       dqv[2] = a*dxv2 + b*dyv2;
    1366    
    1367       // Now we want to find min and max of the centroid and the
    1368       // vertices of the auxiliary triangle and compute jumps
    1369       // from the centroid to the min and max
    1370       find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
    1371    
    1372       // Limit the gradient
    1373       // Same beta_tmp as for stage
    1374       //beta_tmp = beta_uh_dry + (beta_uh - beta_uh_dry) * hfactor;
    1375       limit_gradient(dqv, qmin, qmax, beta_tmp);
    1376 
    1377       //beta_tmp = 0. + (beta_w - 0.) * hfactor;
    1378 
    1379       height_edge_values[k3+0] = height_centroid_values[k] + dqv[0];
    1380       height_edge_values[k3+1] = height_centroid_values[k] + dqv[1];
    1381       height_edge_values[k3+2] = height_centroid_values[k] + dqv[2];
    1382 
     1397          // Limit the gradient
     1398          // Same beta_tmp as for stage
     1399          //beta_tmp = beta_uh_dry + (beta_uh - beta_uh_dry) * hfactor;
     1400          limit_gradient(dqv, qmin, qmax, beta_tmp);
     1401
     1402          //beta_tmp = 0. + (beta_w - 0.) * hfactor;
     1403
     1404          height_edge_values[k3+0] = height_centroid_values[k] + dqv[0];
     1405          height_edge_values[k3+1] = height_centroid_values[k] + dqv[1];
     1406          height_edge_values[k3+2] = height_centroid_values[k] + dqv[2];
     1407      }else{
     1408          // Fast alternative when beta_tmp==0
     1409          height_edge_values[k3+0] = height_centroid_values[k];
     1410          height_edge_values[k3+1] = height_centroid_values[k];
     1411          height_edge_values[k3+2] = height_centroid_values[k];
     1412      }
    13831413      //-----------------------------------
    13841414      // xmomentum
    13851415      //-----------------------------------           
    13861416
    1387       // Calculate the difference between vertex 0 of the auxiliary
    1388       // triangle and the centroid of triangle k     
    1389       dq0 = xmom_centroid_values[k0] - xmom_centroid_values[k];
    1390      
    1391       // Calculate differentials between the vertices
    1392       // of the auxiliary triangle
    1393       dq1 = xmom_centroid_values[k1] - xmom_centroid_values[k0];
    1394       dq2 = xmom_centroid_values[k2] - xmom_centroid_values[k0];
    1395      
    1396       // Calculate the gradient of xmom on the auxiliary triangle
    1397       a = dy2*dq1 - dy1*dq2;
    1398       a *= inv_area2;
    1399       b = dx1*dq2 - dx2*dq1;
    1400       b *= inv_area2;
    1401      
    1402       // Calculate provisional jumps in stage from the centroid
    1403       // of triangle k to its vertices, to be limited     
    1404       dqv[0] = a*dxv0+b*dyv0;
    1405       dqv[1] = a*dxv1+b*dyv1;
    1406       dqv[2] = a*dxv2+b*dyv2;
    1407      
    1408       // Now we want to find min and max of the centroid and the
    1409       // vertices of the auxiliary triangle and compute jumps
    1410       // from the centroid to the min and max
    1411       //
    1412       find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
    1413 
    14141417      beta_tmp = beta_uh_dry + (beta_uh - beta_uh_dry) * hfactor;
    1415 
    1416       // Limit the gradient
    1417       limit_gradient(dqv, qmin, qmax, beta_tmp);
    1418 
    1419       for (i=0; i < 3; i++)
    1420       {
    1421         xmom_edge_values[k3+i] = xmom_centroid_values[k] + dqv[i];
     1418      if(beta_tmp>0.){
     1419          // Calculate the difference between vertex 0 of the auxiliary
     1420          // triangle and the centroid of triangle k     
     1421          dq0 = xmom_centroid_values[k0] - xmom_centroid_values[k];
     1422         
     1423          // Calculate differentials between the vertices
     1424          // of the auxiliary triangle
     1425          dq1 = xmom_centroid_values[k1] - xmom_centroid_values[k0];
     1426          dq2 = xmom_centroid_values[k2] - xmom_centroid_values[k0];
     1427         
     1428          // Calculate the gradient of xmom on the auxiliary triangle
     1429          a = dy2*dq1 - dy1*dq2;
     1430          a *= inv_area2;
     1431          b = dx1*dq2 - dx2*dq1;
     1432          b *= inv_area2;
     1433         
     1434          // Calculate provisional jumps in stage from the centroid
     1435          // of triangle k to its vertices, to be limited     
     1436          dqv[0] = a*dxv0+b*dyv0;
     1437          dqv[1] = a*dxv1+b*dyv1;
     1438          dqv[2] = a*dxv2+b*dyv2;
     1439         
     1440          // Now we want to find min and max of the centroid and the
     1441          // vertices of the auxiliary triangle and compute jumps
     1442          // from the centroid to the min and max
     1443          //
     1444          find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     1445
     1446
     1447          // Limit the gradient
     1448          limit_gradient(dqv, qmin, qmax, beta_tmp);
     1449
     1450          for (i=0; i < 3; i++)
     1451          {
     1452            xmom_edge_values[k3+i] = xmom_centroid_values[k] + dqv[i];
     1453          }
     1454      }else{
     1455          // Fast alternative when beta_tmp==0
     1456          for (i=0; i < 3; i++)
     1457          {
     1458            xmom_edge_values[k3+i] = xmom_centroid_values[k];
     1459          }
    14221460      }
    14231461     
     
    14251463      // ymomentum
    14261464      //-----------------------------------                 
    1427 
    1428       // Calculate the difference between vertex 0 of the auxiliary
    1429       // triangle and the centroid of triangle k
    1430       dq0 = ymom_centroid_values[k0] - ymom_centroid_values[k];
    1431      
    1432       // Calculate differentials between the vertices
    1433       // of the auxiliary triangle
    1434       dq1 = ymom_centroid_values[k1] - ymom_centroid_values[k0];
    1435       dq2 = ymom_centroid_values[k2] - ymom_centroid_values[k0];
    1436      
    1437       // Calculate the gradient of xmom on the auxiliary triangle
    1438       a = dy2*dq1 - dy1*dq2;
    1439       a *= inv_area2;
    1440       b = dx1*dq2 - dx2*dq1;
    1441       b *= inv_area2;
    1442      
    1443       // Calculate provisional jumps in stage from the centroid
    1444       // of triangle k to its vertices, to be limited
    1445       dqv[0] = a*dxv0 + b*dyv0;
    1446       dqv[1] = a*dxv1 + b*dyv1;
    1447       dqv[2] = a*dxv2 + b*dyv2;
    1448      
    1449       // Now we want to find min and max of the centroid and the
    1450       // vertices of the auxiliary triangle and compute jumps
    1451       // from the centroid to the min and max
    1452       //
    1453       find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
    14541465     
    14551466      beta_tmp = beta_vh_dry + (beta_vh - beta_vh_dry) * hfactor;   
    14561467
    1457       // Limit the gradient
    1458       limit_gradient(dqv, qmin, qmax, beta_tmp);
    1459      
    1460       for (i=0;i<3;i++)
    1461       {
    1462         ymom_edge_values[k3 + i] = ymom_centroid_values[k] + dqv[i];
     1468      if(beta_tmp>0.){
     1469          // Calculate the difference between vertex 0 of the auxiliary
     1470          // triangle and the centroid of triangle k
     1471          dq0 = ymom_centroid_values[k0] - ymom_centroid_values[k];
     1472         
     1473          // Calculate differentials between the vertices
     1474          // of the auxiliary triangle
     1475          dq1 = ymom_centroid_values[k1] - ymom_centroid_values[k0];
     1476          dq2 = ymom_centroid_values[k2] - ymom_centroid_values[k0];
     1477         
     1478          // Calculate the gradient of xmom on the auxiliary triangle
     1479          a = dy2*dq1 - dy1*dq2;
     1480          a *= inv_area2;
     1481          b = dx1*dq2 - dx2*dq1;
     1482          b *= inv_area2;
     1483         
     1484          // Calculate provisional jumps in stage from the centroid
     1485          // of triangle k to its vertices, to be limited
     1486          dqv[0] = a*dxv0 + b*dyv0;
     1487          dqv[1] = a*dxv1 + b*dyv1;
     1488          dqv[2] = a*dxv2 + b*dyv2;
     1489         
     1490          // Now we want to find min and max of the centroid and the
     1491          // vertices of the auxiliary triangle and compute jumps
     1492          // from the centroid to the min and max
     1493          //
     1494          find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     1495         
     1496
     1497          // Limit the gradient
     1498          limit_gradient(dqv, qmin, qmax, beta_tmp);
     1499         
     1500          for (i=0;i<3;i++)
     1501          {
     1502            ymom_edge_values[k3 + i] = ymom_centroid_values[k] + dqv[i];
     1503          }
     1504      }else{
     1505          // Fast alternative when beta_tmp==0
     1506          for (i=0;i<3;i++)
     1507          {
     1508            ymom_edge_values[k3 + i] = ymom_centroid_values[k];
     1509          }
     1510
    14631511      }
    14641512     
     
    16881736          // Re-compute momenta at edges
    16891737          for (i=0; i<3; i++){
    1690               //if(hfactor>=0.8){
    16911738              dk= height_edge_values[k3+i];
    1692               //}else{
    1693               //   de[i] = height_centroid_values[k];
    1694               //}
    16951739              xmom_edge_values[k3+i]=xmom_edge_values[k3+i]*dk;
    16961740              ymom_edge_values[k3+i]=ymom_edge_values[k3+i]*dk;
     
    17041748      ymom_vertex_values[k3+1] =  ymom_edge_values[k3] + ymom_edge_values[k3+2]-ymom_edge_values[k3+1];
    17051749      ymom_vertex_values[k3+2] =  ymom_edge_values[k3] + ymom_edge_values[k3+1]-ymom_edge_values[k3+2];
    1706 
    1707      
    17081750
    17091751      // Compute new bed elevation
Note: See TracChangeset for help on using the changeset viewer.