Changeset 1328 for XIOS/dev/branch_openmp/extern/remap/src/intersect.cpp
- Timestamp:
- 11/15/17 12:14:34 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/extern/remap/src/intersect.cpp
r1220 r1328 15 15 namespace sphereRemap { 16 16 17 extern CRemapGrid srcGrid;18 #pragma omp threadprivate(srcGrid)19 20 extern CRemapGrid tgtGrid;21 #pragma omp threadprivate(tgtGrid)22 23 17 using namespace std; 24 18 … … 27 21 int neighbour_idx(const Elt& a, const Elt& b) 28 22 { 29 30 31 32 33 34 35 36 37 38 39 40 41 42 23 for (int i = 0; i < a.n; i++) 24 { 25 for (int j = 0; j < b.n; j++) 26 { 27 assert(squaredist(a.vertex[ i ], b.vertex[ j ]) > EPS*EPS || 28 squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+1)%b.n]) > EPS*EPS); 29 if ( squaredist(a.vertex[ i ], b.vertex[ j ]) < 1e-13*1e-13 && 30 squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+b.n-1)%b.n]) < 1e-13*1e-13) 31 { 32 return i; 33 } 34 } 35 } 36 return NOT_FOUND; 43 37 } 44 38 … … 211 205 bool isNeighbour(Elt& a, const Elt& b) 212 206 { 213 207 // return neighbour_idx(a, b) != NOT_FOUND; 214 208 return insertNeighbour(a,b,false) ; 215 209 } … … 219 213 void intersect(Elt *a, Elt *b) 220 214 { 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 // 215 int na = a->n; /* vertices of a */ 216 int nb = b->n; /* vertices of b */ 217 Coord *c = new Coord[na+nb]; 218 Coord *c2 = new Coord[na+nb]; 219 Coord *xc = new Coord[na+nb]; 220 Coord *xc2 = new Coord[na+nb]; 221 Coord gc, gc2; 222 double *d = new double[na+nb]; 223 double *d2 = new double[na+nb]; 224 double are, are2; 225 Ipt ipt[NMAX*NMAX]; 226 Ipt ipt2[NMAX*NMAX]; 227 ptsec(a, b, ipt); 228 /* make ipt2 transpose of ipt */ 229 for (int ii = 0; ii < na; ii++) 230 for (int jj = 0; jj < nb; jj++) 231 ipt2[jj*na+ii] = ipt[ii*nb+jj]; 232 list<Sgm> iscot; 233 recense(a, b, ipt, iscot, 0); 234 recense(b, a, ipt2, iscot, 1); 235 236 int nseg = iscot.size(); 237 int nc = 0; 238 int nc2 = 0; 239 while (iscot.size() && nc < 2) 240 nc = assemble(iscot, c, d, xc); 241 while (iscot.size() && nc2 < 2) 242 nc2 = assemble(iscot, c2, d2, xc2); 243 // assert(nseg == nc + nc2 || nseg == 1); // unused segment 250 244 251 245 if (!(nseg == nc + nc2 || nseg == 1)) … … 266 260 267 261 // intersect_ym(a,b) ; 268 269 270 271 272 273 274 275 276 277 278 279 262 if (nc == 1) nc = 0; 263 if (nc2 == 1) nc2 = 0; 264 gc = barycentre(xc, nc); 265 gc2 = barycentre(xc2, nc2); 266 orient(nc, xc, c, d, gc); 267 268 Coord pole = srcGrid.pole; 269 if (pole == ORIGIN) pole = tgtGrid.pole; 270 const double MINBASE = 1e-11; 271 if (nc == 2) /* nc is the number of vertices of super mesh element */ 272 { 273 double base = arcdist(xc[0], xc[1]); 280 274 cerr << "DID ARRIVE " << base << xc[0] << xc[1] << endl; 281 282 283 284 285 286 287 288 289 290 291 275 gc = midpoint(gc, midpointSC(xc[0], xc[1])); 276 /* intersection area `are` must be zero here unless we have one great and one small circle */ 277 are = alun(base, fabs(scalarprod(xc[0], pole))); 278 } 279 else 280 { 281 are = airbar(nc, xc, c, d, pole, gc); 282 } 283 if (nc2 == 2) 284 { 285 double base = arcdist(xc2[0], xc2[1]); 292 286 cerr << "DID ARRIVE " << base << xc2[0] << xc2[1] << endl; 293 294 295 296 297 298 299 300 287 assert(base > MINBASE); 288 gc2 = midpoint(gc2, midpointSC(xc2[0], xc2[1])); 289 are2 = alun(base, fabs(scalarprod(xc2[0], pole))); // 0 290 } 291 else 292 { 293 are2 = airbar(nc2, xc2, c2, d2, pole, gc2); 294 } 301 295 302 296 // double ym_area=intersect_ym(a,b) ; 303 297 304 298 if (nc > 1) 305 306 307 308 309 310 311 312 313 314 299 { 300 /* create one super mesh polygon that src and dest point to */ 301 Polyg *is = new Polyg; 302 is->x = gc; 303 is->area = are; 304 is->id = b->id; 305 is->src_id = b->src_id; 306 is->n = nc; 307 (a->is).push_back(is); 308 (b->is).push_back(is); 315 309 /* 316 if (2*fabs(are-ym_area)/(are+ym_area) > 1.1 && ym_area>1e-8)310 if ( 2*fabs(are-ym_area)/(are+ym_area) > 1.1 && ym_area>1e-8) 317 311 { 318 312 cout<<"Big area difference : "<<are<<" "<<ym_area<<endl ; … … 320 314 } 321 315 */ 322 // 323 324 325 326 327 328 329 330 331 332 333 316 // cout<<"intersection : "<<are<<" "<< ym_area<<" diff : "<<fabs(are-ym_area)<<" ratio : "<<fabs(are-ym_area)/(0.5*(are+ym_area))<<endl ; 317 } 318 if (nc2 > 1) 319 { 320 Polyg *is = new Polyg; 321 is->x = gc2; 322 is->area = are2; 323 is->id = b->id; /* intersection holds id of corresponding source element (see Elt class definition for details about id) */ 324 is->src_id = b->src_id; 325 is->n = nc2; 326 (a->is).push_back(is); 327 (b->is).push_back(is); 334 328 /* 335 if ( 329 if ( 2*fabs(are-ym_area)/(are+ym_area) > 1.1 && ym_area>1e-8 ) 336 330 { 337 331 cout<<"Big area difference : "<<are<<" "<<ym_area<<endl ; … … 339 333 } 340 334 */ 341 // 342 335 // cout<<"intersection : "<<are2<<" "<< ym_area<<" diff : "<<fabs(are-ym_area)<<" ratio : "<<fabs(are-ym_area)/(0.5*(are+ym_area))<<endl ; 336 } 343 337 /* 344 338 if (nc<=1 && nc2<=1) … … 350 344 } 351 345 */ 352 353 354 355 356 357 358 } 359 360 } 346 delete [] c; 347 delete [] c2; 348 delete [] xc; 349 delete [] xc2; 350 delete [] d; 351 delete [] d2; 352 } 353 354 }
Note: See TracChangeset
for help on using the changeset viewer.