// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LGPL-2.1-or-later // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: /****************************************************************************/ /* */ /* File: gridcons.c */ /* */ /* Purpose: functions for managing consistency of distributed grids */ /* */ /* Author: Stefan Lang, Klaus Birken */ /* Institut fuer Computeranwendungen III */ /* Universitaet Stuttgart */ /* Pfaffenwaldring 27 */ /* 70550 Stuttgart */ /* */ /* History: 960906 kb begin */ /* */ /* Remarks: */ /* */ /****************************************************************************/ #ifdef ModelP /****************************************************************************/ /* */ /* include files */ /* system include files */ /* application include files */ /* */ /****************************************************************************/ #include #include #include "parallel.h" #include #include #include #include #include #include #include #include /* UG namespaces: */ USING_UG_NAMESPACES #ifdef Debug using namespace PPIF; #endif /****************************************************************************/ /* */ /* defines in the following order */ /* */ /* compile time constants defining static data size (i.e. arrays) */ /* other constants */ /* macros */ /* */ /****************************************************************************/ #ifdef DDD_PRIO_ENV #define DDD_XferBegin DDD_PrioBegin #define DDD_XferEnd DDD_PrioEnd #endif /****************************************************************************/ /* */ /* data structures used in this source file (exported data structures are */ /* in the corresponding include file!) */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* definition of exported global variables */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* forward declarations of functions used before they are defined */ /* */ /****************************************************************************/ /****************************************************************************/ /* ConstructConsistentGridLevel - SYNOPSIS: void ConstructConsistentGridLevel (GRID *theGrid); PARAMETERS: . theGrid DESCRIPTION: Provide a consistent grid level. Do not call for a single grid level, but always for the whole multigrid from bottom to top, since otherwise consistency is not ensured! RETURN VALUE: void */ /****************************************************************************/ static void ConstructConsistentGridLevel (GRID *theGrid) { INT j; EDGE *theEdge; /* this is the simplest fix for VFATHER zombies */ /* just reset all VFATHER pointers and set them */ /* only by master nodes of this or upper levels. */ /* A more complicated fix would be to set the */ /* priorities of the vertices correctly. */ /* (980126 s.l.) */ for (VERTEX* theVertex = PFIRSTVERTEX(theGrid); theVertex != NULL; theVertex = SUCCV(theVertex)) { VFATHER(theVertex) = NULL; /* if (VXGHOST(theVertex)) VFATHER(theVertex) = NULL; else if (OBJT(theVertex) == BVOBJ) if (MOVED(theVertex)) { INT n; DOUBLE *x[MAX_CORNERS_OF_ELEM]; ELEMENT* theElement = VFATHER(theVertex); if (theElement == NULL) continue; HEAPFAULT(theElement); CORNER_COORDINATES(theElement,n,x); UG_GlobalToLocal(n,(const DOUBLE **)x, CVECT(theVertex),LCVECT(theVertex)); } */ } /* reconstruct VFATHER pointers and */ /* make ghost neighborships symmetric (only for 3d)*/ /* * Also: If there are SideVectors, set the VCOUNT field correctly (i.e., the number * of elements that reference a given SideVector). This information has been transferred as-is * during load balancing, but may be wrong on new ghost elements. */ for (ELEMENT* theElement = PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { /* This is the SideVector part */ #ifdef UG_DIM_3 if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) for (INT i=0; i=SIDES_OF_ELEM(NbElement)) SET_NBELEM(theElement,i,NULL); } } #endif */ ELEMENT* theFather = EFATHER(theElement); /* no reconstruction of VFATHER possible */ if (theFather == NULL) continue; for (INT i=0; i=EDGES_OF_ELEM(theFather)) { for (j=0; jmidnode != NULL) PRINTDEBUG(dddif,1, (PFMT " ConstructConsistentGrid(): elem=" EID_FMTX " i=%d n1=" ID_FMTX " n2=" ID_FMTX " midnode= " ID_FMTX "\n", me,theFather,EID_PRTX(theFather),j, ID_PRTX(NBNODE(LINK0(theEdge))), ID_PRTX(NBNODE(LINK1(theEdge))), ID_PRTX(theEdge->midnode))) #endif } PRINTDEBUG(dddif,1, ("ConstructConsistentGrid(): WARN " " theNode= " ID_FMTX " vertex= " VID_FMTX " recalculation of VFATHER impossible\n", ID_PRTX(NBNODE(LINK0(theEdge))), VID_PRTX(theVertex))); /* if it couldn't be recalculated reset it */ VFATHER(theVertex) = NULL; break; } /* reconstruct local coordinates of vertex */ co0 = CORNER_OF_EDGE(theFather,j,0); co1 = CORNER_OF_EDGE(theFather,j,1); /* local coordinates have to be local towards pe */ V_DIM_LINCOMB(0.5, LOCAL_COORD_OF_ELEM(theFather,co0), 0.5, LOCAL_COORD_OF_ELEM(theFather,co1), LCVECT(theVertex)); SETONEDGE(theVertex,j); break; } #ifdef UG_DIM_3 case (SIDE_NODE) : { /* always compute new coords for this case! */ INT k; if (TAG(theFather) == PYRAMID) k=0; else k = GetSideIDFromScratch(theElement,theNode); ASSERT(k < SIDES_OF_ELEM(theFather)); SETONSIDE(theVertex,k); INT m = CORNERS_OF_SIDE(theFather,k); Dune::FieldVector& local = LCVECT(theVertex); DOUBLE fac = 1.0 / m; V_DIM_CLEAR(local); for (INT o=0; odddContext()); SetGhostObjectPriorities(theGrid); DDD_XferEnd(theGrid->dddContext()); DDD_XferBegin(theGrid->dddContext()); SetBorderPriorities(theGrid); DDD_XferEnd(theGrid->dddContext()); ConstructConsistentGridLevel(theGrid); } /****************************************************************************/ /* ConstructConsistentMultiGrid - SYNOPSIS: void ConstructConsistentMultiGrid (MULTIGRID *theMG); PARAMETERS: . theMG DESCRIPTION: Provide a consistent multigrid. RETURN VALUE: void */ /****************************************************************************/ void NS_DIM_PREFIX ConstructConsistentMultiGrid (MULTIGRID *theMG) { INT l; /* this is done in three waves: */ /* 1. set priorities of objects */ /* 2. set border priorities */ /* 3. repair grid inconsistencies */ /* 1. set priorities of objects */ DDD_XferBegin(theMG->dddContext()); for (l=0; l<=TOPLEVEL(theMG); l++) { GRID *theGrid = GRID_ON_LEVEL(theMG,l); SetGhostObjectPriorities(theGrid); } DDD_XferEnd(theMG->dddContext()); /* 2. set border priorities */ DDD_XferBegin(theMG->dddContext()); for (l=0; l<=TOPLEVEL(theMG); l++) { GRID *theGrid = GRID_ON_LEVEL(theMG,l); SetBorderPriorities(theGrid); } DDD_XferEnd(theMG->dddContext()); /* 3. repair grid inconsistencies */ for (l=0; l<=TOPLEVEL(theMG); l++) { GRID *theGrid = GRID_ON_LEVEL(theMG,l); ConstructConsistentGridLevel(theGrid); } } #endif