// 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: overlap.c */ /* */ /* Purpose: management of grid overlap during adaption */ /* */ /* Author: Stefan Lang */ /* Institut fuer Computeranwendungen III */ /* Universitaet Stuttgart */ /* Pfaffenwaldring 27 */ /* 70569 Stuttgart */ /* */ /* History: 970204 sl begin */ /* */ /****************************************************************************/ #ifdef ModelP /****************************************************************************/ /* */ /* include files */ /* system include files */ /* application include files */ /* */ /****************************************************************************/ /* standard C library */ #include #include #include #include #include #include /* low module */ #include #include #include #include #include /* dev module */ #include /* gm module */ #include #include #include #include #include #include #include /* parallel modules */ #include #include #include "identify.h" #include "parallel.h" /* UG namespaces: */ USING_UG_NAMESPACES /* PPIF namespace: */ using namespace PPIF; START_UGDIM_NAMESPACE /****************************************************************************/ /* */ /* defines in the following order */ /* */ /* compile time constants defining static data size (i.e. arrays) */ /* other constants */ /* macros */ /* */ /****************************************************************************/ /* undefine if overlap should be only updated where needed */ /* This does not work since the connection of the overlap needs the fatherelements on both sides (ghost and master sons) and this is not ensured. #define UPDATE_FULLOVERLAP */ /****************************************************************************/ /* */ /* data structures used in this source file (exported data structures are */ /* in the corresponding include file!) */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* definition of exported global variables */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* definition of variables global to this source file only (static!) */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* forward declarations of functions used before they are defined */ /* */ /****************************************************************************/ /****************************************************************************/ /* UpdateElementOverlap - SYNOPSIS: static INT UpdateElementOverlap (ELEMENT *theElement); PARAMETERS: . theElement DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT UpdateElementOverlap (DDD::DDDContext& context, ELEMENT *theElement) { INT i,s,prio; INT SonsOfSide,SonSides[MAX_SONS]; ELEMENT *theNeighbor,*theSon; ELEMENT *SonList[MAX_SONS]; /* yellow_class specific code: */ /* update need to be done for all elements with THEFLAG set, */ /* execpt for yellow copies, since their neighbor need not be */ /* refined (s.l. 971029) */ #ifndef UPDATE_FULLOVERLAP if (!THEFLAG(theElement) && REFINECLASS(theElement)!=YELLOW_CLASS) return(GM_OK); #endif /* if (!THEFLAG(theElement)) return(GM_OK); */ for (i=0; i=context.procs()) break; XFERECOPYX(context, theSon,EPROCPRIO(context, theNeighbor,PrioMaster),PrioHGhost, (OBJT(theSon)==BEOBJ) ? BND_SIZE_TAG(TAG(theSon)) : INNER_SIZE_TAG(TAG(theSon))); /* send son to all elements where theNeighbor is master, vghost or vhghost */ if (0) { for (auto&& [proc, currentPrio] : DDD_InfoProcListRange(context, PARHDRE(theNeighbor), false)) { if (!EHGHOSTPRIO(currentPrio)) { XFERECOPYX(context, theSon,proc,PrioHGhost, (OBJT(theSon)==BEOBJ) ? BND_SIZE_TAG(TAG(theSon)) : INNER_SIZE_TAG(TAG(theSon))); } } } } } return(GM_OK); } /****************************************************************************/ /* UpdateGridOverlap - SYNOPSIS: INT UpdateGridOverlap (GRID *theGrid); PARAMETERS: . theGrid DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ INT UpdateGridOverlap (GRID *theGrid) { DDD::DDDContext& context = theGrid->dddContext(); ELEMENT *theElement; for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (IS_REFINED(theElement)) UpdateElementOverlap(context, theElement); } return(GM_OK); } /****************************************************************************/ /* UpdateMultiGridOverlap - SYNOPSIS: static INT UpdateMultiGridOverlap (MULTIGRID *theMG, INT FromLevel); PARAMETERS: . theMG . FromLevel DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT UpdateMultiGridOverlap (MULTIGRID *theMG, INT FromLevel) { ddd_HandlerInit(theMG->dddContext(), HSET_REFINE); for (INT l = FromLevel; l < TOPLEVEL(theMG); l++) { GRID *theGrid = GRID_ON_LEVEL(theMG,l); UpdateGridOverlap(theGrid); } return(GM_OK); } /****************************************************************************/ /* DropUsedFlags - SYNOPSIS: static INT DropUsedFlags (GRID *theGrid); PARAMETERS: . theGrid DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT DropUsedFlags (GRID *theGrid) { ELEMENT *theElement; for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (USED(theElement) == 1) { REFINE_ELEMENT_LIST(1,theElement,"drop mark"); ASSERT(EFATHER(theElement)!=NULL); /* this father has to be connected */ SETUSED(EFATHER(theElement),1); SETUSED(theElement,0); } } return(GM_OK); } /****************************************************************************/ /* ConnectGridOverlap - SYNOPSIS: INT ConnectGridOverlap (GRID *theGrid); PARAMETERS: . theGrid DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ INT ConnectGridOverlap (GRID *theGrid) { INT i,j,Sons_of_Side,prio; INT SonSides[MAX_SIDE_NODES]; ELEMENT *theElement; ELEMENT *theNeighbor; ELEMENT *theSon; ELEMENT *Sons_of_Side_List[MAX_SONS]; for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { prio = EPRIO(theElement); /* connect only FROM hgost copies */ if (!IS_REFINED(theElement) || !EHGHOSTPRIO(prio)) continue; PRINTDEBUG(gm,1,("Connecting e=%08x/%x ID=%d eLevel=%d\n", DDD_InfoGlobalId(PARHDRE(theElement)), theElement,ID(theElement), LEVEL(theElement))); for (i=0; i=SIDES_OF_ELEM(NbSon)) SET_NBELEM(theSon,j,NULL); } */ } if (!ok) { if (ECLASS(theSon) == YELLOW_CLASS) { UserWriteF("ConnectGridOverlap(): disposing useless yellow ghost e=" EID_FMTX "f=" EID_FMTX "this ghost is useless!\n", EID_PRTX(theSon),EID_PRTX(theElement)); DisposeElement(UPGRID(theGrid),theSon); } else { UserWriteF("ConnectGridOverlap(): ERROR e=" EID_FMTX "f=" EID_FMTX "this ghost is useless!\n", EID_PRTX(theSon),EID_PRTX(theElement)); /* TODO: better do this assert(0); */ } } } } } return(GM_OK); } /****************************************************************************/ /* ConnectMultiGridOverlap - SYNOPSIS: static INT ConnectMultiGridOverlap (MULTIGRID *theMG, INT FromLevel); PARAMETERS: . theMG . FromLevel DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT ConnectMultiGridOverlap (MULTIGRID *theMG, INT FromLevel) { INT l; GRID *theGrid; /* drop used marks to fathers */ for (l=FromLevel+1; l<=TOPLEVEL(theMG); l++) { theGrid = GRID_ON_LEVEL(theMG,l); if (DropUsedFlags(theGrid)) RETURN(GM_FATAL); } /* connect sons of elements with used flag set */ for (l=FromLevel; l& songlobal = CVECT(MYVERTEX(SonNode)); V_DIM_LINCOMB(0.5, CVECT(MYVERTEX(EdgeNode0)), 0.5, CVECT(MYVERTEX(EdgeNode1)),global); V_DIM_EUKLIDNORM_OF_DIFF(songlobal,global,diff); if (diff <= MAX_PAR_DIST) { assert(found == 0); assert (MIDNODE(theEdge)==NULL || MIDNODE(theEdge) == SonNode); #ifdef UG_DIM_2 IFDEBUG(dddif,1) printf("ConnectOverlapVerticalGrid(): new " " midnode relation between theEdge=%p" " SonNode=" ID_FMTX "Vertex=" VID_FMTX "\n", (void*) theEdge,ID_PRTX(SonNode), VID_PRTX(MYVERTEX(SonNode))); ENDDEBUG #endif #ifdef UG_DIM_3 printf("ConnectOverlapVerticalGrid(): new " " midnode relation between theEdge=" ID_FMTX " SonNode=" ID_FMTX "\n", ID_PRTX(theEdge),ID_PRTX(SonNode)); #endif SETNFATHER(SonNode,(GEOM_OBJECT *)theEdge); MIDNODE(theEdge) = SonNode; found ++; /* reconstruct vertex information */ theVertex = MYVERTEX(SonNode); V_DIM_LINCOMB(0.5, LOCAL_COORD_OF_ELEM(theElement,edgenode0), 0.5, LOCAL_COORD_OF_ELEM(theElement,edgenode1), LCVECT(theVertex)); SETONEDGE(theVertex,k); VFATHER(theVertex) = theElement; } } break; } case SIDE_NODE : case CENTER_NODE : /* do nothing */ break; default : assert(0); } } } } return(GM_OK); } static INT ConnectOverlapVerticalMultiGrid (MULTIGRID *theMG) { for (INT i = 0; i <= TOPLEVEL(theMG); i++) { GRID *theGrid = GRID_ON_LEVEL(theMG,i); if (ConnectOverlapVerticalGrid(theGrid)) return(GM_ERROR); } return(GM_OK); } END_UGDIM_NAMESPACE #endif