Changeset 4690


Ignore:
Timestamp:
Aug 29, 2007, 12:07:31 PM (18 years ago)
Author:
ole
Message:

Code prettyfication and dry cell experiment (commented out) in extrapolate_second_order_sww

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/shallow_water_ext.c

    r4687 r4690  
    2020//Shared code snippets
    2121#include "util_ext.h"
     22
    2223
    2324const double pi = 3.14159265358979;
     
    867868  double dqv[3], qmin, qmax, hmin;
    868869  double hc, h0, h1, h2;
     870  double epsilon=1.0e-12; // FIXME Pass in
    869871  double beta_w, beta_w_dry, beta_uh, beta_uh_dry, beta_vh, beta_vh_dry, beta_tmp;
    870872  double minimum_allowed_height;
     
    952954    k6=k*6;
    953955
    954     if (((long *) number_of_boundaries->data)[k]==3){/*no neighbours, set gradient on the triangle to zero*/
     956   
     957    if (((long *) number_of_boundaries->data)[k]==3){
     958      // No neighbours, set gradient on the triangle to zero*/
    955959      ((double *) stage_vertex_values->data)[k3]=((double *)stage_centroid_values->data)[k];
    956960      ((double *) stage_vertex_values->data)[k3+1]=((double *)stage_centroid_values->data)[k];
     
    964968      continue;
    965969    }
    966     else {//we will need centroid coordinates and vertex coordinates of the triangle
    967       //get the vertex coordinates of the FV triangle
     970    else {
     971      // Triangle k has one or more neighbours.
     972      // Get centroid and vertex coordinates of the triangle
     973     
     974      // Get the vertex coordinates
    968975      xv0=((double *)vertex_coordinates->data)[k6]; yv0=((double *)vertex_coordinates->data)[k6+1];
    969976      xv1=((double *)vertex_coordinates->data)[k6+2]; yv1=((double *)vertex_coordinates->data)[k6+3];
    970977      xv2=((double *)vertex_coordinates->data)[k6+4]; yv2=((double *)vertex_coordinates->data)[k6+5];
    971       //get the centroid coordinates of the FV triangle
     978     
     979      // Get the centroid coordinates
    972980      coord_index=2*k;
    973981      x=((double *)centroid_coordinates->data)[coord_index];
    974982      y=((double *)centroid_coordinates->data)[coord_index+1];
    975       //store x- and y- differentials for the vertices of the FV triangle relative to the centroid
     983     
     984      // Store x- and y- differentials for the vertices of the FV triangle relative to the centroid
    976985      dxv0=xv0-x; dxv1=xv1-x; dxv2=xv2-x;
    977986      dyv0=yv0-y; dyv1=yv1-y; dyv2=yv2-y;
    978987    }
     988
     989
     990   
     991   
     992   
     993           
    979994    if (((long *)number_of_boundaries->data)[k]<=1){
    980       //if no boundaries, auxiliary triangle is formed from the centroids of the three neighbours
    981       //if one boundary, auxiliary triangle is formed from this centroid and its two neighbours
     995   
     996      //==============================================
     997      // Number of boundaries <= 1
     998      //==============================================   
     999   
     1000   
     1001      // If no boundaries, auxiliary triangle is formed from the centroids of the three neighbours
     1002      // If one boundary, auxiliary triangle is formed from this centroid and its two neighbours
    9821003      k0=((long *)surrogate_neighbours->data)[k3];
    9831004      k1=((long *)surrogate_neighbours->data)[k3+1];
    9841005      k2=((long *)surrogate_neighbours->data)[k3+2];
    985       //get the auxiliary triangle's vertex coordinates (really the centroids of neighbouring triangles)
     1006     
     1007      // Get the auxiliary triangle's vertex coordinates (really the centroids of neighbouring triangles)
    9861008      coord_index=2*k0;
    9871009      x0=((double *)centroid_coordinates->data)[coord_index];
     
    9931015      x2=((double *)centroid_coordinates->data)[coord_index];
    9941016      y2=((double *)centroid_coordinates->data)[coord_index+1];
    995       //store x- and y- differentials for the vertices of the auxiliary triangle
     1017     
     1018      // Store x- and y- differentials for the vertices of the auxiliary triangle
    9961019      dx1=x1-x0; dx2=x2-x0;
    9971020      dy1=y1-y0; dy2=y2-y0;
    998       //calculate 2*area of the auxiliary triangle
     1021     
     1022      // Calculate 2*area of the auxiliary triangle
    9991023      area2 = dy2*dx1 - dy1*dx2;//the triangle is guaranteed to be counter-clockwise
    1000       //If the mesh is 'weird' near the boundary, the trianlge might be flat or clockwise:
     1024     
     1025      // If the mesh is 'weird' near the boundary, the triangle might be flat or clockwise:
    10011026      if (area2<=0) {
    10021027        PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: negative triangle area encountered");
     
    10041029      } 
    10051030     
    1006 
    1007       //### Calculate heights of neighbouring cells
     1031      // Calculate heights of neighbouring cells
    10081032      hc = ((double *)stage_centroid_values->data)[k]  - ((double *)elevation_centroid_values->data)[k];
    10091033      h0 = ((double *)stage_centroid_values->data)[k0] - ((double *)elevation_centroid_values->data)[k0];
     
    10121036      hmin = min(hc,min(h0,min(h1,h2)));
    10131037     
    1014       //### stage ###
    1015       //calculate the difference between vertex 0 of the auxiliary triangle and the FV triangle centroid
     1038     
     1039      // Dry cell optimisation experiment
     1040      //printf("hmin = %e\n", hmin);     
     1041      //if (hmin < epsilon) {
     1042        //printf("Dry\n");
     1043        //continue;
     1044      //}
     1045
     1046           
     1047      //-----------------------------------
     1048      // stage
     1049      //-----------------------------------     
     1050     
     1051      // Calculate the difference between vertex 0 of the auxiliary triangle and the FV triangle centroid
    10161052      dq0=((double *)stage_centroid_values->data)[k0]-((double *)stage_centroid_values->data)[k];
    1017       //calculate differentials between the vertices of the auxiliary triangle
     1053     
     1054      // Calculate differentials between the vertices of the auxiliary triangle
    10181055      dq1=((double *)stage_centroid_values->data)[k1]-((double *)stage_centroid_values->data)[k0];
    10191056      dq2=((double *)stage_centroid_values->data)[k2]-((double *)stage_centroid_values->data)[k0];
    1020       //calculate the gradient of stage on the auxiliary triangle
     1057     
     1058      // Calculate the gradient of stage on the auxiliary triangle
    10211059      a = dy2*dq1 - dy1*dq2;
    10221060      a /= area2;
    10231061      b = dx1*dq2 - dx2*dq1;
    10241062      b /= area2;
    1025       //calculate provisional jumps in stage from the centroid of the FV tri to its vertices, to be limited
     1063     
     1064      // Calculate provisional jumps in stage from the centroid of the FV tri to its vertices, to be limited
    10261065      dqv[0]=a*dxv0+b*dyv0;
    10271066      dqv[1]=a*dxv1+b*dyv1;
    10281067      dqv[2]=a*dxv2+b*dyv2;
    1029       //now we want to find min and max of the centroid and the vertices of the auxiliary triangle
    1030       //and compute jumps from the centroid to the min and max
     1068     
     1069      // Now we want to find min and max of the centroid and the vertices of the auxiliary triangle
     1070      // and compute jumps from the centroid to the min and max
    10311071      find_qmin_and_qmax(dq0,dq1,dq2,&qmin,&qmax);
     1072     
    10321073      // Playing with dry wet interface
    10331074      hmin = qmin;
     
    10391080        ((double *)stage_vertex_values->data)[k3+i]=((double *)stage_centroid_values->data)[k]+dqv[i];
    10401081     
    1041       //### xmom ###
    1042       //calculate the difference between vertex 0 of the auxiliary triangle and the FV triangle centroid
     1082     
     1083      //-----------------------------------
     1084      // xmomentum
     1085      //-----------------------------------           
     1086
     1087      // Calculate the difference between vertex 0 of the auxiliary triangle and the FV triangle centroid
    10431088      dq0=((double *)xmom_centroid_values->data)[k0]-((double *)xmom_centroid_values->data)[k];
    1044       //calculate differentials between the vertices of the auxiliary triangle
     1089     
     1090      // Calculate differentials between the vertices of the auxiliary triangle
    10451091      dq1=((double *)xmom_centroid_values->data)[k1]-((double *)xmom_centroid_values->data)[k0];
    10461092      dq2=((double *)xmom_centroid_values->data)[k2]-((double *)xmom_centroid_values->data)[k0];
    1047       //calculate the gradient of xmom on the auxiliary triangle
     1093     
     1094      // Calculate the gradient of xmom on the auxiliary triangle
    10481095      a = dy2*dq1 - dy1*dq2;
    10491096      a /= area2;
    10501097      b = dx1*dq2 - dx2*dq1;
    10511098      b /= area2;
    1052       //calculate provisional jumps in stage from the centroid of the FV tri to its vertices, to be limited
     1099     
     1100      // Calculate provisional jumps in stage from the centroid of the FV tri to its vertices, to be limited
    10531101      dqv[0]=a*dxv0+b*dyv0;
    10541102      dqv[1]=a*dxv1+b*dyv1;
    10551103      dqv[2]=a*dxv2+b*dyv2;
    1056       //now we want to find min and max of the centroid and the vertices of the auxiliary triangle
    1057       //and compute jumps from the centroid to the min and max
     1104     
     1105      // Now we want to find min and max of the centroid and the vertices of the auxiliary triangle
     1106      // and compute jumps from the centroid to the min and max
    10581107      find_qmin_and_qmax(dq0,dq1,dq2,&qmin,&qmax);
    10591108      beta_tmp = beta_uh;
     
    10641113        ((double *)xmom_vertex_values->data)[k3+i]=((double *)xmom_centroid_values->data)[k]+dqv[i];
    10651114     
    1066       //### ymom ###
    1067       //calculate the difference between vertex 0 of the auxiliary triangle and the FV triangle centroid
     1115     
     1116      //-----------------------------------
     1117      // ymomentum
     1118      //-----------------------------------                 
     1119
     1120      // Calculate the difference between vertex 0 of the auxiliary triangle and the FV triangle centroid
    10681121      dq0=((double *)ymom_centroid_values->data)[k0]-((double *)ymom_centroid_values->data)[k];
    1069       //calculate differentials between the vertices of the auxiliary triangle
     1122     
     1123      // Calculate differentials between the vertices of the auxiliary triangle
    10701124      dq1=((double *)ymom_centroid_values->data)[k1]-((double *)ymom_centroid_values->data)[k0];
    10711125      dq2=((double *)ymom_centroid_values->data)[k2]-((double *)ymom_centroid_values->data)[k0];
    1072       //calculate the gradient of xmom on the auxiliary triangle
     1126     
     1127      // Calculate the gradient of xmom on the auxiliary triangle
    10731128      a = dy2*dq1 - dy1*dq2;
    10741129      a /= area2;
    10751130      b = dx1*dq2 - dx2*dq1;
    10761131      b /= area2;
    1077       //calculate provisional jumps in stage from the centroid of the FV tri to its vertices, to be limited
     1132     
     1133      // Calculate provisional jumps in stage from the centroid of the FV tri to its vertices, to be limited
    10781134      dqv[0]=a*dxv0+b*dyv0;
    10791135      dqv[1]=a*dxv1+b*dyv1;
    10801136      dqv[2]=a*dxv2+b*dyv2;
    1081       //now we want to find min and max of the centroid and the vertices of the auxiliary triangle
    1082       //and compute jumps from the centroid to the min and max
     1137     
     1138      // Now we want to find min and max of the centroid and the vertices of the auxiliary triangle
     1139      // and compute jumps from the centroid to the min and max
    10831140      find_qmin_and_qmax(dq0,dq1,dq2,&qmin,&qmax);
    10841141      beta_tmp = beta_vh;
     
    10881145      for (i=0;i<3;i++)
    10891146        ((double *)ymom_vertex_values->data)[k3+i]=((double *)ymom_centroid_values->data)[k]+dqv[i];
    1090     }//if (number_of_boundaries[k]<=1)
    1091     else{//number_of_boundaries==2
    1092       //one internal neighbour and gradient is in direction of the neighbour's centroid
    1093       //find the only internal neighbour
     1147    } // End number_of_boundaries <=1
     1148    else{
     1149
     1150      //==============================================
     1151      // Number of boundaries == 2
     1152      //==============================================       
     1153       
     1154      // One internal neighbour and gradient is in direction of the neighbour's centroid
     1155     
     1156      // Find the only internal neighbour
    10941157      for (k2=k3;k2<k3+3;k2++){//k2 just indexes the edges of triangle k
    10951158        if (((long *)surrogate_neighbours->data)[k2]!=k)//find internal neighbour of triabngle k
     
    11021165     
    11031166      k1=((long *)surrogate_neighbours->data)[k2];
    1104       //the coordinates of the triangle are already (x,y). Get centroid of the neighbour (x1,y1)
     1167     
     1168      // The coordinates of the triangle are already (x,y). Get centroid of the neighbour (x1,y1)
    11051169      coord_index=2*k1;
    11061170      x1=((double *)centroid_coordinates->data)[coord_index];
    11071171      y1=((double *)centroid_coordinates->data)[coord_index+1];
    1108       //compute x- and y- distances between the centroid of the FV triangle and that of its neighbour
     1172     
     1173      // Compute x- and y- distances between the centroid of the FV triangle and that of its neighbour
    11091174      dx1=x1-x; dy1=y1-y;
    1110       //set area2 as the square of the distance
     1175     
     1176      // Set area2 as the square of the distance
    11111177      area2=dx1*dx1+dy1*dy1;
    1112       //set dx2=(x1-x0)/((x1-x0)^2+(y1-y0)^2) and dy2=(y1-y0)/((x1-x0)^2+(y1-y0)^2) which
    1113       //respectively correspond to the x- and y- gradients of the conserved quantities
     1178     
     1179      // Set dx2=(x1-x0)/((x1-x0)^2+(y1-y0)^2) and dy2=(y1-y0)/((x1-x0)^2+(y1-y0)^2) which
     1180      // respectively correspond to the x- and y- gradients of the conserved quantities
    11141181      dx2=1.0/area2;
    11151182      dy2=dx2*dy1;
    11161183      dx2*=dx1;
    11171184     
    1118       //## stage ###
    1119       //compute differentials
     1185     
     1186     
     1187      //-----------------------------------
     1188      // stage
     1189      //-----------------------------------           
     1190
     1191      // Compute differentials
    11201192      dq1=((double *)stage_centroid_values->data)[k1]-((double *)stage_centroid_values->data)[k];
    1121       //calculate the gradient between the centroid of the FV triangle and that of its neighbour
     1193     
     1194      // Calculate the gradient between the centroid of the FV triangle and that of its neighbour
    11221195      a=dq1*dx2;
    11231196      b=dq1*dy2;
    1124       //calculate provisional vertex jumps, to be limited
     1197     
     1198      // Calculate provisional vertex jumps, to be limited
    11251199      dqv[0]=a*dxv0+b*dyv0;
    11261200      dqv[1]=a*dxv1+b*dyv1;
    11271201      dqv[2]=a*dxv2+b*dyv2;
    1128       //now limit the jumps
     1202     
     1203      // Now limit the jumps
    11291204      if (dq1>=0.0){
    11301205        qmin=0.0;
     
    11411216        ((double *)stage_vertex_values->data)[k3+i]=((double *)stage_centroid_values->data)[k]+dqv[i];
    11421217     
    1143       //## xmom ###
    1144       //compute differentials
     1218      //-----------------------------------
     1219      // xmomentum
     1220      //-----------------------------------                       
     1221     
     1222      // Compute differentials
    11451223      dq1=((double *)xmom_centroid_values->data)[k1]-((double *)xmom_centroid_values->data)[k];
    1146       //calculate the gradient between the centroid of the FV triangle and that of its neighbour
     1224     
     1225      // Calculate the gradient between the centroid of the FV triangle and that of its neighbour
    11471226      a=dq1*dx2;
    11481227      b=dq1*dy2;
    1149       //calculate provisional vertex jumps, to be limited
     1228     
     1229      // Calculate provisional vertex jumps, to be limited
    11501230      dqv[0]=a*dxv0+b*dyv0;
    11511231      dqv[1]=a*dxv1+b*dyv1;
    11521232      dqv[2]=a*dxv2+b*dyv2;
    1153       //now limit the jumps
     1233     
     1234      // Now limit the jumps
    11541235      if (dq1>=0.0){
    11551236        qmin=0.0;
     
    11641245        ((double *)xmom_vertex_values->data)[k3+i]=((double *)xmom_centroid_values->data)[k]+dqv[i];
    11651246     
    1166       //## ymom ###
    1167       //compute differentials
     1247      //-----------------------------------
     1248      // ymomentum
     1249      //-----------------------------------                       
     1250
     1251      // Compute differentials
    11681252      dq1=((double *)ymom_centroid_values->data)[k1]-((double *)ymom_centroid_values->data)[k];
    1169       //calculate the gradient between the centroid of the FV triangle and that of its neighbour
     1253     
     1254      // Calculate the gradient between the centroid of the FV triangle and that of its neighbour
    11701255      a=dq1*dx2;
    11711256      b=dq1*dy2;
    1172       //calculate provisional vertex jumps, to be limited
     1257     
     1258      // Calculate provisional vertex jumps, to be limited
    11731259      dqv[0]=a*dxv0+b*dyv0;
    11741260      dqv[1]=a*dxv1+b*dyv1;
    11751261      dqv[2]=a*dxv2+b*dyv2;
    1176       //now limit the jumps
     1262     
     1263      // Now limit the jumps
    11771264      if (dq1>=0.0){
    11781265        qmin=0.0;
     
    11861273      for (i=0;i<3;i++)
    11871274        ((double *)ymom_vertex_values->data)[k3+i]=((double *)ymom_centroid_values->data)[k]+dqv[i];
    1188     }//else [number_of_boudaries==2]
     1275    }//else [number_of_boundaries==2]
    11891276  }//for k=0 to number_of_elements-1
     1277 
    11901278  return Py_BuildValue("");
    11911279}//extrapolate_second-order_sw
Note: See TracChangeset for help on using the changeset viewer.