Changeset 4690
- Timestamp:
- Aug 29, 2007, 12:07:31 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/shallow_water_ext.c
r4687 r4690 20 20 //Shared code snippets 21 21 #include "util_ext.h" 22 22 23 23 24 const double pi = 3.14159265358979; … … 867 868 double dqv[3], qmin, qmax, hmin; 868 869 double hc, h0, h1, h2; 870 double epsilon=1.0e-12; // FIXME Pass in 869 871 double beta_w, beta_w_dry, beta_uh, beta_uh_dry, beta_vh, beta_vh_dry, beta_tmp; 870 872 double minimum_allowed_height; … … 952 954 k6=k*6; 953 955 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*/ 955 959 ((double *) stage_vertex_values->data)[k3]=((double *)stage_centroid_values->data)[k]; 956 960 ((double *) stage_vertex_values->data)[k3+1]=((double *)stage_centroid_values->data)[k]; … … 964 968 continue; 965 969 } 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 968 975 xv0=((double *)vertex_coordinates->data)[k6]; yv0=((double *)vertex_coordinates->data)[k6+1]; 969 976 xv1=((double *)vertex_coordinates->data)[k6+2]; yv1=((double *)vertex_coordinates->data)[k6+3]; 970 977 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 972 980 coord_index=2*k; 973 981 x=((double *)centroid_coordinates->data)[coord_index]; 974 982 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 976 985 dxv0=xv0-x; dxv1=xv1-x; dxv2=xv2-x; 977 986 dyv0=yv0-y; dyv1=yv1-y; dyv2=yv2-y; 978 987 } 988 989 990 991 992 993 979 994 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 982 1003 k0=((long *)surrogate_neighbours->data)[k3]; 983 1004 k1=((long *)surrogate_neighbours->data)[k3+1]; 984 1005 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) 986 1008 coord_index=2*k0; 987 1009 x0=((double *)centroid_coordinates->data)[coord_index]; … … 993 1015 x2=((double *)centroid_coordinates->data)[coord_index]; 994 1016 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 996 1019 dx1=x1-x0; dx2=x2-x0; 997 1020 dy1=y1-y0; dy2=y2-y0; 998 //calculate 2*area of the auxiliary triangle 1021 1022 // Calculate 2*area of the auxiliary triangle 999 1023 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: 1001 1026 if (area2<=0) { 1002 1027 PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: negative triangle area encountered"); … … 1004 1029 } 1005 1030 1006 1007 //### Calculate heights of neighbouring cells 1031 // Calculate heights of neighbouring cells 1008 1032 hc = ((double *)stage_centroid_values->data)[k] - ((double *)elevation_centroid_values->data)[k]; 1009 1033 h0 = ((double *)stage_centroid_values->data)[k0] - ((double *)elevation_centroid_values->data)[k0]; … … 1012 1036 hmin = min(hc,min(h0,min(h1,h2))); 1013 1037 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 1016 1052 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 1018 1055 dq1=((double *)stage_centroid_values->data)[k1]-((double *)stage_centroid_values->data)[k0]; 1019 1056 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 1021 1059 a = dy2*dq1 - dy1*dq2; 1022 1060 a /= area2; 1023 1061 b = dx1*dq2 - dx2*dq1; 1024 1062 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 1026 1065 dqv[0]=a*dxv0+b*dyv0; 1027 1066 dqv[1]=a*dxv1+b*dyv1; 1028 1067 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 1031 1071 find_qmin_and_qmax(dq0,dq1,dq2,&qmin,&qmax); 1072 1032 1073 // Playing with dry wet interface 1033 1074 hmin = qmin; … … 1039 1080 ((double *)stage_vertex_values->data)[k3+i]=((double *)stage_centroid_values->data)[k]+dqv[i]; 1040 1081 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 1043 1088 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 1045 1091 dq1=((double *)xmom_centroid_values->data)[k1]-((double *)xmom_centroid_values->data)[k0]; 1046 1092 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 1048 1095 a = dy2*dq1 - dy1*dq2; 1049 1096 a /= area2; 1050 1097 b = dx1*dq2 - dx2*dq1; 1051 1098 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 1053 1101 dqv[0]=a*dxv0+b*dyv0; 1054 1102 dqv[1]=a*dxv1+b*dyv1; 1055 1103 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 1058 1107 find_qmin_and_qmax(dq0,dq1,dq2,&qmin,&qmax); 1059 1108 beta_tmp = beta_uh; … … 1064 1113 ((double *)xmom_vertex_values->data)[k3+i]=((double *)xmom_centroid_values->data)[k]+dqv[i]; 1065 1114 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 1068 1121 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 1070 1124 dq1=((double *)ymom_centroid_values->data)[k1]-((double *)ymom_centroid_values->data)[k0]; 1071 1125 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 1073 1128 a = dy2*dq1 - dy1*dq2; 1074 1129 a /= area2; 1075 1130 b = dx1*dq2 - dx2*dq1; 1076 1131 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 1078 1134 dqv[0]=a*dxv0+b*dyv0; 1079 1135 dqv[1]=a*dxv1+b*dyv1; 1080 1136 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 1083 1140 find_qmin_and_qmax(dq0,dq1,dq2,&qmin,&qmax); 1084 1141 beta_tmp = beta_vh; … … 1088 1145 for (i=0;i<3;i++) 1089 1146 ((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 1094 1157 for (k2=k3;k2<k3+3;k2++){//k2 just indexes the edges of triangle k 1095 1158 if (((long *)surrogate_neighbours->data)[k2]!=k)//find internal neighbour of triabngle k … … 1102 1165 1103 1166 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) 1105 1169 coord_index=2*k1; 1106 1170 x1=((double *)centroid_coordinates->data)[coord_index]; 1107 1171 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 1109 1174 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 1111 1177 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 1114 1181 dx2=1.0/area2; 1115 1182 dy2=dx2*dy1; 1116 1183 dx2*=dx1; 1117 1184 1118 //## stage ### 1119 //compute differentials 1185 1186 1187 //----------------------------------- 1188 // stage 1189 //----------------------------------- 1190 1191 // Compute differentials 1120 1192 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 1122 1195 a=dq1*dx2; 1123 1196 b=dq1*dy2; 1124 //calculate provisional vertex jumps, to be limited 1197 1198 // Calculate provisional vertex jumps, to be limited 1125 1199 dqv[0]=a*dxv0+b*dyv0; 1126 1200 dqv[1]=a*dxv1+b*dyv1; 1127 1201 dqv[2]=a*dxv2+b*dyv2; 1128 //now limit the jumps 1202 1203 // Now limit the jumps 1129 1204 if (dq1>=0.0){ 1130 1205 qmin=0.0; … … 1141 1216 ((double *)stage_vertex_values->data)[k3+i]=((double *)stage_centroid_values->data)[k]+dqv[i]; 1142 1217 1143 //## xmom ### 1144 //compute differentials 1218 //----------------------------------- 1219 // xmomentum 1220 //----------------------------------- 1221 1222 // Compute differentials 1145 1223 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 1147 1226 a=dq1*dx2; 1148 1227 b=dq1*dy2; 1149 //calculate provisional vertex jumps, to be limited 1228 1229 // Calculate provisional vertex jumps, to be limited 1150 1230 dqv[0]=a*dxv0+b*dyv0; 1151 1231 dqv[1]=a*dxv1+b*dyv1; 1152 1232 dqv[2]=a*dxv2+b*dyv2; 1153 //now limit the jumps 1233 1234 // Now limit the jumps 1154 1235 if (dq1>=0.0){ 1155 1236 qmin=0.0; … … 1164 1245 ((double *)xmom_vertex_values->data)[k3+i]=((double *)xmom_centroid_values->data)[k]+dqv[i]; 1165 1246 1166 //## ymom ### 1167 //compute differentials 1247 //----------------------------------- 1248 // ymomentum 1249 //----------------------------------- 1250 1251 // Compute differentials 1168 1252 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 1170 1255 a=dq1*dx2; 1171 1256 b=dq1*dy2; 1172 //calculate provisional vertex jumps, to be limited 1257 1258 // Calculate provisional vertex jumps, to be limited 1173 1259 dqv[0]=a*dxv0+b*dyv0; 1174 1260 dqv[1]=a*dxv1+b*dyv1; 1175 1261 dqv[2]=a*dxv2+b*dyv2; 1176 //now limit the jumps 1262 1263 // Now limit the jumps 1177 1264 if (dq1>=0.0){ 1178 1265 qmin=0.0; … … 1186 1273 for (i=0;i<3;i++) 1187 1274 ((double *)ymom_vertex_values->data)[k3+i]=((double *)ymom_centroid_values->data)[k]+dqv[i]; 1188 }//else [number_of_bou daries==2]1275 }//else [number_of_boundaries==2] 1189 1276 }//for k=0 to number_of_elements-1 1277 1190 1278 return Py_BuildValue(""); 1191 1279 }//extrapolate_second-order_sw
Note: See TracChangeset
for help on using the changeset viewer.