| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 4 |
// vi: set et ts=4 sw=2 sts=2: |
| 5 |
/****************************************************************************/ |
| 6 |
/* */ |
| 7 |
/* File: overlap.c */ |
| 8 |
/* */ |
| 9 |
/* Purpose: management of grid overlap during adaption */ |
| 10 |
/* */ |
| 11 |
/* Author: Stefan Lang */ |
| 12 |
/* Institut fuer Computeranwendungen III */ |
| 13 |
/* Universitaet Stuttgart */ |
| 14 |
/* Pfaffenwaldring 27 */ |
| 15 |
/* 70569 Stuttgart */ |
| 16 |
/* */ |
| 17 |
/* History: 970204 sl begin */ |
| 18 |
/* */ |
| 19 |
/****************************************************************************/ |
| 20 |
|
| 21 |
#ifdef ModelP |
| 22 |
|
| 23 |
/****************************************************************************/ |
| 24 |
/* */ |
| 25 |
/* include files */ |
| 26 |
/* system include files */ |
| 27 |
/* application include files */ |
| 28 |
/* */ |
| 29 |
/****************************************************************************/ |
| 30 |
|
| 31 |
/* standard C library */ |
| 32 |
#include <config.h> |
| 33 |
#include <cassert> |
| 34 |
#include <cmath> |
| 35 |
#include <cstdio> |
| 36 |
#include <cstdlib> |
| 37 |
#include <cstring> |
| 38 |
|
| 39 |
/* low module */ |
| 40 |
#include <dune/uggrid/low/debug.h> |
| 41 |
#include <dune/uggrid/low/heaps.h> |
| 42 |
#include <dune/uggrid/low/misc.h> |
| 43 |
#include <dune/uggrid/low/namespace.h> |
| 44 |
#include <dune/uggrid/low/ugtypes.h> |
| 45 |
|
| 46 |
/* dev module */ |
| 47 |
#include <dune/uggrid/ugdevices.h> |
| 48 |
|
| 49 |
/* gm module */ |
| 50 |
#include <dune/uggrid/gm/algebra.h> |
| 51 |
#include <dune/uggrid/gm/evm.h> |
| 52 |
#include <dune/uggrid/gm/gm.h> |
| 53 |
#include <dune/uggrid/gm/pargm.h> |
| 54 |
#include <dune/uggrid/gm/refine.h> |
| 55 |
#include <dune/uggrid/gm/rm.h> |
| 56 |
#include <dune/uggrid/gm/ugm.h> |
| 57 |
|
| 58 |
/* parallel modules */ |
| 59 |
#include <dune/uggrid/parallel/ddd/include/ddd.h> |
| 60 |
#include <dune/uggrid/parallel/ppif/ppif.h> |
| 61 |
#include "identify.h" |
| 62 |
#include "parallel.h" |
| 63 |
|
| 64 |
/* UG namespaces: */ |
| 65 |
USING_UG_NAMESPACES |
| 66 |
|
| 67 |
/* PPIF namespace: */ |
| 68 |
using namespace PPIF; |
| 69 |
|
| 70 |
START_UGDIM_NAMESPACE |
| 71 |
|
| 72 |
/****************************************************************************/ |
| 73 |
/* */ |
| 74 |
/* defines in the following order */ |
| 75 |
/* */ |
| 76 |
/* compile time constants defining static data size (i.e. arrays) */ |
| 77 |
/* other constants */ |
| 78 |
/* macros */ |
| 79 |
/* */ |
| 80 |
/****************************************************************************/ |
| 81 |
|
| 82 |
/* undefine if overlap should be only updated where needed */ |
| 83 |
/* This does not work since the connection of the overlap needs the |
| 84 |
fatherelements on both sides (ghost and master sons) and this is |
| 85 |
not ensured. |
| 86 |
#define UPDATE_FULLOVERLAP |
| 87 |
*/ |
| 88 |
|
| 89 |
/****************************************************************************/ |
| 90 |
/* */ |
| 91 |
/* data structures used in this source file (exported data structures are */ |
| 92 |
/* in the corresponding include file!) */ |
| 93 |
/* */ |
| 94 |
/****************************************************************************/ |
| 95 |
|
| 96 |
|
| 97 |
/****************************************************************************/ |
| 98 |
/* */ |
| 99 |
/* definition of exported global variables */ |
| 100 |
/* */ |
| 101 |
/****************************************************************************/ |
| 102 |
|
| 103 |
|
| 104 |
/****************************************************************************/ |
| 105 |
/* */ |
| 106 |
/* definition of variables global to this source file only (static!) */ |
| 107 |
/* */ |
| 108 |
/****************************************************************************/ |
| 109 |
|
| 110 |
|
| 111 |
/****************************************************************************/ |
| 112 |
/* */ |
| 113 |
/* forward declarations of functions used before they are defined */ |
| 114 |
/* */ |
| 115 |
/****************************************************************************/ |
| 116 |
|
| 117 |
|
| 118 |
/****************************************************************************/ |
| 119 |
/* |
| 120 |
UpdateElementOverlap - |
| 121 |
|
| 122 |
SYNOPSIS: |
| 123 |
static INT UpdateElementOverlap (ELEMENT *theElement); |
| 124 |
|
| 125 |
PARAMETERS: |
| 126 |
. theElement |
| 127 |
|
| 128 |
DESCRIPTION: |
| 129 |
|
| 130 |
RETURN VALUE: |
| 131 |
INT |
| 132 |
*/ |
| 133 |
/****************************************************************************/ |
| 134 |
|
| 135 |
static INT UpdateElementOverlap (DDD::DDDContext& context, ELEMENT *theElement) |
| 136 |
{ |
| 137 |
INT i,s,prio; |
| 138 |
INT SonsOfSide,SonSides[MAX_SONS]; |
| 139 |
ELEMENT *theNeighbor,*theSon; |
| 140 |
ELEMENT *SonList[MAX_SONS]; |
| 141 |
|
| 142 |
/* yellow_class specific code: */ |
| 143 |
/* update need to be done for all elements with THEFLAG set, */ |
| 144 |
/* execpt for yellow copies, since their neighbor need not be */ |
| 145 |
/* refined (s.l. 971029) */ |
| 146 |
#ifndef UPDATE_FULLOVERLAP |
| 147 |
if (!THEFLAG(theElement) && REFINECLASS(theElement)!=YELLOW_CLASS) return(GM_OK); |
| 148 |
#endif |
| 149 |
/* |
| 150 |
if (!THEFLAG(theElement)) return(GM_OK); |
| 151 |
*/ |
| 152 |
|
| 153 |
for (i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 154 |
{ |
| 155 |
theNeighbor = NBELEM(theElement,i); |
| 156 |
if (theNeighbor == NULL) continue; |
| 157 |
|
| 158 |
prio = EPRIO(theNeighbor); |
| 159 |
if (!IS_REFINED(theNeighbor) || !EHGHOSTPRIO(prio)) continue; |
| 160 |
|
| 161 |
/* yellow_class specific code: */ |
| 162 |
/* this is the special situation an update of the element overlap */ |
| 163 |
/* is needed, since the yellow element has now gotten a new yellow */ |
| 164 |
/* neighbor (s.l. 971029) */ |
| 165 |
/* sending of yellow copies is now done in each situation. To send */ |
| 166 |
/* a yellow copy only if needed, THEFLAG(theNeighbor) must be set */ |
| 167 |
/* properly in AdaptGrid() (980114 s.l.) */ |
| 168 |
#ifndef UPDATE_FULLOVERLAP |
| 169 |
if ((REFINECLASS(theElement)==YELLOW_CLASS && !THEFLAG(theElement)) && |
| 170 |
!THEFLAG(theNeighbor)) continue; |
| 171 |
#endif |
| 172 |
|
| 173 |
PRINTDEBUG(gm,1,("%d: EID=%d side=%d NbID=%d " "NbPARTITION=%d\n",me, |
| 174 |
ID(theElement),i,ID(theNeighbor), EPROCPRIO(context, theNeighbor,PrioMaster))) |
| 175 |
|
| 176 |
Get_Sons_of_ElementSide(theElement,i,&SonsOfSide, |
| 177 |
SonList,SonSides,1,0); |
| 178 |
PRINTDEBUG(gm,1,("%d: SonsOfSide=%d\n",me,SonsOfSide)) |
| 179 |
|
| 180 |
for (s=0; s<SonsOfSide; s++) |
| 181 |
{ |
| 182 |
theSon = SonList[s]; |
| 183 |
ASSERT(theSon != NULL); |
| 184 |
|
| 185 |
PRINTDEBUG(gm,1,("%d: Sending Son=%08x/%x SonID=%d " |
| 186 |
"SonLevel=%d to dest=%d\n", me,EGID(theSon),theSon, |
| 187 |
ID(theSon),LEVEL(theSon), EPROCPRIO(context, theNeighbor,PrioMaster))) |
| 188 |
|
| 189 |
if (EPROCPRIO(context, theNeighbor,PrioMaster)>=context.procs()) break; |
| 190 |
|
| 191 |
XFERECOPYX(context, theSon,EPROCPRIO(context, theNeighbor,PrioMaster),PrioHGhost, |
| 192 |
(OBJT(theSon)==BEOBJ) ? BND_SIZE_TAG(TAG(theSon)) : |
| 193 |
INNER_SIZE_TAG(TAG(theSon))); |
| 194 |
/* send son to all elements where theNeighbor is master, vghost or vhghost */ |
| 195 |
if (0) |
| 196 |
{ |
| 197 |
for (auto&& [proc, currentPrio] : DDD_InfoProcListRange(context, PARHDRE(theNeighbor), false)) |
| 198 |
{ |
| 199 |
if (!EHGHOSTPRIO(currentPrio)) |
| 200 |
{ |
| 201 |
XFERECOPYX(context, theSon,proc,PrioHGhost, |
| 202 |
(OBJT(theSon)==BEOBJ) ? BND_SIZE_TAG(TAG(theSon)) : |
| 203 |
INNER_SIZE_TAG(TAG(theSon))); |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
return(GM_OK); |
| 211 |
} |
| 212 |
|
| 213 |
/****************************************************************************/ |
| 214 |
/* |
| 215 |
UpdateGridOverlap - |
| 216 |
|
| 217 |
SYNOPSIS: |
| 218 |
INT UpdateGridOverlap (GRID *theGrid); |
| 219 |
|
| 220 |
PARAMETERS: |
| 221 |
. theGrid |
| 222 |
|
| 223 |
DESCRIPTION: |
| 224 |
|
| 225 |
RETURN VALUE: |
| 226 |
INT |
| 227 |
*/ |
| 228 |
/****************************************************************************/ |
| 229 |
|
| 230 |
INT UpdateGridOverlap (GRID *theGrid) |
| 231 |
{ |
| 232 |
DDD::DDDContext& context = theGrid->dddContext(); |
| 233 |
ELEMENT *theElement; |
| 234 |
|
| 235 |
for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) |
| 236 |
{ |
| 237 |
if (IS_REFINED(theElement)) |
| 238 |
UpdateElementOverlap(context, theElement); |
| 239 |
} |
| 240 |
|
| 241 |
return(GM_OK); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
/****************************************************************************/ |
| 246 |
/* |
| 247 |
UpdateMultiGridOverlap - |
| 248 |
|
| 249 |
SYNOPSIS: |
| 250 |
static INT UpdateMultiGridOverlap (MULTIGRID *theMG, INT FromLevel); |
| 251 |
|
| 252 |
PARAMETERS: |
| 253 |
. theMG |
| 254 |
. FromLevel |
| 255 |
|
| 256 |
DESCRIPTION: |
| 257 |
|
| 258 |
RETURN VALUE: |
| 259 |
INT |
| 260 |
*/ |
| 261 |
/****************************************************************************/ |
| 262 |
|
| 263 |
static INT UpdateMultiGridOverlap (MULTIGRID *theMG, INT FromLevel) |
| 264 |
{ |
| 265 |
ddd_HandlerInit(theMG->dddContext(), HSET_REFINE); |
| 266 |
|
| 267 |
for (INT l = FromLevel; l < TOPLEVEL(theMG); l++) |
| 268 |
{ |
| 269 |
GRID *theGrid = GRID_ON_LEVEL(theMG,l); |
| 270 |
UpdateGridOverlap(theGrid); |
| 271 |
} |
| 272 |
|
| 273 |
return(GM_OK); |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
/****************************************************************************/ |
| 278 |
/* |
| 279 |
DropUsedFlags - |
| 280 |
|
| 281 |
SYNOPSIS: |
| 282 |
static INT DropUsedFlags (GRID *theGrid); |
| 283 |
|
| 284 |
PARAMETERS: |
| 285 |
. theGrid |
| 286 |
|
| 287 |
DESCRIPTION: |
| 288 |
|
| 289 |
RETURN VALUE: |
| 290 |
INT |
| 291 |
*/ |
| 292 |
/****************************************************************************/ |
| 293 |
|
| 294 |
static INT DropUsedFlags (GRID *theGrid) |
| 295 |
{ |
| 296 |
ELEMENT *theElement; |
| 297 |
|
| 298 |
for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) |
| 299 |
{ |
| 300 |
if (USED(theElement) == 1) |
| 301 |
{ |
| 302 |
REFINE_ELEMENT_LIST(1,theElement,"drop mark"); |
| 303 |
|
| 304 |
ASSERT(EFATHER(theElement)!=NULL); |
| 305 |
|
| 306 |
/* this father has to be connected */ |
| 307 |
SETUSED(EFATHER(theElement),1); |
| 308 |
SETUSED(theElement,0); |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
return(GM_OK); |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
/****************************************************************************/ |
| 317 |
/* |
| 318 |
ConnectGridOverlap - |
| 319 |
|
| 320 |
SYNOPSIS: |
| 321 |
INT ConnectGridOverlap (GRID *theGrid); |
| 322 |
|
| 323 |
PARAMETERS: |
| 324 |
. theGrid |
| 325 |
|
| 326 |
DESCRIPTION: |
| 327 |
|
| 328 |
RETURN VALUE: |
| 329 |
INT |
| 330 |
*/ |
| 331 |
/****************************************************************************/ |
| 332 |
|
| 333 |
INT ConnectGridOverlap (GRID *theGrid) |
| 334 |
{ |
| 335 |
INT i,j,Sons_of_Side,prio; |
| 336 |
INT SonSides[MAX_SIDE_NODES]; |
| 337 |
ELEMENT *theElement; |
| 338 |
ELEMENT *theNeighbor; |
| 339 |
ELEMENT *theSon; |
| 340 |
ELEMENT *Sons_of_Side_List[MAX_SONS]; |
| 341 |
|
| 342 |
for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) |
| 343 |
{ |
| 344 |
prio = EPRIO(theElement); |
| 345 |
|
| 346 |
/* connect only FROM hgost copies */ |
| 347 |
if (!IS_REFINED(theElement) || !EHGHOSTPRIO(prio)) continue; |
| 348 |
|
| 349 |
PRINTDEBUG(gm,1,("Connecting e=%08x/%x ID=%d eLevel=%d\n", |
| 350 |
DDD_InfoGlobalId(PARHDRE(theElement)), |
| 351 |
theElement,ID(theElement), |
| 352 |
LEVEL(theElement))); |
| 353 |
|
| 354 |
for (i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 355 |
{ |
| 356 |
if (OBJT(theElement)==BEOBJ |
| 357 |
&& SIDE_ON_BND(theElement,i) |
| 358 |
&& !INNER_BOUNDARY(theElement,i)) continue; |
| 359 |
|
| 360 |
theNeighbor = NBELEM(theElement,i); |
| 361 |
if (theNeighbor == NULL) continue; |
| 362 |
|
| 363 |
prio = EPRIO(theNeighbor); |
| 364 |
/* overlap situation hasn't changed */ |
| 365 |
if (!THEFLAG(theElement) && !THEFLAG(theNeighbor)) continue; |
| 366 |
|
| 367 |
/* connect only TO master copies */ |
| 368 |
#ifdef UG_DIM_2 |
| 369 |
if (!IS_REFINED(theNeighbor) || !MASTERPRIO(prio)) continue; |
| 370 |
#endif |
| 371 |
#ifdef UG_DIM_3 |
| 372 |
if (!IS_REFINED(theNeighbor)) continue; |
| 373 |
#endif |
| 374 |
|
| 375 |
if (Get_Sons_of_ElementSide(theElement,i,&Sons_of_Side, |
| 376 |
Sons_of_Side_List,SonSides,1,0)!=GM_OK) RETURN(GM_FATAL); |
| 377 |
|
| 378 |
IFDEBUG(gm,1) |
| 379 |
UserWriteF(" side=%d NSONS=%d Sons_of_Side=%d:\n", |
| 380 |
i,NSONS(theElement),Sons_of_Side); |
| 381 |
for (j=0; j<Sons_of_Side; j++) |
| 382 |
UserWriteF(" son=%08x/%x sonside=%d\n", |
| 383 |
EGID(Sons_of_Side_List[j]), |
| 384 |
Sons_of_Side_List[j],SonSides[j]); |
| 385 |
printf(" connecting ghostelements:\n"); |
| 386 |
ENDDEBUG |
| 387 |
|
| 388 |
/* the ioflag=1 is needed, since not all sended ghosts are needed! */ |
| 389 |
if (Connect_Sons_of_ElementSide(theGrid,theElement,i, |
| 390 |
Sons_of_Side,Sons_of_Side_List,SonSides,1)!=GM_OK) |
| 391 |
RETURN(GM_FATAL); |
| 392 |
} |
| 393 |
|
| 394 |
/* 1. yellow_class specific code: */ |
| 395 |
/* check whether is a valid ghost, which as in minimum one */ |
| 396 |
/* master element as neighbor */ |
| 397 |
/* TODO: move this functionality to ComputeCopies */ |
| 398 |
/* then disposing of theSon can be done in AdaptGrid */ |
| 399 |
/* and the extra Xfer env around ConnectGridOverlap() */ |
| 400 |
/* can be deleted (s.l. 971029) */ |
| 401 |
|
| 402 |
/* 2. ghost-ghost neighborship specific code: */ |
| 403 |
/* reset in 3D all unsymmetric neighbor relationships */ |
| 404 |
/* to avoid referencing of zombie pointers. */ |
| 405 |
/* this happened e.g. in CorrectElementSidePattern() */ |
| 406 |
/* (s.l. 980223) */ |
| 407 |
{ |
| 408 |
ELEMENT *SonList[MAX_SONS]; |
| 409 |
|
| 410 |
GetAllSons(theElement,SonList); |
| 411 |
for (i=0; SonList[i]!=NULL; i++) |
| 412 |
{ |
| 413 |
INT ok = 0; |
| 414 |
theSon = SonList[i]; |
| 415 |
if (!EHGHOST(theSon)) continue; |
| 416 |
for (j=0; j<SIDES_OF_ELEM(theSon); j++) |
| 417 |
{ |
| 418 |
ELEMENT *NbSon = NBELEM(theSon,j); |
| 419 |
|
| 420 |
if (NbSon == NULL) continue; |
| 421 |
|
| 422 |
if (EMASTER(NbSon)) |
| 423 |
{ |
| 424 |
ok = 1; |
| 425 |
} |
| 426 |
/* reset unsymmetric pointer relation ship */ |
| 427 |
/* TODO: delete this is done in ElementObjMkCons() |
| 428 |
else |
| 429 |
{ |
| 430 |
INT k; |
| 431 |
for (k=0; k<SIDES_OF_ELEM(NbSon); k++) |
| 432 |
{ |
| 433 |
if (NBELEM(NbSon,k)==theSon) break; |
| 434 |
} |
| 435 |
if (k>=SIDES_OF_ELEM(NbSon)) SET_NBELEM(theSon,j,NULL); |
| 436 |
} |
| 437 |
*/ |
| 438 |
} |
| 439 |
if (!ok) |
| 440 |
{ |
| 441 |
if (ECLASS(theSon) == YELLOW_CLASS) |
| 442 |
{ |
| 443 |
UserWriteF("ConnectGridOverlap(): disposing useless yellow ghost e=" EID_FMTX |
| 444 |
"f=" EID_FMTX "this ghost is useless!\n", |
| 445 |
EID_PRTX(theSon),EID_PRTX(theElement)); |
| 446 |
DisposeElement(UPGRID(theGrid),theSon); |
| 447 |
} |
| 448 |
else |
| 449 |
{ |
| 450 |
UserWriteF("ConnectGridOverlap(): ERROR e=" EID_FMTX |
| 451 |
"f=" EID_FMTX "this ghost is useless!\n", |
| 452 |
EID_PRTX(theSon),EID_PRTX(theElement)); |
| 453 |
|
| 454 |
/* TODO: better do this |
| 455 |
assert(0); */ |
| 456 |
} |
| 457 |
} |
| 458 |
} |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
return(GM_OK); |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
/****************************************************************************/ |
| 468 |
/* |
| 469 |
ConnectMultiGridOverlap - |
| 470 |
|
| 471 |
SYNOPSIS: |
| 472 |
static INT ConnectMultiGridOverlap (MULTIGRID *theMG, INT FromLevel); |
| 473 |
|
| 474 |
PARAMETERS: |
| 475 |
. theMG |
| 476 |
. FromLevel |
| 477 |
|
| 478 |
DESCRIPTION: |
| 479 |
|
| 480 |
RETURN VALUE: |
| 481 |
INT |
| 482 |
*/ |
| 483 |
/****************************************************************************/ |
| 484 |
|
| 485 |
static INT ConnectMultiGridOverlap (MULTIGRID *theMG, INT FromLevel) |
| 486 |
{ |
| 487 |
INT l; |
| 488 |
GRID *theGrid; |
| 489 |
|
| 490 |
/* drop used marks to fathers */ |
| 491 |
for (l=FromLevel+1; l<=TOPLEVEL(theMG); l++) |
| 492 |
{ |
| 493 |
theGrid = GRID_ON_LEVEL(theMG,l); |
| 494 |
if (DropUsedFlags(theGrid)) RETURN(GM_FATAL); |
| 495 |
} |
| 496 |
|
| 497 |
/* connect sons of elements with used flag set */ |
| 498 |
for (l=FromLevel; l<TOPLEVEL(theMG); l++) |
| 499 |
{ |
| 500 |
|
| 501 |
theGrid = GRID_ON_LEVEL(theMG,l); |
| 502 |
if (ConnectGridOverlap(theGrid)) RETURN(GM_FATAL); |
| 503 |
} |
| 504 |
|
| 505 |
return(GM_OK); |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
/****************************************************************************/ |
| 510 |
/* |
| 511 |
ConnectVerticalOverlap - reconstruct fathers and sons of HGHOSTS |
| 512 |
|
| 513 |
SYNOPSIS: |
| 514 |
INT ConnectVerticalOverlap (MULTIGRID *theMG); |
| 515 |
|
| 516 |
PARAMETERS: |
| 517 |
. theMG - pointer to multigrid |
| 518 |
|
| 519 |
DESCRIPTION: |
| 520 |
IO and Loadbalancing to not consider father-son relations of HGHOSTS; |
| 521 |
here, this information is reconstructed. |
| 522 |
|
| 523 |
RETURN VALUE: |
| 524 |
INT |
| 525 |
|
| 526 |
GM_OK if ok. |
| 527 |
*/ |
| 528 |
/****************************************************************************/ |
| 529 |
|
| 530 |
static INT CompareSide (ELEMENT *theElement, INT s, ELEMENT *theFather, INT t) |
| 531 |
{ |
| 532 |
NODE *Nodes[MAX_SIDE_NODES]; |
| 533 |
INT n; |
| 534 |
INT m = CORNERS_OF_SIDE(theElement,s); |
| 535 |
INT k = 0; |
| 536 |
INT i,j; |
| 537 |
|
| 538 |
GetSonSideNodes(theFather,t,&n,Nodes,0); |
| 539 |
|
| 540 |
for (i=0; i<m; i++) |
| 541 |
{ |
| 542 |
NODE *theNode = CORNER(theElement,CORNER_OF_SIDE(theElement,s,i)); |
| 543 |
|
| 544 |
for (j=0; j<MAX_SIDE_NODES; j++) |
| 545 |
if (theNode == Nodes[j]) { |
| 546 |
k++; |
| 547 |
break; |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
return((k == m)); |
| 552 |
} |
| 553 |
|
| 554 |
INT ConnectVerticalOverlap (MULTIGRID *theMG) |
| 555 |
{ |
| 556 |
INT l; |
| 557 |
|
| 558 |
for (l=1; l<=TOPLEVEL(theMG); l++) |
| 559 |
{ |
| 560 |
GRID *theGrid = GRID_ON_LEVEL(theMG,l); |
| 561 |
ELEMENT *theElement; |
| 562 |
|
| 563 |
for (theElement=PFIRSTELEMENT(theGrid); |
| 564 |
theElement!=NULL; theElement=SUCCE(theElement)) |
| 565 |
{ |
| 566 |
INT prio = EPRIO(theElement); |
| 567 |
bool neflag = false; |
| 568 |
INT i; |
| 569 |
|
| 570 |
if (prio == PrioMaster) break; |
| 571 |
if (prio == PrioVGhost) continue; |
| 572 |
if (EFATHER(theElement) != NULL) continue; |
| 573 |
for (i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 574 |
{ |
| 575 |
ELEMENT *theNeighbor = NBELEM(theElement,i); |
| 576 |
|
| 577 |
if (theNeighbor == NULL) continue; |
| 578 |
if (EMASTER(theNeighbor)) |
| 579 |
{ |
| 580 |
ELEMENT *theFather = EFATHER(theNeighbor); |
| 581 |
INT j; |
| 582 |
|
| 583 |
ASSERT(theFather != NULL); |
| 584 |
for (j=0; j<SIDES_OF_ELEM(theFather); j++) |
| 585 |
{ |
| 586 |
ELEMENT *el = NBELEM(theFather,j); |
| 587 |
|
| 588 |
if (el == NULL) continue; |
| 589 |
if (EMASTER(el)) continue; |
| 590 |
if (EVGHOST(el)) continue; |
| 591 |
if (CompareSide(theElement,i,theFather,j)) |
| 592 |
{ |
| 593 |
INT where = PRIO2INDEX(EPRIO(theElement)); |
| 594 |
PRINTDEBUG(dddif,0,(PFMT " ConnectVerticalOverlap " |
| 595 |
" e=" EID_FMTX |
| 596 |
" n=" EID_FMTX |
| 597 |
" nf=" EID_FMTX |
| 598 |
" f=" EID_FMTX "\n", |
| 599 |
me, |
| 600 |
EID_PRTX(theElement), |
| 601 |
EID_PRTX(theNeighbor), |
| 602 |
EID_PRTX(theFather), |
| 603 |
EID_PRTX(el))); |
| 604 |
SET_EFATHER(theElement,el); |
| 605 |
if (NSONS(el) == 0) |
| 606 |
{ |
| 607 |
SET_SON(el,where,theElement); |
| 608 |
/* Father found, hence exit loop. Otherwise multiple fixes lead to element list inconsistency |
| 609 |
and endless element loop */ |
| 610 |
/* Achim 030506 */ |
| 611 |
neflag = true; |
| 612 |
break; |
| 613 |
} |
| 614 |
else |
| 615 |
{ |
| 616 |
ELEMENT *theSon = SON(el,where); |
| 617 |
|
| 618 |
assert(PRIO2INDEX(EPRIO(theSon)) == where); |
| 619 |
GRID_UNLINK_ELEMENT(theGrid,theElement); |
| 620 |
GRID_LINKX_ELEMENT(theGrid,theElement, |
| 621 |
EPRIO(theElement),theSon); |
| 622 |
/* Father found, hence exit loop. Otherwise multiple fixes lead to element list inconsistency |
| 623 |
and endless element loop */ |
| 624 |
/* Achim 030506 */ |
| 625 |
neflag = true; |
| 626 |
break; |
| 627 |
} |
| 628 |
SETNSONS(el,NSONS(el)+1); |
| 629 |
} |
| 630 |
} |
| 631 |
/* Father found, hence exit loop. Otherwise multiple fixes lead to element list inconsistency |
| 632 |
and endless element loop */ |
| 633 |
/* Achim 030506 */ |
| 634 |
if (neflag == true) |
| 635 |
break; |
| 636 |
} |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
return(GM_OK); |
| 642 |
} |
| 643 |
|
| 644 |
static INT ConnectOverlapVerticalGrid (GRID *theGrid) |
| 645 |
{ |
| 646 |
INT i,j,k,found,edgenode0,edgenode1; |
| 647 |
ELEMENT *theElement,*theSon,*SonList[MAX_SONS]; |
| 648 |
VERTEX *theVertex; |
| 649 |
DOUBLE diff; |
| 650 |
DOUBLE_VECTOR global; |
| 651 |
|
| 652 |
for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) |
| 653 |
{ |
| 654 |
/* reconstruct node relations using element relations */ |
| 655 |
if (GetAllSons(theElement,SonList) != GM_OK) REP_ERR_RETURN(1); |
| 656 |
for (i=0; SonList[i]!=NULL; i++) |
| 657 |
{ |
| 658 |
theSon = SonList[i]; |
| 659 |
for (j=0; j<CORNERS_OF_ELEM(theSon); j++) |
| 660 |
{ |
| 661 |
found = 0; |
| 662 |
NODE *SonNode = CORNER(theSon, j); |
| 663 |
switch(NTYPE(SonNode)) |
| 664 |
{ |
| 665 |
case CORNER_NODE : |
| 666 |
{ |
| 667 |
const NODE *FatherNode = (NODE *) NFATHER(SonNode); |
| 668 |
if (FatherNode != nullptr) |
| 669 |
{ |
| 670 |
assert(SONNODE(FatherNode) == SonNode); |
| 671 |
break; |
| 672 |
} |
| 673 |
assert(!MOVED(MYVERTEX(SonNode))); |
| 674 |
for (k=0; k<CORNERS_OF_ELEM(theElement); k++) |
| 675 |
{ |
| 676 |
NODE *theNode = CORNER(theElement,k); |
| 677 |
if (MYVERTEX(theNode) == MYVERTEX(SonNode)) |
| 678 |
{ |
| 679 |
assert(found == 0); |
| 680 |
assert (SONNODE(theNode)==NULL || |
| 681 |
SONNODE(theNode) == SonNode); |
| 682 |
printf("ConnectOverlapVerticalGrid(): new " |
| 683 |
" sonnode relation between theNode=" ID_FMTX |
| 684 |
" SonNode=" ID_FMTX "\n", |
| 685 |
ID_PRTX(theNode),ID_PRTX(SonNode)); |
| 686 |
SETNFATHER(SonNode,(GEOM_OBJECT *)theNode); |
| 687 |
SONNODE(theNode) = SonNode; |
| 688 |
found ++; |
| 689 |
} |
| 690 |
} |
| 691 |
break; |
| 692 |
} |
| 693 |
case MID_NODE : |
| 694 |
{ |
| 695 |
const EDGE *FatherEdge = (EDGE *) NFATHER(SonNode); |
| 696 |
if (FatherEdge != nullptr) |
| 697 |
{ |
| 698 |
assert(MIDNODE(FatherEdge) == SonNode); |
| 699 |
break; |
| 700 |
} |
| 701 |
assert(!MOVED(MYVERTEX(SonNode))); |
| 702 |
for (k=0; k<EDGES_OF_ELEM(theElement); k++) |
| 703 |
{ |
| 704 |
edgenode0 = CORNER_OF_EDGE(theElement,k,0); |
| 705 |
edgenode1 = CORNER_OF_EDGE(theElement,k,1); |
| 706 |
const NODE *EdgeNode0 = CORNER(theElement, edgenode0); |
| 707 |
const NODE *EdgeNode1 = CORNER(theElement, edgenode1); |
| 708 |
assert(EdgeNode0!=NULL && EdgeNode1!=NULL); |
| 709 |
|
| 710 |
EDGE *theEdge = GetEdge(EdgeNode0, EdgeNode1); |
| 711 |
assert(theEdge != nullptr); |
| 712 |
const FieldVector<DOUBLE,DIM>& songlobal = CVECT(MYVERTEX(SonNode)); |
| 713 |
V_DIM_LINCOMB(0.5, CVECT(MYVERTEX(EdgeNode0)), |
| 714 |
0.5, CVECT(MYVERTEX(EdgeNode1)),global); |
| 715 |
V_DIM_EUKLIDNORM_OF_DIFF(songlobal,global,diff); |
| 716 |
if (diff <= MAX_PAR_DIST) |
| 717 |
{ |
| 718 |
assert(found == 0); |
| 719 |
assert (MIDNODE(theEdge)==NULL || |
| 720 |
MIDNODE(theEdge) == SonNode); |
| 721 |
|
| 722 |
#ifdef UG_DIM_2 |
| 723 |
IFDEBUG(dddif,1) |
| 724 |
printf("ConnectOverlapVerticalGrid(): new " |
| 725 |
" midnode relation between theEdge=%p" |
| 726 |
" SonNode=" ID_FMTX "Vertex=" VID_FMTX "\n", |
| 727 |
(void*) theEdge,ID_PRTX(SonNode), |
| 728 |
VID_PRTX(MYVERTEX(SonNode))); |
| 729 |
ENDDEBUG |
| 730 |
#endif |
| 731 |
#ifdef UG_DIM_3 |
| 732 |
printf("ConnectOverlapVerticalGrid(): new " |
| 733 |
" midnode relation between theEdge=" ID_FMTX |
| 734 |
" SonNode=" ID_FMTX "\n", |
| 735 |
ID_PRTX(theEdge),ID_PRTX(SonNode)); |
| 736 |
#endif |
| 737 |
SETNFATHER(SonNode,(GEOM_OBJECT *)theEdge); |
| 738 |
MIDNODE(theEdge) = SonNode; |
| 739 |
found ++; |
| 740 |
|
| 741 |
/* reconstruct vertex information */ |
| 742 |
theVertex = MYVERTEX(SonNode); |
| 743 |
V_DIM_LINCOMB(0.5, LOCAL_COORD_OF_ELEM(theElement,edgenode0), |
| 744 |
0.5, LOCAL_COORD_OF_ELEM(theElement,edgenode1), |
| 745 |
LCVECT(theVertex)); |
| 746 |
SETONEDGE(theVertex,k); |
| 747 |
VFATHER(theVertex) = theElement; |
| 748 |
} |
| 749 |
} |
| 750 |
break; |
| 751 |
} |
| 752 |
case SIDE_NODE : |
| 753 |
case CENTER_NODE : |
| 754 |
/* do nothing */ |
| 755 |
break; |
| 756 |
default : |
| 757 |
assert(0); |
| 758 |
} |
| 759 |
} |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
return(GM_OK); |
| 764 |
} |
| 765 |
|
| 766 |
static INT ConnectOverlapVerticalMultiGrid (MULTIGRID *theMG) |
| 767 |
{ |
| 768 |
for (INT i = 0; i <= TOPLEVEL(theMG); i++) |
| 769 |
{ |
| 770 |
GRID *theGrid = GRID_ON_LEVEL(theMG,i); |
| 771 |
if (ConnectOverlapVerticalGrid(theGrid)) return(GM_ERROR); |
| 772 |
} |
| 773 |
return(GM_OK); |
| 774 |
} |
| 775 |
|
| 776 |
END_UGDIM_NAMESPACE |
| 777 |
|
| 778 |
#endif |