| 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: gridcons.c */ |
| 8 |
/* */ |
| 9 |
/* Purpose: functions for managing consistency of distributed grids */ |
| 10 |
/* */ |
| 11 |
/* Author: Stefan Lang, Klaus Birken */ |
| 12 |
/* Institut fuer Computeranwendungen III */ |
| 13 |
/* Universitaet Stuttgart */ |
| 14 |
/* Pfaffenwaldring 27 */ |
| 15 |
/* 70550 Stuttgart */ |
| 16 |
/* */ |
| 17 |
/* History: 960906 kb begin */ |
| 18 |
/* */ |
| 19 |
/* Remarks: */ |
| 20 |
/* */ |
| 21 |
/****************************************************************************/ |
| 22 |
|
| 23 |
#ifdef ModelP |
| 24 |
|
| 25 |
/****************************************************************************/ |
| 26 |
/* */ |
| 27 |
/* include files */ |
| 28 |
/* system include files */ |
| 29 |
/* application include files */ |
| 30 |
/* */ |
| 31 |
/****************************************************************************/ |
| 32 |
|
| 33 |
#include <config.h> |
| 34 |
#include <cstdlib> |
| 35 |
|
| 36 |
#include "parallel.h" |
| 37 |
#include <dune/uggrid/low/debug.h> |
| 38 |
#include <dune/uggrid/low/namespace.h> |
| 39 |
#include <dune/uggrid/gm/evm.h> |
| 40 |
#include <dune/uggrid/gm/gm.h> |
| 41 |
#include <dune/uggrid/gm/refine.h> |
| 42 |
#include <dune/uggrid/gm/shapes.h> |
| 43 |
#include <dune/uggrid/gm/ugm.h> |
| 44 |
#include <dune/uggrid/ugdevices.h> |
| 45 |
|
| 46 |
/* UG namespaces: */ |
| 47 |
USING_UG_NAMESPACES |
| 48 |
#ifdef Debug |
| 49 |
using namespace PPIF; |
| 50 |
#endif |
| 51 |
|
| 52 |
/****************************************************************************/ |
| 53 |
/* */ |
| 54 |
/* defines in the following order */ |
| 55 |
/* */ |
| 56 |
/* compile time constants defining static data size (i.e. arrays) */ |
| 57 |
/* other constants */ |
| 58 |
/* macros */ |
| 59 |
/* */ |
| 60 |
/****************************************************************************/ |
| 61 |
|
| 62 |
#ifdef DDD_PRIO_ENV |
| 63 |
#define DDD_XferBegin DDD_PrioBegin |
| 64 |
#define DDD_XferEnd DDD_PrioEnd |
| 65 |
#endif |
| 66 |
|
| 67 |
|
| 68 |
/****************************************************************************/ |
| 69 |
/* */ |
| 70 |
/* data structures used in this source file (exported data structures are */ |
| 71 |
/* in the corresponding include file!) */ |
| 72 |
/* */ |
| 73 |
/****************************************************************************/ |
| 74 |
|
| 75 |
|
| 76 |
/****************************************************************************/ |
| 77 |
/* */ |
| 78 |
/* definition of exported global variables */ |
| 79 |
/* */ |
| 80 |
/****************************************************************************/ |
| 81 |
|
| 82 |
|
| 83 |
/****************************************************************************/ |
| 84 |
/* */ |
| 85 |
/* forward declarations of functions used before they are defined */ |
| 86 |
/* */ |
| 87 |
/****************************************************************************/ |
| 88 |
|
| 89 |
|
| 90 |
/****************************************************************************/ |
| 91 |
/* |
| 92 |
ConstructConsistentGridLevel - |
| 93 |
|
| 94 |
SYNOPSIS: |
| 95 |
void ConstructConsistentGridLevel (GRID *theGrid); |
| 96 |
|
| 97 |
PARAMETERS: |
| 98 |
. theGrid |
| 99 |
|
| 100 |
DESCRIPTION: |
| 101 |
Provide a consistent grid level. Do not call for a single grid level, but |
| 102 |
always for the whole multigrid from bottom to top, since otherwise |
| 103 |
consistency is not ensured! |
| 104 |
|
| 105 |
RETURN VALUE: |
| 106 |
void |
| 107 |
*/ |
| 108 |
/****************************************************************************/ |
| 109 |
|
| 110 |
static void ConstructConsistentGridLevel (GRID *theGrid) |
| 111 |
{ |
| 112 |
INT j; |
| 113 |
EDGE *theEdge; |
| 114 |
|
| 115 |
/* this is the simplest fix for VFATHER zombies */ |
| 116 |
/* just reset all VFATHER pointers and set them */ |
| 117 |
/* only by master nodes of this or upper levels. */ |
| 118 |
/* A more complicated fix would be to set the */ |
| 119 |
/* priorities of the vertices correctly. */ |
| 120 |
/* (980126 s.l.) */ |
| 121 |
for (VERTEX* theVertex = PFIRSTVERTEX(theGrid); theVertex != NULL; |
| 122 |
theVertex = SUCCV(theVertex)) { |
| 123 |
VFATHER(theVertex) = NULL; |
| 124 |
/* |
| 125 |
if (VXGHOST(theVertex)) |
| 126 |
VFATHER(theVertex) = NULL; |
| 127 |
else if (OBJT(theVertex) == BVOBJ) |
| 128 |
if (MOVED(theVertex)) |
| 129 |
{ |
| 130 |
INT n; |
| 131 |
DOUBLE *x[MAX_CORNERS_OF_ELEM]; |
| 132 |
|
| 133 |
ELEMENT* theElement = VFATHER(theVertex); |
| 134 |
if (theElement == NULL) continue; |
| 135 |
HEAPFAULT(theElement); |
| 136 |
CORNER_COORDINATES(theElement,n,x); |
| 137 |
UG_GlobalToLocal(n,(const DOUBLE **)x, |
| 138 |
CVECT(theVertex),LCVECT(theVertex)); |
| 139 |
} |
| 140 |
*/ |
| 141 |
} |
| 142 |
|
| 143 |
/* reconstruct VFATHER pointers and */ |
| 144 |
/* make ghost neighborships symmetric (only for 3d)*/ |
| 145 |
/* |
| 146 |
* Also: If there are SideVectors, set the VCOUNT field correctly (i.e., the number |
| 147 |
* of elements that reference a given SideVector). This information has been transferred as-is |
| 148 |
* during load balancing, but may be wrong on new ghost elements. |
| 149 |
*/ |
| 150 |
for (ELEMENT* theElement = PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) |
| 151 |
{ |
| 152 |
/* This is the SideVector part */ |
| 153 |
#ifdef UG_DIM_3 |
| 154 |
if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) |
| 155 |
for (INT i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 156 |
SETVCOUNT(SVECTOR(theElement,i), (NBELEM(theElement,i) ? 2 : 1)); |
| 157 |
#endif |
| 158 |
|
| 159 |
/* Here comes the rest, all the way to the end of the element loop */ |
| 160 |
|
| 161 |
/* TODO: delete now done in ElementObjMkCons() |
| 162 |
#ifdef UG_DIM_3 |
| 163 |
if (EVGHOST(theElement)) |
| 164 |
{ |
| 165 |
ELEMENT *NbElement; |
| 166 |
|
| 167 |
for (INT i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 168 |
{ |
| 169 |
NbElement = NBELEM(theElement,i); |
| 170 |
for (j=0; j<SIDES_OF_ELEM(NbElement); j++) |
| 171 |
{ |
| 172 |
if (NBELEM(NbElement,j) == theElement) break; |
| 173 |
} |
| 174 |
if (j>=SIDES_OF_ELEM(NbElement)) |
| 175 |
SET_NBELEM(theElement,i,NULL); |
| 176 |
} |
| 177 |
} |
| 178 |
#endif |
| 179 |
*/ |
| 180 |
|
| 181 |
ELEMENT* theFather = EFATHER(theElement); |
| 182 |
|
| 183 |
/* no reconstruction of VFATHER possible */ |
| 184 |
if (theFather == NULL) continue; |
| 185 |
|
| 186 |
for (INT i=0; i<CORNERS_OF_ELEM(theElement); i++) |
| 187 |
{ |
| 188 |
NODE* theNode = CORNER(theElement,i); |
| 189 |
if (CORNERTYPE(theNode)) continue; |
| 190 |
|
| 191 |
VERTEX* theVertex = MYVERTEX(theNode); |
| 192 |
|
| 193 |
/* this is too few for arbitrary load balancing, since |
| 194 |
VFATHER pointer may have changed (970828 s.l.) |
| 195 |
if (VFATHER(theVertex)==NULL || EPRIO(VFATHER(theVertex))==PrioHGhost) |
| 196 |
*/ |
| 197 |
/* this is too few for arbitrary load balancing, since |
| 198 |
VFATHER pointer may be already a zombie pointer (980126 s.l.) |
| 199 |
if (VFATHER(theVertex)==NULL || EPRIO(theFather)!=PrioHGhost) |
| 200 |
*/ |
| 201 |
{ |
| 202 |
switch (NTYPE(theNode)) |
| 203 |
{ |
| 204 |
case (MID_NODE) : |
| 205 |
{ |
| 206 |
INT co0,co1; |
| 207 |
|
| 208 |
for (j=0; j<EDGES_OF_ELEM(theFather); j++) |
| 209 |
{ |
| 210 |
theEdge = GetEdge(CORNER(theFather,CORNER_OF_EDGE(theFather,j,0)), |
| 211 |
CORNER(theFather,CORNER_OF_EDGE(theFather,j,1))); |
| 212 |
if (MIDNODE(theEdge) == theNode) break; |
| 213 |
} |
| 214 |
/* here should be an assertion, but not in each situation the |
| 215 |
midnode pointer is set (970829 s.l.) |
| 216 |
ASSERT(j<EDGES_OF_ELEM(theFather)); |
| 217 |
*/ |
| 218 |
if (j>=EDGES_OF_ELEM(theFather)) |
| 219 |
{ |
| 220 |
for (j=0; j<EDGES_OF_ELEM(theFather); j++) |
| 221 |
{ |
| 222 |
theEdge = GetEdge(CORNER(theFather,CORNER_OF_EDGE(theFather,j,0)), |
| 223 |
CORNER(theFather,CORNER_OF_EDGE(theFather,j,1))); |
| 224 |
#ifdef Debug |
| 225 |
if (theEdge->midnode != NULL) |
| 226 |
PRINTDEBUG(dddif,1, |
| 227 |
(PFMT " ConstructConsistentGrid(): elem=" EID_FMTX |
| 228 |
" i=%d n1=" ID_FMTX " n2=" ID_FMTX " midnode= " ID_FMTX "\n", |
| 229 |
me,theFather,EID_PRTX(theFather),j, |
| 230 |
ID_PRTX(NBNODE(LINK0(theEdge))), |
| 231 |
ID_PRTX(NBNODE(LINK1(theEdge))), |
| 232 |
ID_PRTX(theEdge->midnode))) |
| 233 |
#endif |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
PRINTDEBUG(dddif,1, |
| 239 |
("ConstructConsistentGrid(): WARN " |
| 240 |
" theNode= " ID_FMTX |
| 241 |
" vertex= " VID_FMTX |
| 242 |
" recalculation of VFATHER impossible\n", |
| 243 |
ID_PRTX(NBNODE(LINK0(theEdge))), |
| 244 |
VID_PRTX(theVertex))); |
| 245 |
/* if it couldn't be recalculated reset it */ |
| 246 |
VFATHER(theVertex) = NULL; |
| 247 |
break; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
/* reconstruct local coordinates of vertex */ |
| 252 |
co0 = CORNER_OF_EDGE(theFather,j,0); |
| 253 |
co1 = CORNER_OF_EDGE(theFather,j,1); |
| 254 |
|
| 255 |
/* local coordinates have to be local towards pe */ |
| 256 |
|
| 257 |
|
| 258 |
V_DIM_LINCOMB(0.5, LOCAL_COORD_OF_ELEM(theFather,co0), |
| 259 |
0.5, LOCAL_COORD_OF_ELEM(theFather,co1), |
| 260 |
LCVECT(theVertex)); |
| 261 |
SETONEDGE(theVertex,j); |
| 262 |
|
| 263 |
break; |
| 264 |
} |
| 265 |
|
| 266 |
#ifdef UG_DIM_3 |
| 267 |
case (SIDE_NODE) : |
| 268 |
{ |
| 269 |
/* always compute new coords for this case! */ |
| 270 |
INT k; |
| 271 |
if (TAG(theFather) == PYRAMID) k=0; |
| 272 |
else |
| 273 |
k = GetSideIDFromScratch(theElement,theNode); |
| 274 |
ASSERT(k < SIDES_OF_ELEM(theFather)); |
| 275 |
|
| 276 |
SETONSIDE(theVertex,k); |
| 277 |
|
| 278 |
INT m = CORNERS_OF_SIDE(theFather,k); |
| 279 |
Dune::FieldVector<DOUBLE,DIM>& local = LCVECT(theVertex); |
| 280 |
DOUBLE fac = 1.0 / m; |
| 281 |
V_DIM_CLEAR(local); |
| 282 |
for (INT o=0; o<m; o++) |
| 283 |
{ |
| 284 |
INT l = CORNER_OF_SIDE(theFather,k,o); |
| 285 |
V_DIM_LINCOMB(1.0,local,1.0, |
| 286 |
LOCAL_COORD_OF_ELEM(theFather,l),local); |
| 287 |
} |
| 288 |
V_DIM_SCALE(fac,local); |
| 289 |
|
| 290 |
ELEMENT* theNb = NBELEM(theFather,k); |
| 291 |
if (theNb != NULL) |
| 292 |
{ |
| 293 |
for (j=0; j<SIDES_OF_ELEM(theNb); j++) |
| 294 |
{ |
| 295 |
if (NBELEM(theNb,j) == theFather) break; |
| 296 |
} |
| 297 |
ASSERT(j < SIDES_OF_ELEM(theNb)); |
| 298 |
SETONNBSIDE(theVertex,j); |
| 299 |
} |
| 300 |
else SETONNBSIDE(theVertex,MAX_SIDES_OF_ELEM); |
| 301 |
break; |
| 302 |
} |
| 303 |
#endif |
| 304 |
case (CENTER_NODE) : |
| 305 |
case (LEVEL_0_NODE) : |
| 306 |
/* nothing to do */ |
| 307 |
break; |
| 308 |
|
| 309 |
case (CORNER_NODE) : |
| 310 |
default : |
| 311 |
assert(0); |
| 312 |
break; |
| 313 |
} |
| 314 |
|
| 315 |
VFATHER(theVertex) = theFather; |
| 316 |
|
| 317 |
if (OBJT(theVertex) == BVOBJ) |
| 318 |
if (MOVED(theVertex)) { |
| 319 |
INT n; |
| 320 |
DOUBLE *x[MAX_CORNERS_OF_ELEM]; |
| 321 |
|
| 322 |
CORNER_COORDINATES(theFather,n,x); |
| 323 |
UG_GlobalToLocal(n,(const DOUBLE **)x, |
| 324 |
CVECT(theVertex),LCVECT(theVertex)); |
| 325 |
} |
| 326 |
} |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
/****************************************************************************/ |
| 332 |
/* |
| 333 |
ConstructConsistentGrid - |
| 334 |
|
| 335 |
SYNOPSIS: |
| 336 |
void ConstructConsistentGrid (GRID *theGrid); |
| 337 |
|
| 338 |
PARAMETERS: |
| 339 |
. theGrid |
| 340 |
|
| 341 |
DESCRIPTION: |
| 342 |
Provide a consistent grid level. Do not call for a single grid level, but |
| 343 |
always for the whole multigrid from bottom to top, since otherwise |
| 344 |
consistency is not ensured! |
| 345 |
|
| 346 |
RETURN VALUE: |
| 347 |
void |
| 348 |
*/ |
| 349 |
/****************************************************************************/ |
| 350 |
|
| 351 |
void NS_DIM_PREFIX ConstructConsistentGrid (GRID *theGrid) |
| 352 |
{ |
| 353 |
/* the setting of the priorities has to be done in two waves after */ |
| 354 |
/* completion of the grid transfer, since */ |
| 355 |
/* - decisions about vghost prio can only be done if all sons are */ |
| 356 |
/* available in SetGhostObjectPriorities() */ |
| 357 |
/* - setting of the border priorities can only be done if all */ |
| 358 |
/* ghost objects have their proper priority */ |
| 359 |
|
| 360 |
DDD_XferBegin(theGrid->dddContext()); |
| 361 |
SetGhostObjectPriorities(theGrid); |
| 362 |
DDD_XferEnd(theGrid->dddContext()); |
| 363 |
|
| 364 |
DDD_XferBegin(theGrid->dddContext()); |
| 365 |
SetBorderPriorities(theGrid); |
| 366 |
DDD_XferEnd(theGrid->dddContext()); |
| 367 |
|
| 368 |
ConstructConsistentGridLevel(theGrid); |
| 369 |
} |
| 370 |
|
| 371 |
/****************************************************************************/ |
| 372 |
/* |
| 373 |
ConstructConsistentMultiGrid - |
| 374 |
|
| 375 |
SYNOPSIS: |
| 376 |
void ConstructConsistentMultiGrid (MULTIGRID *theMG); |
| 377 |
|
| 378 |
PARAMETERS: |
| 379 |
. theMG |
| 380 |
|
| 381 |
DESCRIPTION: |
| 382 |
Provide a consistent multigrid. |
| 383 |
|
| 384 |
RETURN VALUE: |
| 385 |
void |
| 386 |
*/ |
| 387 |
/****************************************************************************/ |
| 388 |
|
| 389 |
void NS_DIM_PREFIX ConstructConsistentMultiGrid (MULTIGRID *theMG) |
| 390 |
{ |
| 391 |
INT l; |
| 392 |
|
| 393 |
/* this is done in three waves: */ |
| 394 |
/* 1. set priorities of objects */ |
| 395 |
/* 2. set border priorities */ |
| 396 |
/* 3. repair grid inconsistencies */ |
| 397 |
|
| 398 |
/* 1. set priorities of objects */ |
| 399 |
DDD_XferBegin(theMG->dddContext()); |
| 400 |
for (l=0; l<=TOPLEVEL(theMG); l++) |
| 401 |
{ |
| 402 |
GRID *theGrid = GRID_ON_LEVEL(theMG,l); |
| 403 |
SetGhostObjectPriorities(theGrid); |
| 404 |
} |
| 405 |
DDD_XferEnd(theMG->dddContext()); |
| 406 |
|
| 407 |
/* 2. set border priorities */ |
| 408 |
DDD_XferBegin(theMG->dddContext()); |
| 409 |
for (l=0; l<=TOPLEVEL(theMG); l++) |
| 410 |
{ |
| 411 |
GRID *theGrid = GRID_ON_LEVEL(theMG,l); |
| 412 |
SetBorderPriorities(theGrid); |
| 413 |
} |
| 414 |
DDD_XferEnd(theMG->dddContext()); |
| 415 |
|
| 416 |
/* 3. repair grid inconsistencies */ |
| 417 |
for (l=0; l<=TOPLEVEL(theMG); l++) |
| 418 |
{ |
| 419 |
GRID *theGrid = GRID_ON_LEVEL(theMG,l); |
| 420 |
ConstructConsistentGridLevel(theGrid); |
| 421 |
} |
| 422 |
|
| 423 |
} |
| 424 |
|
| 425 |
#endif |