// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LGPL-2.1-or-later /****************************************************************************/ /* */ /* File: refine.c */ /* */ /* Purpose: unstructured grid adaption using a general element concept */ /* (dimension independent for 2/3D) */ /* */ /* Author: Stefan Lang */ /* Institut fuer Computeranwendungen III */ /* Universitaet Stuttgart */ /* Pfaffenwaldring 27 */ /* 70569 Stuttgart */ /* email: ug@ica3.uni-stuttgart.de */ /* */ /* History: 08.08.95 begin serial algorithm, ug version 3.0 */ /* */ /* Remarks: - level 0 grid consists of red elements only */ /* - the only restriction in the element hierarchy is that */ /* green or yellow elements might not have sons of class */ /* green or red */ /* - the rule set for refinement consists of regular (red) */ /* and irregular rules; regular rules create red elements */ /* while irregular rules result in green elements */ /* (green elements are needed for the closure of the grid, */ /* yellow elements, which are from copy rules, save */ /* the numerical properties of the solver and are handsome for */ /* the discretisation */ /* - if the rule set for the red rules is not complete for build-*/ /* up a consistent red refined region the FIFO might be used */ /* for some (hopefully not too much) iterations to find a */ /* consistent one */ /* - in 2D: exists a complete rule set for grids of triangles */ /* and quadrilaterals exclusively */ /* - in 3D: exists a complete rule set for tetrahedrons */ /* and we assume after some analysation a complete set */ /* of rules described by an algorithm for hexahedrons */ /* - for mixed element types in arbitrary dimension no */ /* rule set for the closure exists */ /* - BEFORE refinement we assume a situation where the error */ /* estimator has detected and marked the leaf elements for */ /* further refinement */ /* - AFTER refinement all elements are refined by a rule in way */ /* that no hanging nodes remain (this is the default mode) */ /* or with hanging nodes (in the hanging node mode) */ /* if you use inconsistent red refinement, you need to tell */ /* the algorithm explicitly to use the FIFO */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* include files */ /* system include files */ /* application include files */ /* */ /****************************************************************************/ /* standard C library */ #include #include #include #include #include #include #include #include #include /* low module */ #include #include #include #include /* dev module */ #include /* gm module */ #include "algebra.h" #include "evm.h" #include "gm.h" #include "cw.h" #include "refine.h" #include "elements.h" #include "rm.h" #include "ugm.h" /* parallel modules */ #ifdef ModelP #include #include #include #include #include #include "pargm.h" #endif #ifdef Debug #include #endif #include USING_UG_NAMESPACES using namespace PPIF; /****************************************************************************/ /* */ /* 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 */ /* define for use of DDD_ConsCheck() */ /* #define DDD_CONSCHECK(context) if (DDD_ConsCheck(context)) assert(0); */ #define DDD_CONSCHECK(context) #define MINVNCLASS 2 /* determines copies, dep. on discr. ! */ /* defines for side matching of elements 8 bits: */ /* _ _ _ _ (4 bits for corner of one element) _ _ _ _ (4 bits for the other)*/ #define LINEPOINTS 51 /* 0011 0011 */ #define TRIPOINTS 119 /* 0111 0111 */ #define QUADPOINTS 255 /* 1111 1111 */ #define MAX_GREEN_SONS 32 /* max num of sons for green refinement */ /* define to control element which is responsible */ /* equal side refinement of neighboring elements */ #ifdef ModelP #define _EID_ EGID #define _ID_ GID #else #define _EID_ ID #define _ID_ ID #endif #define EDGE_IN_PATTERN(p,i) (((p)[(i)]) & 0x1) #define SIDE_IN_PATTERN(e,p,i) (((p)[EDGES_OF_ELEM(e)+(i)]) & 0x1) #define EDGE_IN_PAT(p,i) (((p)>>(i)) & 0x1) #define SIDE_IN_PAT(p,i) (((p)>>(i)) & 0x1) #define MARK_BISECT_EDGE(r,i) ((r)->pattern[(i)]==1) #define REF_TYPE_CHANGES(e) ((REFINE(e)!=MARK(e)) || \ (REFINECLASS(e)!=MARKCLASS(e))) #define MARKED(e) (MARK(e)!=NO_REFINEMENT) /* green marked elements were NEWGREEN is true are refined without rule */ #ifdef DUNE_UGGRID_TET_RULESET #define NEWGREEN(e) (TAG(e)==HEXAHEDRON || TAG(e)== PRISM || \ TAG(e)==PYRAMID) #else #define NEWGREEN(e) (TAG(e)==HEXAHEDRON || TAG(e)== PRISM || \ TAG(e)==PYRAMID || TAG(e)== TETRAHEDRON) #endif /* marked elem with new green refinement (without rule, only 3D) */ #ifdef __ANISOTROPIC__ #define MARKED_NEW_GREEN(elem) \ (DIM==3 && ((NEWGREEN(elem) && MARKCLASS(elem)==GREEN_CLASS) || \ ((TAG(elem)==PRISM && MARKCLASS(elem)==RED_CLASS && USED(elem)==1)))) #else #define MARKED_NEW_GREEN(elem) \ (DIM==3 && NEWGREEN(elem) && MARKCLASS(elem)==GREEN_CLASS) #endif /** \brief Refined elem with new green refinement (without rule, only 3D) */ #define REFINED_NEW_GREEN(elem) \ (DIM==3 && NEWGREEN(elem) && REFINECLASS(elem)==GREEN_CLASS) /** \brief Macro to test whether element changes refinement */ #define REFINEMENT_CHANGES(elem) \ (REF_TYPE_CHANGES(elem) || \ (MARKED_NEW_GREEN(elem) && \ (REFINECLASS(elem)!=GREEN_CLASS || (REFINECLASS(elem)==GREEN_CLASS \ && USED(elem)==1)))) /** @name Macros for storing sparse data needed in ExchangeClosureInfo() */ /*@{*/ #define MARKCLASSDATA_SHIFT 20 #define GETMARKCLASSDATA(elem,dataadr) \ (*(dataadr)) = (*(dataadr)) | ((MARKCLASS(elem))<>MARKCLASSDATA_SHIFT)&((1<>MARKDATA_SHIFT)&((1<>COARSENDATA_SHIFT)&((1<=0; i--) \ { \ theEdge=GetEdge(CORNER_OF_EDGE_PTR((elem),i,0), \ CORNER_OF_EDGE_PTR((elem),i,1)); \ ASSERT(theEdge!=NULL); \ \ pattern = (pattern<<1) | macro(theEdge); \ } \ \ (*(patadr)) |= pattern; \ } #define SetEdgeInfo(elem,pat,macro,OP) \ { \ INT i,pattern; \ EDGE *theEdge; \ \ pattern = (pat); \ for (i=0; i>= 1; \ } \ } /*@}*/ #define REFINE_CONTEXT_LIST(d,context) \ IFDEBUG(gm,2) \ { \ INT i; \ \ UserWrite(" UpdateContext is :\n"); \ for(i=0; i
  • GM_OK if ok
  • GM_ERROR if an error occurs
  • */ /****************************************************************************/ INT NS_DIM_PREFIX SetRefineInfo (MULTIGRID *theMG) { if (MultiGridStatus(theMG,1,0,0,0) != GM_OK) return(GM_ERROR); return(GM_OK); } /****************************************************************************/ /** \brief Drop marks from leafelements to first regular This function drops marks from leafelements to first regular, and resets marks on all elements above (important for restrict marks) \return
      .n GM_OK if ok .n GM_ERROR if an error occurs */ /****************************************************************************/ static INT DropMarks (MULTIGRID *theMG) { return(GM_OK); for (INT k = TOPLEVEL(theMG); k > 0; k--) { const GRID *theGrid = GRID_ON_LEVEL(theMG,k); for (ELEMENT *theElement = FIRSTELEMENT(theGrid); theElement != NULL; theElement=SUCCE(theElement)) if ((MARKCLASS(theElement) == RED_CLASS) && (ECLASS(theElement) != RED_CLASS)) { INT Mark = MARK(theElement); /** \todo marks must be changed if element type changes */ if (TAG(theElement)!=HEXAHEDRON && TAG(EFATHER(theElement))==HEXAHEDRON) Mark = HEXA_RED; if (TAG(theElement)!=PYRAMID && TAG(EFATHER(theElement))==PYRAMID) Mark = PYR_RED; ELEMENT *FatherElement = theElement; SETMARK(FatherElement,NO_REFINEMENT); SETMARKCLASS(FatherElement,NO_CLASS); FatherElement = EFATHER(FatherElement); SETMARK(FatherElement,Mark); SETMARKCLASS(FatherElement,RED_CLASS); } } return(GM_OK); } /* Functions for realizing the (parallel) closure FIFO */ /****************************************************************************/ /** \brief Function for realizing the (parallel) closure FIFO */ /****************************************************************************/ static INT InitClosureFIFO (void) { fifo_first=fifo_last=fifo_insertfirst=fifo_insertlast=NULL; first = 1; fifoloop = 0; if (0) UserWriteF("Using FIFO: loop %d\n",fifoloop); return (GM_OK); } /****************************************************************************/ /** \brief Function for realizing the (parallel) closure FIFO \param theGrid - pointer to grid structure . theElement . thePattern . NewPattern DESCRIPTION: */ /****************************************************************************/ static INT UpdateFIFOLists (GRID *theGrid, ELEMENT *theElement, INT thePattern, INT NewPattern) { if (MARKCLASS(theElement)==RED_CLASS && thePattern!=NewPattern) { #ifdef UG_DIM_2 for (INT j = 0; j < EDGES_OF_ELEM(theElement); j++) { if (EDGE_IN_PAT(thePattern,j)==0 && EDGE_IN_PAT(NewPattern,j)) { EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, j, 0), CORNER_OF_EDGE_PTR(theElement, j, 1)); ASSERT(theEdge != NULL); SETPATTERN(theEdge,1); /* boundary case */ if (SIDE_ON_BND(theElement,j)) continue; /* add the element sharing this edge to fifo_queue */ ELEMENT *NbElement = NBELEM(theElement, j); if (NbElement==NULL) continue; PRINTDEBUG(gm,1,(" ADDING to FIFO: NBID=%d\n", ID(NbElement))) /* unlink element from element list */ if (PREDE(NbElement) != NULL) SUCCE(PREDE(NbElement)) = SUCCE(NbElement); if (SUCCE(NbElement) != NULL) PREDE(SUCCE(NbElement)) = PREDE(NbElement); if (FIRSTELEMENT(theGrid) == NbElement) FIRSTELEMENT(theGrid) = SUCCE(NbElement); SUCCE(NbElement) = PREDE(NbElement) = NULL; /* insert into fifo */ if (fifo_insertfirst == NULL) { fifo_insertfirst = fifo_insertlast = NbElement; } else { SUCCE(fifo_insertlast) = NbElement; PREDE(NbElement) = fifo_insertlast; fifo_insertlast = NbElement; } } if (EDGE_IN_PAT(thePattern,j) && EDGE_IN_PAT(NewPattern,j)==0) { UserWriteF("UpdateFIFOLists(): ERROR EID=%d in fifo " "thePattern=%d has edge=%d refined but " "NewPattern=%d NOT!\n", ID(theElement),thePattern,j,NewPattern); RETURN(-1); } } #endif #ifdef UG_DIM_3 UserWriteF("UpdateFIFOLists(): ERROR fifo for 3D NOT implemented!\n"); ASSERT(0); #endif } return(GM_OK); } /****************************************************************************/ /** \brief Function for realizing the (parallel) closure FIFO \param theGrid - pointer to grid structure */ /****************************************************************************/ static INT UpdateClosureFIFO (GRID *theGrid) { /* insert fifo work list into elementlist */ for (ELEMENT *theElement = fifo_last; theElement != nullptr; theElement=PREDE(theElement)) { SUCCE(theElement) = FIRSTELEMENT(theGrid); PREDE(FIRSTELEMENT(theGrid)) = theElement; FIRSTELEMENT(theGrid) = theElement; } PREDE(FIRSTELEMENT(theGrid)) = NULL; if (fifo_insertfirst != NULL) { /* append fifo insert list to fifo work list */ firstElement = fifo_first = fifo_insertfirst; fifo_last = fifo_insertlast; IFDEBUG(gm,2) UserWriteF(" FIFO Queue:"); for (ELEMENT *theElement = fifo_first; theElement != nullptr; theElement=SUCCE(theElement)) UserWriteF(" %d\n", ID(theElement)); ENDDEBUG fifo_insertfirst = fifo_insertlast = NULL; first = 0; fifoloop++; UserWriteF(" loop %d",fifoloop); return(1); } return(0); } /****************************************************************************/ /* ManageParallelFIFO - function for realizing the (parallel) closure FIFO SYNOPSIS: static INT ManageParallelFIFO (ELEMENT *firstElement); PARAMETERS: \param firstElement DESCRIPTION: \return
        INT */ /****************************************************************************/ static INT ManageParallelFIFO (const PPIF::PPIFContext& context, const ELEMENT *firstElement) { #if defined(FIFO) && defined(ModelP) if (context.procs() == 1) return(0); do { /* exchange FIFO flag and PATTERN from slaves to master */ IF_FIF0AndPat_S2M(GLEVEL(grid)); /* add all master elements of horizontal interface to FIFO */ for (ELEMENT *theElement = firstElement; theElement != nullptr; theElement=SUCCE(theElement)) { if (IS_HOR_MASTER(theElement) && FIFO(theElement)) { AddToFIFIO(theElement); SETFIFO(theElement,0); } } /* check condition for termination of pattern adaptation */ AllFIFOsEmpty = CheckGlobalFIFOStatus(fifo); } while (fifo==NULL && AllFIFOsEmpty==1); #else return (0); #endif } /****************************************************************************/ /** \brief Changes refinement of element \param theElement - pointer to element This function returns a boolean value to indicate, whether an element changes its refinement (1) or not (0). \return
          .n 0 if element will not change refinement .n 1 if it will */ /****************************************************************************/ INT NS_DIM_PREFIX Refinement_Changes (ELEMENT *theElement) { return(REFINEMENT_CHANGES(theElement)); } /****************************************************************************/ /* GridClosure - compute closure for next level SYNOPSIS: static INT PrepareGridClosure (GRID *theGrid); PARAMETERS: \param theGrid - pointer to grid structure DESCRIPTION: This function computes the closure for next level. A closure can only be determined if the rule set for the used elements is complete. This means that for all side and edge patterns possible for an element type exists a rule which closes the element. In this case a FIFO for computing the closure is not needed any more and the closure can be computed in one step. \return
            INT .n >0 if elements will be refined .n 0 if no elements will be refined .n -1 if an error occurred */ /****************************************************************************/ static INT PrepareGridClosure (const GRID *theGrid) { /* reset USED flag of elements and PATTERN and */ /* ADDPATTERN flag on the edges */ for (ELEMENT *theElement = PFIRSTELEMENT(theGrid); theElement != nullptr; theElement=SUCCE(theElement)) { SETUSED(theElement,0); if (EGHOST(theElement)) { SETCOARSEN(theElement,0); SETMARK(theElement,NO_REFINEMENT); SETMARKCLASS(theElement,0); } for (INT j = 0; j < EDGES_OF_ELEM(theElement); j++) { EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, j, 0), CORNER_OF_EDGE_PTR(theElement, j, 1)); ASSERT(theEdge != NULL); SETPATTERN(theEdge,0); SETADDPATTERN(theEdge,1); /* needed in RestrictMarks() */ } } return(GM_OK); } #ifdef ModelP /****************************************************************************/ /* Gather_ElementClosureInfo - SYNOPSIS: static int Gather_ElementClosureInfo (DDD_OBJ obj, void *data); PARAMETERS: . obj . data DESCRIPTION: \return
              int */ /****************************************************************************/ static int Gather_ElementClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio) { ELEMENT *theElement = (ELEMENT *)obj; PRINTDEBUG(gm,1,("Gather_ElementClosureInfo(): e=" EID_FMTX "\n", EID_PRTX(theElement))) INT refinedata = 0; #ifdef UG_DIM_2 GetEdgeInfo(theElement,&refinedata,PATTERN); #endif /* mark and sidepattern have same control word positions */ /* if this changes sidepattern must be sent separately */ GETMARKDATA(theElement,&refinedata); GETMARKCLASSDATA(theElement,&refinedata); GETCOARSENDATA(theElement,&refinedata); ((INT *)data)[0] = refinedata; PRINTDEBUG(gm,1,("Gather_ElementClosureInfo(): refinedata=%08x " "sidepattern=%d markclass=%d mark=%d coarse=%d\n",refinedata, SIDEPATTERN(theElement),MARKCLASS(theElement),MARK(theElement),COARSEN(theElement))) return(GM_OK); } /****************************************************************************/ /* Scatter_ElementClosureInfo - SYNOPSIS: static int Scatter_ElementClosureInfo (DDD_OBJ obj, void *data); PARAMETERS: . obj . data DESCRIPTION: \return
                int */ /****************************************************************************/ static int Scatter_ElementClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio) { ELEMENT *theElement = (ELEMENT *)obj; PRINTDEBUG(gm,1,("Scatter_ElementClosureInfo(): e=" EID_FMTX "\n", EID_PRTX(theElement))) INT refinedata = ((INT *)data)[0]; #ifdef UG_DIM_2 SetEdgeInfo(theElement,refinedata,PATTERN,|); #endif /* mark and sidepattern have same control word positions */ /* if this changes sidepattern must be sent separately */ SETMARKDATA(theElement,refinedata); if (EMASTER(theElement)) return(GM_OK); if (EGHOST(theElement) && EGHOSTPRIO(prio)) return(GM_OK); SETMARKCLASSDATA(theElement,refinedata); SETCOARSENDATA(theElement,refinedata); PRINTDEBUG(gm,1,("Scatter_ElementClosureInfo(): refinedata=%08x " "sidepattern=%d markclass=%d mark=%d coarse=%d\n",refinedata, SIDEPATTERN(theElement),MARKCLASS(theElement),MARK(theElement),COARSEN(theElement))) return(GM_OK); } static INT ExchangeElementClosureInfo (GRID *theGrid) { auto& context = theGrid->dddContext(); const auto& dddctrl = ddd_ctrl(context); /* exchange information of elements to compute closure */ DDD_IFAOnewayX(context, dddctrl.ElementSymmVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), Gather_ElementClosureInfo, Scatter_ElementClosureInfo); return(GM_OK); } static int Gather_ElementRefine (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio) { ELEMENT *theElement = (ELEMENT *)obj; PRINTDEBUG(gm,1,("Gather_ElementRefine(): e=" EID_FMTX "\n", EID_PRTX(theElement))) ((INT *)data)[0] = MARKCLASS(theElement); ((INT *)data)[1] = MARK(theElement); return(GM_OK); } static int Scatter_ElementRefine (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio) { ELEMENT *theElement = (ELEMENT *)obj; PRINTDEBUG(gm,1,("Scatter_ElementClosureInfo(): e=" EID_FMTX "\n", EID_PRTX(theElement))) if (EMASTER(theElement)) return(GM_OK); if (EGHOST(theElement) && EGHOSTPRIO(prio)) return(GM_OK); SETMARKCLASS(theElement,((INT *)data)[0]); SETMARK(theElement,((INT *)data)[1]); return(GM_OK); } static INT ExchangeElementRefine (GRID *theGrid) { auto& context = theGrid->dddContext(); const auto& dddctrl = ddd_ctrl(context); /* exchange information of elements to compute closure */ DDD_IFAOnewayX(context, dddctrl.ElementSymmVHIF,GRID_ATTR(theGrid),IF_FORWARD,2*sizeof(INT), Gather_ElementRefine, Scatter_ElementRefine); return(GM_OK); } #ifdef UG_DIM_3 /****************************************************************************/ /* Gather_EdgeClosureInfo - SYNOPSIS: static int Gather_EdgeClosureInfo (DDD_OBJ obj, void *data); PARAMETERS: . obj . data DESCRIPTION: \return
                  int */ /****************************************************************************/ static int Gather_EdgeClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data) { EDGE *theEdge = (EDGE *)obj; PRINTDEBUG(gm,1,("Gather_EdgeClosureInfo(): e=" ID_FMTX "pattern=%d \n", ID_PRTX(theEdge),PATTERN(theEdge))) INT pattern = PATTERN(theEdge); ((INT *)data)[0] = pattern; return(GM_OK); } /****************************************************************************/ /* Scatter_EdgeClosureInfo - SYNOPSIS: static int Scatter_EdgeClosureInfo (DDD_OBJ obj, void *data); PARAMETERS: . obj . data DESCRIPTION: \return
                    int */ /****************************************************************************/ static int Scatter_EdgeClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data) { EDGE *theEdge = (EDGE *)obj; INT pattern = std::max((INT)PATTERN(theEdge),((INT *)data)[0]); PRINTDEBUG(gm,1,("Gather_EdgeClosureInfo(): e=" ID_FMTX "pattern=%d \n", ID_PRTX(theEdge),pattern)) SETPATTERN(theEdge,pattern); return(GM_OK); } INT ExchangeEdgeClosureInfo (GRID *theGrid) { auto& context = theGrid->dddContext(); const auto& dddctrl = ddd_ctrl(context); /* exchange information of edges to compute closure */ DDD_IFAOneway(context, dddctrl.EdgeVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), Gather_EdgeClosureInfo, Scatter_EdgeClosureInfo); return(GM_OK); } #endif /****************************************************************************/ /* ExchangeClosureInfo - SYNOPSIS: static INT ExchangeClosureInfo (GRID *theGrid); PARAMETERS: . theGrid DESCRIPTION: \return
                      INT */ /****************************************************************************/ static INT ExchangeClosureInfo (GRID *theGrid) { /* exchange information of elements to compute closure */ if (ExchangeElementClosureInfo(theGrid) != GM_OK) RETURN(GM_ERROR); #ifdef UG_DIM_3 /* exchange information of edges to compute closure */ if (ExchangeEdgeClosureInfo(theGrid) != GM_OK) RETURN(GM_ERROR); #endif return(GM_OK); } #endif /****************************************************************************/ /* ComputePatterns - SYNOPSIS: static INT ComputePatterns (GRID *theGrid); PARAMETERS: . theGrid - pointer to grid structure DESCRIPTION: \return
                        INT */ /****************************************************************************/ static INT ComputePatterns (const GRID *theGrid) { /* ComputePatterns works only on master elements */ /* since ghost elements have no information from */ /* RestrictMarks() up to this time and this may */ /* leed to inconsistency while coarsening */ /* reset EDGE/SIDEPATTERN in elements */ /* set SIDEPATTERN in elements */ /* set PATTERN on the edges */ for (ELEMENT *theElement = PFIRSTELEMENT(theGrid); theElement != nullptr; theElement=SUCCE(theElement)) { #ifdef ModelP if (EGHOST(theElement)) { #ifdef UG_DIM_3 SETSIDEPATTERN(theElement,0); #endif continue; } #endif if (MARKCLASS(theElement)==RED_CLASS) { INT Mark = MARK(theElement); SHORT *thePattern = MARK2PATTERN(theElement,Mark); for (INT i = 0; i < EDGES_OF_ELEM(theElement); i++) if (EDGE_IN_PATTERN(thePattern,i)) { EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, i, 0), CORNER_OF_EDGE_PTR(theElement, i, 1)); ASSERT(theEdge != NULL); SETPATTERN(theEdge,1); } #ifdef UG_DIM_3 /* SIDEPATTERN must be reset here for master elements, */ /* because it overlaps with MARK (980217 s.l.) */ SETSIDEPATTERN(theElement,0); for (INT i = 0; i < SIDES_OF_ELEM(theElement); i++) { #ifdef DUNE_UGGRID_TET_RULESET if (CORNERS_OF_SIDE(theElement,i)==4) { #endif /* set SIDEPATTERN if side has node */ if(SIDE_IN_PATTERN(theElement,thePattern,i)) SETSIDEPATTERN(theElement, SIDEPATTERN(theElement) | 1< INT */ /****************************************************************************/ static INT CorrectTetrahedronSidePattern (ELEMENT *theElement, INT i, ELEMENT *theNeighbor, INT j) { INT theEdgeNum,theEdgePattern=0; INT NbEdgeNum,NbEdgePattern,NbSidePattern,NbSideMask; if (TAG(theElement)==PYRAMID || TAG(theElement)==PRISM) return(GM_OK); for (INT k = EDGES_OF_ELEM(theElement) - 1; k >= 0; k--) { EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, k, 0), CORNER_OF_EDGE_PTR(theElement, k, 1)); ASSERT(theEdge!=NULL); theEdgePattern = (theEdgePattern<<1) | PATTERN(theEdge); } /* because SIDEPATTERN is set to zero, */ /* I choose TriSectionEdge[0] */ theEdgeNum = TriSectionEdge[theEdgePattern &CondensedEdgeOfSide[i]][0]; if (theEdgeNum == -2) RETURN(-1); if (theEdgeNum == -1) return(GM_OK); switch (TAG(theNeighbor)) { case TETRAHEDRON : NbEdgePattern = 0; for (INT k = 0; k < EDGES_OF_ELEM(theNeighbor); k++) { EDGE *NbEdge = GetEdge(CORNER_OF_EDGE_PTR(theNeighbor, k, 0), CORNER_OF_EDGE_PTR(theNeighbor, k, 1)); ASSERT(NbEdge!=NULL); NbEdgePattern = NbEdgePattern | (PATTERN(NbEdge)<trisectionedge)) trisectionedge = edge; } assert(trisectionedge != -1); if (theEdgeNum != trisectionedge) SETSIDEPATTERN(theNeighbor, SIDEPATTERN(theNeighbor)|(1< INT */ /****************************************************************************/ static INT CorrectElementSidePattern (ELEMENT *theElement, ELEMENT *theNeighbor, INT i) { INT j; #ifdef ModelP /* this case should not occur */ if (theNeighbor == NULL) { ASSERT(EGHOST(theElement)); UserWriteF("CorrectElementSidePattern(): error elem=" EID_FMTX " nb[%d]=" EID_FMTX " nb=" EID_FMTX "\n", EID_PRTX(theElement),i,EID_PRTX(NBELEM(theElement,i)), EID_PRTX(theNeighbor)); return(GM_OK); } #endif /* search neighbors side */ for (j=0; j= SIDES_OF_ELEM(theNeighbor)) { if (!(EGHOST(theElement) && EGHOST(theNeighbor))) { UserWriteF("CorrectElementSidePattern(): ERROR nbelem not found elem=%08x/" EID_FMTX " nb=%08x/" EID_FMTX "\n", theElement,EID_PRTX(theElement),theNeighbor,EID_PRTX(theNeighbor)); } ASSERT(EGHOST(theElement) && EGHOST(theNeighbor)); return(GM_OK); } #else ASSERT(j INT */ /****************************************************************************/ static INT SetElementSidePatterns (GRID *theGrid, ELEMENT *firstElement) { INT i; ELEMENT *theElement,*theNeighbor; /* set pattern (edge and side) on the elements */ for (theElement=firstElement; theElement!=NULL; theElement=SUCCE(theElement)) { /* make edgepattern consistent with pattern of edges */ SETUSED(theElement,1); #ifndef __ANISOTROPIC__ /** \todo change this for red refinement of pyramids */ if (DIM==3 && TAG(theElement)==PYRAMID) continue; #endif /* make sidepattern consistent with neighbors */ for (i=0; i INT */ /****************************************************************************/ static INT SetElementRules (GRID *theGrid, ELEMENT *firstElement, INT *cnt) { INT Mark,NewPattern; INT thePattern,theEdgePattern,theSidePattern=0; ELEMENT *theElement; [[maybe_unused]] const int me = theGrid->ppifContext().me(); /* set refinement rules from edge- and sidepattern */ (*cnt) = 0; for (theElement=firstElement; theElement!=NULL; theElement=SUCCE(theElement)) { theEdgePattern = 0; /* compute element pattern */ GetEdgeInfo(theElement,&theEdgePattern,PATTERN); #ifdef UG_DIM_2 thePattern = theEdgePattern; PRINTDEBUG(gm,2,(PFMT "SetElementRules(): e=" EID_FMTX " edgepattern=%d\n", me,EID_PRTX(theElement),theEdgePattern)); #endif #ifdef UG_DIM_3 theSidePattern = SIDEPATTERN(theElement); thePattern = theSidePattern< int */ /****************************************************************************/ static int Gather_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data) { #ifdef UG_DIM_2 INT pat; ELEMENT *theElement = (ELEMENT *)obj; pat = 0; GetEdgeInfo(theElement,&pat,ADDPATTERN); ((INT *)data)[0] = pat; PRINTDEBUG(gm,4,("Gather_AddEdgePattern(): elem=" EID_FMTX "pat=%08x\n", EID_PRTX(theElement),pat)); return(GM_OK); #endif #ifdef UG_DIM_3 INT addpattern; EDGE *theEdge = (EDGE *)obj; addpattern = ADDPATTERN(theEdge); ((INT *)data)[0] = addpattern; PRINTDEBUG(gm,4,("Gather_AddEdgePattern(): edge=" ID_FMTX "pat=%08x\n", ID_PRTX(theEdge),addpattern)); return(GM_OK); #endif } /****************************************************************************/ /* Scatter_AddEdgePattern - SYNOPSIS: static int Scatter_AddEdgePattern (DDD_OBJ obj, void *data); PARAMETERS: . obj . data DESCRIPTION: \return
                          int */ /****************************************************************************/ static int Scatter_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data) { #ifdef UG_DIM_2 INT pat; ELEMENT *theElement = (ELEMENT *)obj; /** \todo (HRR 971207): output after SetEdgeInfo (pat not init)? */ PRINTDEBUG(gm,4,("Scatter_AddEdgePattern(): elem=" EID_FMTX "pat=%08x\n", EID_PRTX(theElement),pat)); pat = ((INT *)data)[0]; SetEdgeInfo(theElement,pat,ADDPATTERN,&); return(GM_OK); #endif #ifdef UG_DIM_3 INT addpattern; EDGE *theEdge = (EDGE *)obj; addpattern = std::min((INT)ADDPATTERN(theEdge),((INT *)data)[0]); PRINTDEBUG(gm,4,("Gather_AddEdgePattern(): edge=" ID_FMTX "pat=%08x\n", ID_PRTX(theEdge),addpattern)); SETADDPATTERN(theEdge,addpattern); return(GM_OK); #endif } /****************************************************************************/ /* ExchangeAddPatterns - SYNOPSIS: static INT ExchangeAddPatterns (GRID *theGrid); PARAMETERS: . theGrid - pointer to grid structure DESCRIPTION: \return
                            INT */ /****************************************************************************/ static INT ExchangeAddPatterns (GRID *theGrid) { auto& context = theGrid->dddContext(); const auto& dddctrl = ddd_ctrl(context); /* exchange addpatterns of edges */ #ifdef UG_DIM_2 DDD_IFAOneway(context, dddctrl.ElementVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), Gather_AddEdgePattern, Scatter_AddEdgePattern); #endif #ifdef UG_DIM_3 DDD_IFAOneway(context, dddctrl.EdgeVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), Gather_AddEdgePattern, Scatter_AddEdgePattern); #endif return(GM_OK); } #endif /****************************************************************************/ /* SetAddPatterns - SYNOPSIS: static INT SetAddPatterns (GRID *theGrid); PARAMETERS: . theGrid - pointer to grid structure DESCRIPTION: \return
                              INT */ /****************************************************************************/ static INT SetAddPatterns (GRID *theGrid) { INT j; ELEMENT *theElement; EDGE *theEdge; /* set additional pattern on the edges */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (MARKCLASS(theElement)!=RED_CLASS) continue; REFINE_ELEMENT_LIST(1,theElement,"SetAddPatterns(): addpattern=0"); for (j=0; j INT */ /****************************************************************************/ static INT BuildGreenClosure (const GRID *theGrid) { INT i; ELEMENT *theElement; EDGE *theEdge; #ifdef UG_DIM_3 INT j; #endif /* build a green covering around the red elements */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { #ifdef __ANISOTROPIC__ if (MARKCLASS(theElement)==RED_CLASS && !(TAG(theElement)==PRISM && MARK(theElement)==PRI_QUADSECT)) continue; ASSERT(MARKCLASS(theElement)!=RED_CLASS || (MARKCLASS(theElement)==RED_CLASS && TAG(theElement)==PRISM && MARK(theElement)==PRI_QUADSECT)); #else if (MARKCLASS(theElement)==RED_CLASS) continue; #endif SETUPDATE_GREEN(theElement,0); /* if edge node exists element needs to be green */ for (i=0; i= SIDES_OF_ELEM(theNeighbor)) { ASSERT(EGHOST(theElement) && EGHOST(theNeighbor)); continue; } #else ASSERT(j reset USED flag */ /* in parallel case: one communication to determine the minimum */ /* over all copies of an green element would be needed */ if (REFINECLASS(theElement)==GREEN_CLASS && MARKCLASS(theElement)==GREEN_CLASS && UPDATE_GREEN(theElement)==0) { /* do not renew green refinement */ SETUSED(theElement,0); } #ifdef __ANISOTROPIC__ if (MARKCLASS(theElement)==RED_CLASS && UPDATE_GREEN(theElement)==0) { ASSERT(TAG(theElement)==PRISM && MARK(theElement)==PRI_QUADSECT); SETUSED(theElement,0); } #endif #endif } return(GM_OK); } #if defined(ModelP) && defined(Debug) #define CEIL(n) ((n)+((ALIGNMENT-((n)&(ALIGNMENT-1)))&(ALIGNMENT-1))) /****************************************************************************/ /* Gather_ElementInfo - SYNOPSIS: static int Gather_ElementInfo (DDD_OBJ obj, void *Data); PARAMETERS: . obj . Data DESCRIPTION: \return
                                int */ /****************************************************************************/ static int Gather_ElementInfo (DDD::DDDContext&, DDD_OBJ obj, void *Data) { INT epat,eaddpat; ELEMENT *theElement = (ELEMENT *)obj; char *data = (char *)Data; PRINTDEBUG(gm,4,("Gather_ElementInfo(): elem=" EID_FMTX "\n", EID_PRTX(theElement))); memcpy(data,theElement,sizeof(struct generic_element)); data += CEIL(sizeof(struct generic_element)); epat = 0; GetEdgeInfo(theElement,&epat,PATTERN); ((int *)data)[0] = epat; data += sizeof(INT); eaddpat = 0; GetEdgeInfo(theElement,&eaddpat,ADDPATTERN); ((int *)data)[0] = eaddpat; return(GM_OK); } /* this macro compares control word macros of two elements */ #define COMPARE_MACRO(elem0,elem1,macro,print) \ if (macro(elem0) != macro(elem1)) \ { \ print("e=" EID_FMTX " macro=%s differs value0=%d value1=%d \n", \ EID_PRTX(elem0),# macro,macro(elem0),macro(elem1)); \ assert(0); \ } #ifdef DUNE_UGGRID_TET_RULESET #define COMPARE_MACROX(elem0,elem1,macro,print) \ { \ INT _mark0,_mark1,_pat0,_pat1; \ \ _mark0 = macro(elem0); _mark1 = macro(elem1); \ _pat0 = MARK2PAT((elem0),_mark0); _pat1 = MARK2PAT((elem1),_mark1); \ if ((_pat0 & ((1<<10)-1)) != (_pat1 & ((1<<10)-1))) \ COMPARE_MACRO(elem0,elem1,macro,print) \ } #else #define COMPARE_MACROX(elem0,elem1,macro,print) \ COMPARE_MACRO(elem0,elem1,macro,print) #endif /* this macro compares two values */ #define COMPARE_VALUE(elem0,val0,val1,string,print) \ if ((val0) != (val1)) \ { \ (print)("e=" EID_FMTX " %s differs value0=%d value1=%d \n", \ EID_PRTX(elem0),(string),(val0),(val1)); \ assert(0); \ } /****************************************************************************/ /* Scatter_ElementInfo - SYNOPSIS: static int Scatter_ElementInfo (DDD_OBJ obj, void *Data); PARAMETERS: . obj . Data DESCRIPTION: \return
                                  int */ /****************************************************************************/ static int Scatter_ElementInfo (DDD::DDDContext&, DDD_OBJ obj, void *Data) { INT epat,mpat,eaddpat,maddpat; ELEMENT *theElement = (ELEMENT *)obj; struct generic_element ge; ELEMENT *theMaster = (ELEMENT *)≥ char *data = (char *)Data; memcpy(theMaster,data,sizeof(struct generic_element)); data += CEIL(sizeof(struct generic_element)); PRINTDEBUG(gm,4,("Scatter_ElementInfo(): Comparing elem=" EID_FMTX " master=" EID_FMTX "\n",EID_PRTX(theElement), EID_PRTX(theMaster))); /* now compare the control entries of master with it local copy */ COMPARE_MACRO(theElement,theMaster,REFINECLASS,PrintDebug) COMPARE_MACRO(theElement,theMaster,MARKCLASS,PrintDebug) COMPARE_MACROX(theElement,theMaster,REFINE,PrintDebug) COMPARE_MACROX(theElement,theMaster,MARK,PrintDebug) COMPARE_MACRO(theElement,theMaster,COARSEN,PrintDebug) COMPARE_MACRO(theElement,theMaster,USED,PrintDebug) /* #ifndef DUNE_UGGRID_TET_RULESET */ #ifdef UG_DIM_3 COMPARE_MACRO(theElement,theMaster,SIDEPATTERN,PrintDebug) #endif /* #endif */ epat = 0; GetEdgeInfo(theElement,&epat,PATTERN); mpat = ((INT *)data)[0]; data += sizeof(INT); COMPARE_VALUE(theElement,epat,mpat,"EdgePattern",PrintDebug) eaddpat = 0; GetEdgeInfo(theElement,&eaddpat,ADDPATTERN); maddpat = ((INT *)data)[0]; COMPARE_VALUE(theElement,eaddpat,maddpat,"EdgeAddPattern",PrintDebug) return(GM_OK); } static INT CheckElementInfo (GRID *theGrid) { auto& context = theGrid->dddContext(); const auto& dddctrl = ddd_ctrl(context); /* exchange element info */ DDD_IFAOneway(context, dddctrl.ElementVHIF,GRID_ATTR(theGrid),IF_FORWARD, CEIL(sizeof(struct generic_element))+2*sizeof(INT), Gather_ElementInfo, Scatter_ElementInfo); return(GM_OK); } #endif /****************************************************************************/ /* */ /* Function: GridClosure */ /* */ /* Purpose: compute closure for next level. A closure can only be */ /* determined if the rule set for the used elements is complete. */ /* This means that for all side and edge patterns possible for */ /* an element type exists a rule which closes the element. */ /* In this case a FIFO for computing the closure is not needed */ /* any more and the closure can be computed in one step. */ /* */ /* Param: GRID *theGrid: pointer to grid structure */ /* */ /* return: INT >0: elements will be refined */ /* INT 0: no elements will be refined */ /* INT -1: an error occurred */ /* */ /****************************************************************************/ /****************************************************************************/ /** \brief Compute closure for next level \param theGrid - pointer to grid structure This function computes closure for next level. A closure can only be determined if the rule set for the used elements is complete. This means that for all side and edge patterns possible for an element type exists a rule which closes the element. In this case a FIFO for computing the closure is not needed any more and the closure can be computed in one step. \return
                                    .n >0 elements will be refined .n =0 no elements will be refined .n =-1 an error occurred */ /****************************************************************************/ static int GridClosure (GRID *theGrid) { INT cnt; /* initialize used control word entries */ if (PrepareGridClosure(theGrid) != GM_OK) RETURN(GM_ERROR); /* compute pattern on edges and elements */ if (ComputePatterns(theGrid) != GM_OK) RETURN(GM_ERROR); firstElement = PFIRSTELEMENT(theGrid); if (fifoFlag) if (InitClosureFIFO() != GM_OK) return(GM_OK); /* fifo loop */ do { #ifdef UG_DIM_3 #if defined(ModelP) && defined(DUNE_UGGRID_TET_RULESET) /* edge pattern is needed consistently in CorrectTetrahedronSidePattern() */ if (!refine_seq) { if (ExchangeEdgeClosureInfo(theGrid) != GM_OK) return(GM_ERROR); } #endif /* set side patterns on the elements */ if (SetElementSidePatterns(theGrid,firstElement) != GM_OK) RETURN(GM_ERROR); #endif #ifdef ModelP if (ExchangeClosureInfo(theGrid) != GM_OK) RETURN(GM_ERROR); #endif /* set rules on the elements */ if (SetElementRules(theGrid,firstElement,&cnt) != GM_OK) RETURN(GM_ERROR); } /* exit only if fifo not active or fifo queue */ /* empty or all processor have finished closure */ while (fifoFlag && UpdateClosureFIFO(theGrid) && ManageParallelFIFO(theGrid->ppifContext(), firstElement)); /* set patterns on all edges of red elements */ if (SetAddPatterns(theGrid) != GM_OK) RETURN(GM_ERROR); /* build the closure around the red elements */ if (BuildGreenClosure(theGrid) != GM_OK) RETURN(GM_ERROR); #if defined(Debug) && defined(ModelP) if (CheckElementInfo(theGrid)) RETURN(GM_ERROR); #endif return(cnt); } /****************************************************************************/ /* GetNeighborSons - fill SonList for theElement SYNOPSIS: static INT GetNeighborSons (ELEMENT *theElement, ELEMENT *theSon, ELEMENT *SonList[MAX_SONS], int count, int nsons); PARAMETERS: . theElement - father element . theSon - currently visited son . SonList[MAX_SONS] - the list of sons . count - son count . sons - number of sons DESCRIPTION: This function fills SonList for theElement with a breadth first search \return
                                      INT .n new son count */ /****************************************************************************/ static INT GetNeighborSons (ELEMENT *theElement, ELEMENT *theSon, ELEMENT *SonList[MAX_SONS], int count, int nsons) { ELEMENT *NbElement; int i,j, startson, stopson; startson = count; for (i=0; i INT .n 0 if ok .n 1 if an error occurs */ /****************************************************************************/ INT NS_DIM_PREFIX GetAllSons (const ELEMENT *theElement, ELEMENT *SonList[MAX_SONS]) { ELEMENT *son; int SonID,i; ASSERT(theElement != NULL); for (SonID=0; SonID INT */ /****************************************************************************/ INT NS_DIM_PREFIX GetSons (const ELEMENT *theElement, ELEMENT *SonList[MAX_SONS]) { int SonID; ELEMENT *son; if (theElement==NULL) RETURN(GM_ERROR); for (SonID=0; SonID0 error */ /* */ /****************************************************************************/ /****************************************************************************/ /* RestrictElementMark - restrict refinement marks SYNOPSIS: static INT RestrictElementMark(ELEMENT *theElement); PARAMETERS: . theElement - pointer to the element DESCRIPTION: This function restricts refinement marks of an element whose sons are further marked for refinement \return
                                        INT .n =0 - ok .n >0 - error */ /****************************************************************************/ static INT RestrictElementMark(ELEMENT *theElement) { #ifdef UG_DIM_3 #ifdef DUNE_UGGRID_TET_RULESET EDGE *theEdge; int j,Rule,Pattern; #endif #endif if (MARKCLASS(theElement)==RED_CLASS) { /** \todo this mark is from DropMarks()! */ /* theElement is marked from outside */ /** \todo edit this for new element type or */ /* for different restrictions */ switch (TAG(theElement)) { #ifdef UG_DIM_2 case TRIANGLE : SETMARK(theElement,T_RED); break; case QUADRILATERAL : SETMARK(theElement,Q_RED); break; #endif #ifdef UG_DIM_3 case TETRAHEDRON : #ifdef DUNE_UGGRID_TET_RULESET if (MARK(theElement)!=RED) /** \todo Is REFINE always as red rule available? */ SETMARK(theElement,REFINE(theElement)); #else SETMARK(theElement,TET_RED); #endif break; case PYRAMID : SETMARK(theElement,PYR_RED); break; case PRISM : SETMARK(theElement,PRI_RED); break; case HEXAHEDRON : SETMARK(theElement,HEXA_RED); break; #endif default : ASSERT(0); } } else { /** \todo edit this for new element type or for different restrictions */ switch (TAG(theElement)) { #ifdef UG_DIM_2 case TRIANGLE : SETMARK(theElement,T_RED); break; case QUADRILATERAL : SETMARK(theElement,Q_RED); break; #endif #ifdef UG_DIM_3 case TETRAHEDRON : #ifdef DUNE_UGGRID_TET_RULESET /* theElement is not marked from outside, */ /* so find a reg. rule being consistent */ /* with those neighbors of all sons of */ /* theElement which are marked for refine.*/ /* this choice will make sure these marks */ /* will not be distroyed. */ Pattern = RULE2PAT(theElement, REFINE(theElement)); for (j=0; j INT .n 0 if ok .n >0 if an error occurs */ /****************************************************************************/ static INT RestrictMarks (const GRID *theGrid) { ELEMENT *theElement,*SonList[MAX_SONS]; INT flag; for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (GetSons(theElement,SonList)!=GM_OK) RETURN(GM_ERROR); if (hFlag) { if ( /* if element is not refined anyway, */ /* then there are no restrictions to apply */ REFINE(theElement) == NO_REFINEMENT || /* irregular elements are marked by estimator, */ /* because they are leaf elements */ ECLASS(theElement) == YELLOW_CLASS || ECLASS(theElement) == GREEN_CLASS || /* regular elements with YELLOW_CLASS copies are */ /* marked by estimator, because the marks are dropped */ REFINECLASS(theElement) == YELLOW_CLASS ) { continue; } /* regular elements with GREEN_CLASS refinement */ /* go to no refinement or red refinement */ if (REFINECLASS(theElement)==GREEN_CLASS) { for (UINT i=0; iNO_REFINEMENT) { if (RestrictElementMark(theElement)) RETURN(GM_ERROR); /* this must be done only once for each element */ break; } } continue; } /* regular elements with regular refinement are */ /* the only ones to coarsen */ if (REFINECLASS(theElement) == RED_CLASS) { #ifndef __ANISOTROPIC__ SETMARK(theElement,REFINE(theElement)); SETMARKCLASS(theElement,REFINECLASS(theElement)); #else ASSERT(MARK(theElement)>=1); #endif } } #ifdef ModelP /* if no (or not all) sons are found by GetSons() on */ /* this proc then coarsening is not allowed */ if (REFINECLASS(theElement)==RED_CLASS && SonList[0]==NULL) continue; #endif flag = 0; for (UINT i=0; i < MAX_SONS && SonList[i]!=NULL; i++) { /* if not all sons are marked no unrefinement is possible */ if (!COARSEN(SonList[i]) || REFINECLASS(SonList[i])==RED_CLASS) { flag = 1; break; } } if (flag) continue; /* preserve regular refinement marks */ if (hFlag==0 && SonList[0]==NULL) continue; /* remove refinement */ SETMARK(theElement,NO_REFINEMENT); SETMARKCLASS(theElement,NO_CLASS); SETCOARSEN(theElement,1); } return(GM_OK); } /****************************************************************************/ /* ComputeCopies - determine copy elements from node classes SYNOPSIS: static int ComputeCopies (GRID *theGrid); PARAMETERS: . theGrid - pointer to grid structure DESCRIPTION: This function determines copy elements from node classes \return
                                          int .n GM_OK if ok */ /****************************************************************************/ static int ComputeCopies (GRID *theGrid) { ELEMENT *theElement; int flag; int cnt = 0; PRINTDEBUG(gm,1,("ComputeCopies on level %d\n",GLEVEL(theGrid))); [[maybe_unused]] const int me = theGrid->ppifContext().me(); /* set class of all dofs on next level to 0 */ ClearNextNodeClasses(theGrid); /* seed dofs of regularly and irregularly refined elements to 3 */ flag = 0; for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (MARK(theElement)!=NO_REFINEMENT && (MARKCLASS(theElement)==RED_CLASS || MARKCLASS(theElement)==GREEN_CLASS)) { SeedNextNodeClasses(theElement); flag=1; /* there is at least one element to be refined */ } } /* copy all option or neighborhood */ if (rFlag==GM_COPY_ALL) { #ifdef ModelP flag = UG_GlobalMaxINT(theGrid->ppifContext(), flag); #endif if (flag) for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { SeedNextNodeClasses(theElement); } } else { PropagateNextNodeClasses(theGrid); } /* an element is copied if it has a dof of class 2 and higher */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { INT maxclass = 0; if ((MARK(theElement)==NO_REFINEMENT)&& ((maxclass=MaxNextNodeClass(theElement))>=MINVNCLASS)) { PRINTDEBUG(gm,1,(PFMT "ComputeCopies(): level=%d e=" EID_FMTX "yellow marked\n", me,LEVEL(theElement),EID_PRTX(theElement))); SETMARK(theElement,COPY); SETMARKCLASS(theElement,YELLOW_CLASS); cnt++; } else { PRINTDEBUG(gm,1,(PFMT "ComputeCopies(): level=%d e=" EID_FMTX "not yellow marked" " mark=%d maxclass=%d\n", me,LEVEL(theElement),EID_PRTX(theElement),MARK(theElement),maxclass)); } } return(cnt); } /****************************************************************************/ /* CheckElementContextConsistency - check NTYPE flags of nodes SYNOPSIS: static void CheckElementContextConsistency(ELEMENT *theElement); PARAMETERS: . theElement - element to check DESCRIPTION: This function checks NTYPE flags of nodes in elementcontextt with the sons \return
                                            void */ /****************************************************************************/ #ifdef Debug static void CheckElementContextConsistency(ELEMENT *theElement, ELEMENTCONTEXT theElementContext) { int i; [[maybe_unused]] int errorflag = 0; int errortype[MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM]; int correcttype[MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM]; for (i=0; i int .n 0 - ok .n 1 - fatal memory error */ /****************************************************************************/ static int UpdateContext (GRID *theGrid, ELEMENT *theElement, NODE **theElementContext) { /* reset context to NULL */ for(INT i=0; i INT */ /****************************************************************************/ static INT UnrefineElement (GRID *theGrid, ELEMENT *theElement) { int s; ELEMENT *theSon,*SonList[MAX_SONS]; /* something to do ? */ if ((REFINE(theElement)==NO_REFINEMENT)||(theGrid==NULL)) return(GM_OK); if (GetAllSons(theElement,SonList)!=GM_OK) RETURN(GM_FATAL); for (s=0; sppifContext().me(); for (s=0; s bool */ /****************************************************************************/ static bool compare_node(const NODE* a, const NODE* b) { return a > b; } /****************************************************************************/ /** \brief Get the sons of an element side \param[in] theElement Input element \param[in] side Input element side number \param[out] Sons_of_Side Number of topological sons of the element side \param[in,out] SonList[MAX_SONS] Output elements \param[out] SonSides Output element side numbers \param[in] NeedSons If this is false, the correct list of sons is expected to be provided in SonList. If not it is recomputed. \param[in] ioflag An obsolete debugging flag \param[in] useRefineClass For a given side of an element, this routine computes all element sides on the next finer grid level which are topological sons of the input element side. */ /****************************************************************************/ INT NS_DIM_PREFIX Get_Sons_of_ElementSide (const ELEMENT *theElement, INT side, INT *Sons_of_Side, ELEMENT *SonList[MAX_SONS], INT *SonSides, INT NeedSons, INT ioflag, INT useRefineClass) { enum MarkClass markclass; /* reset soncount */ *Sons_of_Side = 0; /* get sons of element */ if (NeedSons) if (GetAllSons(theElement,SonList) != GM_OK) RETURN(GM_FATAL); IFDEBUG(gm,2) UserWriteF(" Get_Sons_of_ElementSide():" " id=%d tag=%d, refineclass=%d markclass=%d refine=%d mark=%d coarse=%d" " used=%d nsons=%d side=%d needsons=%d\n", ID(theElement),TAG(theElement),REFINECLASS(theElement),MARKCLASS(theElement), REFINE(theElement),MARK(theElement),COARSEN(theElement), USED(theElement),NSONS(theElement),side,NeedSons); for (INT i = 0; i < MAX_SONS && SonList[i] != NULL; i++) UserWriteF(" son[%d]=" EID_FMTX "\n",i,EID_PRTX(SonList[i])); ENDDEBUG #ifdef UG_DIM_2 markclass = RED_CLASS; #endif #ifdef UG_DIM_3 /* The following line used to read: markclass = (enum MarkClass) MARKCLASS(theElement); This works well within the UG grid refinement context. However, now I want to use this method within the DUNE UGGridLeafIntersectionIterator. The problem is that the user may have randomly marked elements before calling the iterator. In that case the mark classes may not be set the way this method expects it. Hence we allow the option to use REFINECLASS instead. To be absolutely certain we don't break existing code we keep the old behaviour as the default.*/ markclass = (enum MarkClass) ((useRefineClass) ? REFINECLASS(theElement) : MARKCLASS(theElement)); #endif /** \todo quick fix */ #ifdef ModelP if (EHGHOST(theElement)) markclass = GREEN_CLASS; #endif /* select sons to connect */ switch (markclass) { case YELLOW_CLASS : { *Sons_of_Side = 1; SonSides[0] = side; break; } case GREEN_CLASS : case RED_CLASS : { /* determine sonnodes of side */ NODE *SideNodes[MAX_SIDE_NODES]; INT nodes; INT nsons = 0; /* determine nodes of sons on side of element */ GetSonSideNodes(theElement,side,&nodes,SideNodes,ioflag); /* sort side nodes in descending address order */ std::sort(SideNodes, SideNodes + MAX_SIDE_NODES, compare_node); IFDEBUG(gm,3) UserWriteF("After qsort:\n"); for (INT i = 0; i < MAX_SIDE_NODES; i++) UserWriteF(" %8d",i); UserWriteF("\n"); for (INT i = 0; i < MAX_SIDE_NODES; i++) if (SideNodes[i]!=NULL) UserWriteF(" %x",SideNodes[i]); else UserWriteF(" %8d",0); UserWriteF("\n"); ENDDEBUG /* determine sonnode on side */ /* for (i=0; i corner; std::fill(corner.begin(), corner.end(), -1); IFDEBUG(gm,4) UserWriteF("son=%d\n",i); ENDDEBUG /* soncorners on side */ for (INT j = 0; j < CORNERS_OF_ELEM(SonList[i]); j++) { const NODE *nd = CORNER(SonList[i], j); if (std::binary_search(SideNodes, SideNodes + nodes, nd, compare_node)) { corner[n] = j; n++; } } assert(n<5); IFDEBUG(gm,4) UserWriteF("\n nodes on side n=%d:",n); for (INT j = 0; j < MAX_CORNERS_OF_SIDE; j++) UserWriteF(" %d",corner[j]); ENDDEBUG IFDEBUG(gm,0) if (n==3) assert(TAG(SonList[i])!=HEXAHEDRON); if (n==4) assert(TAG(SonList[i])!=TETRAHEDRON); ENDDEBUG /* sonside on side */ #ifdef UG_DIM_2 assert(n<=2); if (n==2) { if (corner[0]+1 == corner[1]) SonSides[nsons] = corner[0]; else { /** \todo find proper assert assert(corner[1] == CORNERS_OF_ELEM(theElement)-1); */ SonSides[nsons] = corner[1]; } SonList[nsons] = SonList[i]; nsons++; } #endif #ifdef UG_DIM_3 if (n==3 || n==4) { /* determine side number */ INT edge0 = EDGE_WITH_CORNERS(SonList[i],corner[0],corner[1]); INT edge1 = EDGE_WITH_CORNERS(SonList[i],corner[1],corner[2]); /* corners are not stored in local side numbering, */ /* therefore corner[x]-corner[y] might be the diagonal */ if (n==4 && edge0==-1) edge0 = EDGE_WITH_CORNERS(SonList[i],corner[0], corner[3]); if (n==4 && edge1==-1) edge1 = EDGE_WITH_CORNERS(SonList[i],corner[1], corner[3]); assert(edge0!=-1 && edge1!=-1); INT sonside = -1; for (INT side0 = 0; side0 < MAX_SIDES_OF_EDGE; side0++) { for (INT side1 = 0; side1 < MAX_SIDES_OF_EDGE; side1++) { IFDEBUG(gm,5) UserWriteF("edge0=%d side0=%d SIDE_WITH_EDGE=%d\n", edge0, side0, SIDE_WITH_EDGE(SonList[i],edge0,side0)); UserWriteF("edge1=%d side1=%d SIDE_WITH_EDGE=%d\n", edge1, side1, SIDE_WITH_EDGE(SonList[i],edge1,side1)); ENDDEBUG if (SIDE_WITH_EDGE(SonList[i],edge0,side0) == SIDE_WITH_EDGE(SonList[i],edge1,side1)) { sonside = SIDE_WITH_EDGE(SonList[i],edge0,side0); break; } } if (sonside != -1) break; } assert(sonside != -1); IFDEBUG(gm,4) UserWriteF(" son[%d]=%x with sonside=%d on eside=%d\n", i,SonList[i],sonside,side); ENDDEBUG IFDEBUG(gm,3) for (INT k = 0; k < SIDES_OF_ELEM(SonList[i]); k++) { const ELEMENT *Nb = NBELEM(SonList[i],k); if (Nb!=NULL) { INT j; for (j=0; j0 && nsons<6); #endif IFDEBUG(gm,3) UserWriteF(" nsons on side=%d\n",nsons); ENDDEBUG *Sons_of_Side = nsons; break; } /* old style This case would work for the sequential case if SonList is ordered according to rule (e.g. introduce GetOrderedSonList()). The upper case, used now in each situation, is a factor of 2 slower for uniform refinement!! (s.l. 981016) #ifndef ModelP case RED_CLASS: #endif */ { INT nsons = 0; for (INT i = 0; i < MAX_SONS && SonList[i] != NULL; i++) { const SONDATA *sondata = SON_OF_RULE(MARK2RULEADR(theElement, MARK(theElement)), i); for (INT j = 0; j < SIDES_OF_ELEM(SonList[i]); j++) if (SON_NB(sondata,j) == FATHER_SIDE_OFFSET+side) { SonSides[nsons] = j; SonList[nsons] = SonList[i]; nsons ++; } } *Sons_of_Side = nsons; break; } default : RETURN(GM_FATAL); } #ifdef ModelP IFDEBUG(gm,4) UserWriteF("Sons_of_Side=%d\n",*Sons_of_Side); for (INT i = 0; i < *Sons_of_Side; i++) UserWriteF("son[%d]=" EID_FMTX " sonside[%d]=%d\n",i, EID_PRTX(SonList[i]),i,SonSides[i]); ENDDEBUG #endif for (INT i = *Sons_of_Side; i < MAX_SONS; i++) SonList[i] = NULL; return(GM_OK); } /****************************************************************************/ /* Sort_Node_Ptr - SYNOPSIS: static INT Sort_Node_Ptr (INT n,NODE **nodes); PARAMETERS: . n . nodes DESCRIPTION: \return
                                              INT */ /****************************************************************************/ static INT Sort_Node_Ptr (INT n,NODE **nodes) { NODE* nd; INT i,j,max; max = 0; switch (n) { #ifdef UG_DIM_2 case 2 : #endif #ifdef UG_DIM_3 case 3 : case 4 : #endif for (i=0; i INT */ /****************************************************************************/ static INT Fill_Comp_Table (COMPARE_RECORD **SortTable, COMPARE_RECORD *Table, INT nelems, ELEMENT **Elements, const INT *Sides) { for (INT i = 0; i < nelems; i++) { SortTable[i] = Table+i; COMPARE_RECORD *Entry = Table+i; Entry->elem = Elements[i]; Entry->side = Sides[i]; Entry->nodes = CORNERS_OF_SIDE(Entry->elem,Entry->side); for (INT j = 0; j < CORNERS_OF_SIDE(Entry->elem, Entry->side); j++) Entry->nodeptr[j] = CORNER_OF_SIDE_PTR(Entry->elem,Entry->side,j); if (Sort_Node_Ptr(Entry->nodes,Entry->nodeptr)!=GM_OK) RETURN(GM_FATAL); } return(GM_OK); } /****************************************************************************/ /* compare_nodes - SYNOPSIS: static bool compare_nodes(const COMPARE_RECORD* a, const COMPARE_RECORD* b) PARAMETERS: . a . b DESCRIPTION: \return
                                                bool */ /****************************************************************************/ static bool compare_nodes(const COMPARE_RECORD* a, const COMPARE_RECORD* b) { const int n = (a->nodes == 4 && b->nodes == 4) ? 4 : 3; for (int i = 0; i < n; ++i) { if (a->nodeptr[i] > b->nodeptr[i]) return true; else if (a->nodeptr[i] < b->nodeptr[i]) return false; } return false; } /****************************************************************************/ /* Connect_Sons_of_ElementSide - SYNOPSIS: INT Connect_Sons_of_ElementSide (GRID *theGrid, ELEMENT *theElement, INT side, INT Sons_of_Side, ELEMENT **Sons_of_Side_List, INT *SonSides, INT ioflag); PARAMETERS: . theGrid . theElement . side . Sons_of_Side . Sons_of_Side_List . SonSides . ioflag DESCRIPTION: \return
                                                  INT */ /****************************************************************************/ INT NS_DIM_PREFIX Connect_Sons_of_ElementSide (GRID *theGrid, ELEMENT *theElement, INT side, INT Sons_of_Side, ELEMENT **Sons_of_Side_List, INT *SonSides, INT ioflag) { COMPARE_RECORD ElemSonTable[MAX_SONS]; COMPARE_RECORD NbSonTable[MAX_SONS]; COMPARE_RECORD *ElemSortTable[MAX_SONS]; COMPARE_RECORD *NbSortTable[MAX_SONS]; ELEMENT *theNeighbor; ELEMENT *Sons_of_NbSide_List[MAX_SONS]; INT nbside,Sons_of_NbSide,NbSonSides[MAX_SONS]; INT k; IFDEBUG(gm,2) UserWriteF("Connect_Sons_of_ElementSide: ID(elem)=%d side=%d " "Sons_of_Side=%d\n",ID(theElement),side,Sons_of_Side); REFINE_ELEMENT_LIST(0,theElement,"theElement:"); ENDDEBUG if (Sons_of_Side <= 0) return(GM_OK); /* connect to boundary */ if (OBJT(theElement)==BEOBJ && SIDE_ON_BND(theElement,side)) { /** \todo connect change test */ for (int i = 0; i < Sons_of_Side; i++) { assert(OBJT(Sons_of_Side_List[i])==BEOBJ); if (CreateSonElementSide(theGrid,theElement,side, Sons_of_Side_List[i],SonSides[i]) != GM_OK) { return(GM_FATAL); } } /* internal boundaries not connected */ /* return(GM_OK); */ } /* connect to neighbor element */ theNeighbor = NBELEM(theElement,side); if (theNeighbor==NULL) return(GM_OK); /* master elements only connect to master elements */ /* ghost elements connect to ghost and master elements */ #ifdef ModelP if (!ioflag && EMASTER(theElement) && EHGHOST(theNeighbor)) return(GM_OK); #endif /* only yellow elements may have no neighbors */ if (MARKCLASS(theNeighbor)==NO_CLASS) { if (hFlag) assert(MARKCLASS(theElement)==YELLOW_CLASS); return(GM_OK); } if (REFINEMENT_CHANGES(theNeighbor)) return(GM_OK); /* determine corresponding side of neighbor */ for (nbside=0; nbside0 && Sons_of_NbSide<6); else if (!(Sons_of_Side == Sons_of_NbSide && Sons_of_NbSide>0 && Sons_of_NbSide<6)) { ELEMENT *elem=NULL; ELEMENT *SonList[MAX_SONS]; REFINE_ELEMENT_LIST(0,theElement,"theElement:"); REFINE_ELEMENT_LIST(0,theNeighbor,"theNeighbor:"); UserWriteF("elem=" EID_FMTX " nb=" EID_FMTX "Sons_of_Side=%d Sons_of_NbSide=%d\n",EID_PRTX(theElement), EID_PRTX(theNeighbor),Sons_of_Side,Sons_of_NbSide); fflush(stdout); GetAllSons(theElement,SonList); for (int i = 0; i < MAX_SONS && SonList[i] != NULL; i++) { REFINE_ELEMENT_LIST(0,SonList[i],"son:"); } GetAllSons(theNeighbor,SonList); for (int i = 0; i < MAX_SONS && SonList[i] != NULL; i++) { REFINE_ELEMENT_LIST(0,SonList[i],"nbson:"); } /* sig bus error to see stack in totalview */ SET_NBELEM(elem,0,NULL); assert(0); } #ifdef ModelP } #endif IFDEBUG(gm,2) UserWriteF("Connect_Sons_of_ElementSide: NBID(elem)=%d side=%d " "Sons_of_Side=%d\n",ID(theNeighbor),nbside,Sons_of_NbSide); REFINE_ELEMENT_LIST(0,theNeighbor,"theNeighbor:"); ENDDEBUG /* fill sort and comparison tables */ Fill_Comp_Table(ElemSortTable,ElemSonTable,Sons_of_Side,Sons_of_Side_List, SonSides); Fill_Comp_Table(NbSortTable,NbSonTable,Sons_of_NbSide,Sons_of_NbSide_List, NbSonSides); IFDEBUG(gm,5) if (!ioflag) { UserWriteF("BEFORE qsort\n"); /* test whether all entries are corresponding */ for (int i = 0; i < Sons_of_Side; i++) { COMPARE_RECORD *Entry, *NbEntry; Entry = ElemSortTable[i]; NbEntry = NbSortTable[i]; if (Entry->nodes != NbEntry->nodes) UserWriteF("Connect_Sons_of_ElementSide(): LIST Sorttables[%d]" " eNodes=%d nbNodes=%d\n", i,Entry->nodes,NbEntry->nodes); for (int j = 0; j < Entry->nodes; j++) UserWriteF("Connect_Sons_of_ElementSide(): LIST Sorttables[%d][%d]" " eNodePtr=%d/%8x/%d nbNodePtr=%d/%8x/%d\n", i,j, ID(Entry->nodeptr[j]),Entry->nodeptr[j],NTYPE(Entry->nodeptr[j]), ID(NbEntry->nodeptr[j]),NbEntry->nodeptr[j],NTYPE(NbEntry->nodeptr[j])); UserWriteF("\n"); } UserWriteF("\n\n"); } ENDDEBUG /* qsort the tables using nodeptrs */ std::sort(ElemSortTable, ElemSortTable + Sons_of_Side, compare_nodes); std::sort(NbSortTable, NbSortTable + Sons_of_NbSide, compare_nodes); #ifdef ModelP if (!ioflag && Sons_of_NbSide!=Sons_of_Side) ASSERT(0); #endif #ifdef Debug if (!ioflag) /* check whether both sort table match exactly */ for (int i = 0; i < Sons_of_Side; i++) { COMPARE_RECORD *Entry, *NbEntry; Entry = ElemSortTable[i]; NbEntry = NbSortTable[i]; if (Entry->nodes != NbEntry->nodes) { printf("Connect_Sons_of_ElementSide(): ERROR Sorttables[%d]"\ " eNodes=%d nbNodes=%d\n",i,Entry->nodes,NbEntry->nodes); assert(0); } for (int j = 0; j < Entry->nodes; j++) if (Entry->nodeptr[j] != NbEntry->nodeptr[j]) { printf("Connect_Sons_of_ElementSide(): " "ERROR Sorttables[%d][%d]"\ " eNodePtr=%p nbNodePtr=%p\n", i,j,Entry->nodeptr[j],NbEntry->nodeptr[j]); /* assert(0);*/ } } #endif IFDEBUG(gm,4) if (!ioflag) { UserWriteF("After qsort\n"); /* test whether all entries are corresponding */ UserWriteF("SORTTABLELIST:\n"); for (int i = 0; i < Sons_of_Side; i++) { COMPARE_RECORD *Entry, *NbEntry; Entry = ElemSortTable[i]; NbEntry = NbSortTable[i]; UserWriteF("EAdr=%x side=%d realNbAdr=%x NbAdr=%x nbside=%x " "realNbAdr=%x\n", Entry->elem, Entry->side, NBELEM(Entry->elem,Entry->side), NbEntry->elem, NbEntry->side,NBELEM(NbEntry->elem,NbEntry->side)); } for (int i = 0; i < Sons_of_Side; i++) { COMPARE_RECORD *Entry, *NbEntry; Entry = ElemSortTable[i]; NbEntry = NbSortTable[i]; if (NBELEM(Entry->elem,Entry->side)!=NbEntry->elem) { UserWriteF("NOTEQUAL for i=%d elem=%x: elemrealnb=%x " "elemsortnb=%x\n", i,Entry->elem,NBELEM(Entry->elem,Entry->side),NbEntry->elem); REFINE_ELEMENT_LIST(0,theElement,"theElement:"); REFINE_ELEMENT_LIST(0,theNeighbor,"theNeighbor:"); } if (NBELEM(NbEntry->elem,NbEntry->side)!=Entry->elem) { UserWriteF("NOTEQUAL for i=%d nb=%x: nbrealnb=%x nbsortnb=%x\n", i,NbEntry->elem,NBELEM(NbEntry->elem,NbEntry->side), Entry->elem); REFINE_ELEMENT_LIST(0,theElement,"theE:"); REFINE_ELEMENT_LIST(0,theNeighbor,"theN:"); } } UserWriteF("\n\n"); } ENDDEBUG /* set neighborship relations */ if (ioflag) { for (int i = 0; i < Sons_of_Side; i++) { const COMPARE_RECORD *Entry = ElemSortTable[i]; for (k=0; knodes != NbEntry->nodes) continue; int idx; for (idx = 0; idx < Entry->nodes; idx++) if (Entry->nodeptr[idx] != NbEntry->nodeptr[idx]) break; if (idx == Entry->nodes) { SET_NBELEM(ElemSortTable[i]->elem,ElemSortTable[i]->side, NbSortTable[k]->elem); SET_NBELEM(NbSortTable[k]->elem,NbSortTable[k]->side, ElemSortTable[i]->elem); } } } } else /* all entries need to match exactly */ for (int i = 0; i < Sons_of_Side; i++) { SET_NBELEM(ElemSortTable[i]->elem,ElemSortTable[i]->side, NbSortTable[i]->elem); SET_NBELEM(NbSortTable[i]->elem,NbSortTable[i]->side, ElemSortTable[i]->elem); #ifdef UG_DIM_3 if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) if (DisposeDoubledSideVector(theGrid,ElemSortTable[i]->elem, ElemSortTable[i]->side, NbSortTable[i]->elem, NbSortTable[i]->side)) RETURN(GM_FATAL); #endif } return(GM_OK); } /****************************************************************************/ /** \brief Copy an element \param theGrid - grid level of sons of theElement \param theElement - element to refine \param theContext - nodes needed for new elements This function copies an element, (i) corner nodes are already allocated, (iv) create son and set references to sons \return
                                                  • 0 - ok
                                                  • 1 - fatal memory error
                                                  */ /****************************************************************************/ static INT RefineElementYellow (GRID *theGrid, ELEMENT *theElement, NODE **theContext) { INT i; bool boundaryelement = false; const int me = theGrid->ppifContext().me(); /* check for boundary */ if (OBJT(theElement) == BEOBJ) for (i=0; i INT .n 0 - ok .n 1 - fatal memory error */ /****************************************************************************/ static int RefineElementGreen (GRID *theGrid, ELEMENT *theElement, NODE **theContext) { struct greensondata { /** \brief Element type */ short tag; /** \brief Boundary element: yes (=1) or no (=0) */ short bdy; std::array corners; int nb[MAX_SIDES_OF_ELEM]; ELEMENT *theSon; }; typedef struct greensondata GREENSONDATA; std::array sons; int j, k, l; int node0; bool bdy; IFDEBUG(gm,1) UserWriteF("RefineElementGreen(): ELEMENT ID=%d\n",ID(theElement)); ENDDEBUG /* init son data array */ for (int i = 0; i < MAX_GREEN_SONS; i++) { sons[i].tag = -1; sons[i].bdy = -1; for (j=0; j sides; std::array theSideNodes; for (int i = 0; i < SIDES_OF_ELEM(theElement); i++) { NODE *theNode = theContext[CORNERS_OF_ELEM(theElement)+ EDGES_OF_ELEM(theElement)+i]; const int nedges = EDGES_OF_SIDE(theElement,i); bdy = (OBJT(theElement) == BEOBJ && SIDE_ON_BND(theElement,i)); int nelem = 5*i; /* A face in 3d gets subdivided into at most 5 (yes, 5) parts */ for (j=nelem; j<(nelem+5); j++) sons[j].bdy = bdy; k = 0; for (j=0; jmaxedge) maxedge = 2*k+1; */ /* neighboring elements need to refine in the same way */ /* in parallel case all copies of the elements also */ if (theSideNodes[2*k+1]!=NULL && _ID_(theSideNodes[2*k+1])>maxid) maxid = _ID_(theSideNodes[2*k+1]); } #if !defined ModelP // For an unknown reason the maxid variable is unsigned when ModelP is set, and signed otherwise. assert(maxid != -1); #endif assert(node0 != -1); /* if (node0 == maxedge && ((SIDEPATTERN(theElement)&(1< elementsSide0; l = 0; for (j=side0*5; j<(side0*5+5); j++) { for (k=0; k elementsSide1; l = 0; for (j=side1*5; j<(side1*5+5); j++) { for (int m = 0; m < MAX_SIDES_OF_ELEM; m++) if ((sons[j].nb[m]-MAX_GREEN_SONS)==side0) elementsSide1[l++] = j; } ASSERT(l==2); /* determine neighboring elements */ for (j=0; j= 0) { IFDEBUG(gm,2) if (i%5 == 0) UserWriteF(" SIDE %d:\n",i/5); ENDDEBUG NODE *ElementNodes[MAX_CORNERS_OF_ELEM]; l = 0; for (j=0; j= 0) /* valid son entry */ { l = 0; IFDEBUG(gm,0) for (j=0; j0 && Sons_of_Side<6); if (Connect_Sons_of_ElementSide(theGrid,theElement,i,Sons_of_Side, Sons_of_Side_List,SonSides,0)!=GM_OK) RETURN(GM_FATAL); #ifdef ModelP if (Identify_Objects_of_ElementSide(theGrid,theElement,i)) RETURN(GM_FATAL); #endif } return(GM_OK); } /****************************************************************************/ /* RefineElementRed - refine an element in the given context SYNOPSIS: static int RefineElementRed (GRID *theGrid, ELEMENT *theElement, NODE **theElementContext); PARAMETERS: \param theGrid - grid level of sons of theElement \param theElement - element to refine \param theContext - current context of element DESCRIPTION: This function refines an element in the given context, (i) corner and midnodes are already allocated, (ii) edges between corner and midnodes are ok, (iii) create interior nodes and edges, (iv) create sons and set references to sons. \return
                                                    INT .n GM_OK - ok .n GM_FATAL - fatal memory error */ /****************************************************************************/ static int RefineElementRed (GRID *theGrid, ELEMENT *theElement, NODE **theElementContext) { const int me = theGrid->ppifContext().me(); /* is something to do ? */ if (!MARKED(theElement)) return(GM_OK); std::array SonList = {}; REFRULE const* rule = MARK2RULEADR(theElement,MARK(theElement)); /* create elements */ for (INT s=0; s= FATHER_SIDE_OFFSET) { /* at the boundary */ if (SIDE_ON_BND(theElement,side-FATHER_SIDE_OFFSET)) { boundaryelement = true; break; } } } } NODE* ElementNodes[MAX_CORNERS_OF_ELEM]; for (INT i=0; i INT .n GM_OK - ok .n GM_FATAL - fatal memory error */ /****************************************************************************/ static INT RefineElement (GRID *UpGrid, ELEMENT *theElement,NODE** theNodeContext) { switch (MARKCLASS(theElement)) { case (YELLOW_CLASS) : if (RefineElementYellow(UpGrid,theElement,theNodeContext)!=GM_OK) RETURN(GM_FATAL); break; case (GREEN_CLASS) : #ifdef __ANISOTROPIC__ case (RED_CLASS) : #endif if (MARKED_NEW_GREEN(theElement)) { /* elements with incomplete rules set */ if (RefineElementGreen(UpGrid,theElement,theNodeContext) != GM_OK) RETURN(GM_FATAL); } else { /* elements with complete rules set */ if (RefineElementRed(UpGrid,theElement,theNodeContext)!=GM_OK) RETURN(GM_FATAL); } break; #ifndef __ANISOTROPIC__ case (RED_CLASS) : if (RefineElementRed(UpGrid,theElement,theNodeContext)!=GM_OK) RETURN(GM_FATAL); break; #endif default : RETURN(GM_FATAL); } return(GM_OK); } /****************************************************************************/ /* AdaptGrid - adapt one level of the multigrid SYNOPSIS: static int AdaptGrid (GRID *theGrid, INT *nadapted) PARAMETERS: \param theGrid - grid level to refine \param nadapted - number elements have been changed DESCRIPTION: This function refines one level of the grid \return
                                                      INT .n GM_OK - ok .n GM_FATAL - fatal memory error */ /****************************************************************************/ #ifdef ModelP static int AdaptLocalGrid (GRID *theGrid, INT *nadapted) #else static int AdaptGrid (GRID *theGrid, INT *nadapted) #endif { INT modified = 0; ELEMENT *NextElement; #ifdef ModelP const int me = theGrid->ppifContext().me(); auto& dddContext = theGrid->dddContext(); #endif GRID *UpGrid = UPGRID(theGrid); if (UpGrid == nullptr) RETURN(GM_FATAL); REFINE_GRID_LIST(1,MYMG(theGrid),GLEVEL(theGrid),("AdaptGrid(%d):\n",GLEVEL(theGrid)),""); #ifdef IDENT_ONLY_NEW /* reset ident flags for old objects */ for (NODE *theNode = PFIRSTNODE(UpGrid); theNode != nullptr; theNode = SUCCN(theNode)) SETNEW_NIDENT(theNode, 0); for (ELEMENT* theElement = PFIRSTELEMENT(UpGrid); theElement != nullptr; theElement = SUCCE(theElement)) { for (INT i = 0; i < EDGES_OF_ELEM(theElement); i++) { EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, i, 0), CORNER_OF_EDGE_PTR(theElement, i, 1)); SETNEW_EDIDENT(theEdge, 0); } } #endif /* refine elements */ /* ModelP: first loop over master elems, then loop over ghost elems */ /* this assures that no unnecessary disposures of objects are done */ /* which may cause trouble during identification (s.l. 9803020 */ for (ELEMENT *theElement = FIRSTELEMENT(theGrid); theElement != nullptr; theElement=NextElement) { NextElement = SUCCE(theElement); #ifdef ModelP /* loop over master elems first, then over ghost elems */ if (NextElement == NULL) NextElement=PFIRSTELEMENT(theGrid); if (NextElement == FIRSTELEMENT(theGrid)) NextElement = NULL; #endif #ifdef ModelP /* reset update overlap flag */ SETTHEFLAG(theElement,0); #endif /* do not change PrioVGhost elements */ if (EVGHOST(theElement)) continue; if (REFINEMENT_CHANGES(theElement)) { #ifdef ModelP { /* check for valid load balancing */ const auto& proclist = DDD_InfoProcListRange(dddContext, PARHDRE(theElement), false); for (auto&& [proc, prio] : proclist) { if (prio != PrioMaster && prio != PrioHGhost) { UserWriteF(PFMT "ERROR invalid load balancing: element=" EID_FMTX " has copies of type=%d on proc=%d\n", me, EID_PRTX(theElement), prio, proc); REFINE_ELEMENT_LIST(0,theElement,"ERROR element: "); assert(0); } } } #endif if (hFlag==0 && MARKCLASS(theElement)!=RED_CLASS) { /* remove copy marks */ SETMARK(theElement,NO_REFINEMENT); SETMARKCLASS(theElement,NO_CLASS); /* continue; */ } REFINE_ELEMENT_LIST(1,theElement,"REFINING element: "); if (UnrefineElement(UpGrid,theElement)) RETURN(GM_FATAL); #ifdef ModelP /* dispose hghost elements with EFATHER==NULL */ /** \todo how handle this situation? */ /* situation possibly some elements to be coarsened are */ /* disconnected from their fathers (970109 s.l.) */ if (0) if (EHGHOST(theElement) && COARSEN(theElement)) { if (LEVEL(theElement)>0 && EFATHER(theElement)==NULL) { DisposeElement(theGrid,theElement); continue; } } #endif if (EMASTER(theElement)) { ELEMENTCONTEXT theContext; if (UpdateContext(UpGrid,theElement,theContext)!=0) RETURN(GM_FATAL); REFINE_CONTEXT_LIST(2,theContext); #ifdef Debug CheckElementContextConsistency(theElement,theContext); #endif /* is something to do ? */ if (MARKED(theElement)) if (RefineElement(UpGrid,theElement,theContext)) RETURN(GM_FATAL); } /* refine and refineclass flag */ SETREFINE(theElement,MARK(theElement)); SETREFINECLASS(theElement,MARKCLASS(theElement)); SETUSED(theElement,0); #ifdef ModelP /* set update overlap flag */ SETTHEFLAG(theElement,1); #endif /* this grid is modified */ modified++; } else { #ifdef ModelP /* dispose hghost elements with EFATHER==NULL */ /** \todo how handle this situation? */ /* situation possibly some elements to be coarsened are */ /* disconnected from their fathers (970109 s.l.) */ if (0) if (EHGHOST(theElement) && COARSEN(theElement)) { if (LEVEL(theElement)>0 && EFATHER(theElement)==NULL) { DisposeElement(theGrid,theElement); continue; } } #endif #ifdef __ANISOTROPIC__ if (USED(theElement)==0 && MARKCLASS(theElement)==GREEN_CLASS) #else if (USED(theElement)==0) #endif { /* count not updated green refinements */ No_Green_Update++; } } /* count green marks */ if (MARKCLASS(theElement) == GREEN_CLASS) Green_Marks++; /* reset coarse flag */ SETCOARSEN(theElement,0); } if (UG_GlobalMaxINT(theGrid->ppifContext(), modified)) { /* reset (multi)grid status */ SETGLOBALGSTATUS(UpGrid); RESETMGSTATUS(MYMG(UpGrid)); } REFINE_GRID_LIST(1,MYMG(theGrid),GLEVEL(theGrid), ("END AdaptGrid(%d):\n",GLEVEL(theGrid)),""); *nadapted = modified; return(GM_OK); } #ifdef ModelP static int AdaptGrid (GRID *theGrid, INT toplevel, INT level, INT newlevel, INT *nadapted) { GRID *FinerGrid = UPGRID(theGrid); START_TIMER(gridadapti_timer) #ifdef UPDATE_FULLOVERLAP DDD_XferBegin(theGrid->dddContext()); { for (ELEMENT *theElement = PFIRSTELEMENT(FinerGrid); theElement != nullptr; theElement=SUCCE(theElement)) { if (EPRIO(theElement) == PrioHGhost) DisposeElement(FinerGrid,theElement,true); } } DDD_XferEnd(theGrid->dddContext()); #endif DDD_IdentifyBegin(theGrid->dddContext()); SET_IDENT_MODE(IDENT_ON); DDD_XferBegin(theGrid->dddContext()); DDD_CONSCHECK(theGrid->dddContext()); /* now really manipulate the next finer level */ START_TIMER(gridadaptl_timer) #ifdef DDDOBJMGR DDD_ObjMgrBegin(); #endif if (leveldddContext()); SUM_TIMER(gridadaptl_timer) DDD_CONSCHECK(theGrid->dddContext()); { int check=1; int debugstart=3; #ifdef Debug int gmlevel=Debuggm; #else int gmlevel=0; #endif if (IDENT_IN_STEPS) { DDD_IdentifyEnd(theGrid->dddContext()); } /* if no grid adaption has occurred adapt next level */ *nadapted = UG_GlobalSumINT(theGrid->ppifContext(), *nadapted); if (*nadapted == 0) { if (!IDENT_IN_STEPS) { SET_IDENT_MODE(IDENT_OFF); DDD_IdentifyEnd(theGrid->dddContext()); } SUM_TIMER(gridadapti_timer) return(GM_OK); } /* DDD_JoinBegin(); */ if (IDENT_IN_STEPS) DDD_IdentifyBegin(theGrid->dddContext()); DDD_CONSCHECK(theGrid->dddContext()); START_TIMER(ident_timer) if (Identify_SonObjects(theGrid)) RETURN(GM_FATAL); SET_IDENT_MODE(IDENT_OFF); DDD_IdentifyEnd(theGrid->dddContext()); SUM_TIMER(ident_timer) /* DDD_JoinEnd(); */ DDD_CONSCHECK(theGrid->dddContext()); if (leveldddContext()); if (0) /* delete sine this is already done in */ /* ConstructConsistentGrid() (s.l. 980522) */ if (SetGridBorderPriorities(theGrid)) RETURN(GM_FATAL); if (UpdateGridOverlap(theGrid)) RETURN(GM_FATAL); DDD_XferEnd(theGrid->dddContext()); DDD_CONSCHECK(theGrid->dddContext()); DDD_XferBegin(theGrid->dddContext()); if (ConnectGridOverlap(theGrid)) RETURN(GM_FATAL); DDD_XferEnd(theGrid->dddContext()); DDD_CONSCHECK(theGrid->dddContext()); /* this is needed due to special cases while coarsening */ /* sample scene: a ghost element is needed as overlap */ /* for two master elements, one of the master elements */ /* is coarsened, then the prio of nodes of the ghost */ /* element must eventually be downgraded from master */ /* to ghost prio (s.l. 971020) */ /* this is done as postprocessing step, since this needs */ /* 2 XferBegin/Ends here per modified gridlevel (s.l. 980522) */ /* #ifndef NEW_GRIDCONS_STYLE ConstructConsistentGrid(FinerGrid); #endif */ SUM_TIMER(overlap_timer) } DDD_CONSCHECK(theGrid->dddContext()); CheckConsistency(MYMG(theGrid),(INT)level,(INT)debugstart,(INT)gmlevel,&check); } if (0) CheckGrid(FinerGrid,1,0,1,1); SUM_TIMER(gridadapti_timer) return(GM_OK); } #endif #ifdef ModelP /* parameters for CheckGrid() */ #define GHOSTS 1 #define GEOM 1 #define ALG 0 #define LIST 1 #define IF 1 /****************************************************************************/ /* CheckConsistency - SYNOPSIS: void CheckConsistency (MULTIGRID *theMG, INT level ,INT debugstart, INT gmlevel, INT *check); PARAMETERS: . theMG . level . debugstart . gmlevel . check */ /****************************************************************************/ static void CheckConsistency (MULTIGRID *theMG, INT level ,INT debugstart, INT gmlevel, int *check) { GRID *theGrid = GRID_ON_LEVEL(theMG,level); IFDEBUG(gm,debugstart) printf(PFMT "AdaptMultiGrid(): %d. ConsCheck() on level=%d\n",theMG->ppifContext().me(),(*check)++,level); #ifdef Debug Debuggm = GHOSTS; #endif CheckGrid(theGrid,GEOM,ALG,LIST,IF); #ifdef Debug Debuggm=gmlevel; #endif if (DDD_ConsCheck(theMG->dddContext()) > 0) buggy(theMG); ENDDEBUG } #endif #ifdef STAT_OUT void NS_DIM_PREFIX Manage_Adapt_Timer (int alloc) { if (alloc) { NEW_TIMER(adapt_timer) NEW_TIMER(closure_timer) NEW_TIMER(gridadapt_timer) NEW_TIMER(gridadapti_timer) NEW_TIMER(gridadaptl_timer) NEW_TIMER(ident_timer) NEW_TIMER(overlap_timer) NEW_TIMER(gridcons_timer) NEW_TIMER(algebra_timer) } else { DEL_TIMER(adapt_timer) DEL_TIMER(closure_timer) DEL_TIMER(gridadapt_timer) DEL_TIMER(gridadapti_timer) DEL_TIMER(gridadaptl_timer) DEL_TIMER(ident_timer) DEL_TIMER(overlap_timer) DEL_TIMER(gridcons_timer) DEL_TIMER(algebra_timer) } } void NS_DIM_PREFIX Print_Adapt_Timer (const MULTIGRID* theMG, int total_adapted) { UserWriteF("ADAPT: total_adapted=%d t_adapt=%.2f: t_closure=%.2f t_gridadapt=%.2f t_gridadapti=%.2f " "t_gridadaptl=%.2f t_overlap=%.2f t_ident=%.2f t_gridcons=%.2f t_algebra=%.2f\n", total_adapted,EVAL_TIMER(adapt_timer),EVAL_TIMER(closure_timer),EVAL_TIMER(gridadapt_timer), EVAL_TIMER(gridadapti_timer),EVAL_TIMER(gridadaptl_timer),EVAL_TIMER(overlap_timer), EVAL_TIMER(ident_timer),EVAL_TIMER(gridcons_timer),EVAL_TIMER(algebra_timer)); UserWriteF("ADAPTMAX: total_adapted=%d t_adapt=%.2f: t_closure=%.2f t_gridadapt=%.2f " "t_gridadapti=%.2f " "t_gridadaptl=%.2f t_overlap=%.2f t_ident=%.2f t_gridcons=%.2f t_algebra=%.2f\n", total_adapted,UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(adapt_timer)), UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(closure_timer)), UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(gridadapt_timer)),UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(gridadapti_timer)), UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(gridadaptl_timer)), UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(overlap_timer)), UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(ident_timer)),UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(gridcons_timer)), UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(algebra_timer))); } #endif static INT PreProcessAdaptMultiGrid(MULTIGRID *theMG) { /* The matrices for the calculation are removed, to remember the recalculating the MGSTATUS is set to 1 */ MGSTATUS(theMG) = 1 ; return(0); } static INT PostProcessAdaptMultiGrid(MULTIGRID *theMG) { START_TIMER(algebra_timer) if (CreateAlgebra(theMG)) REP_ERR_RETURN(1); SUM_TIMER(algebra_timer) REFINE_MULTIGRID_LIST(1,theMG,"END AdaptMultiGrid():\n","",""); /* if (hFlag) UserWriteF(" Number of green refinements not updated: " "%d (%d green marks)\n",No_Green_Update,Green_Marks); */ /* increment step count */ SETREFINESTEP(REFINEINFO(theMG),REFINESTEP(REFINEINFO(theMG))+1); SUM_TIMER(adapt_timer) /* CheckMultiGrid(theMG); */ #ifdef STAT_OUT Print_Adapt_Timer(theMG, total_adapted); Manage_Adapt_Timer(0); #endif return(0); } /****************************************************************************/ /** \brief Adapt whole multigrid structure \param theMG - multigrid to refine \param flag - flag for switching between different yellow closures This function refines whole multigrid structure \return
                                                      • 0 - ok
                                                      • 1 - out of memory, but data structure as before
                                                      • 2 - fatal memory error, data structure corrupted
                                                      */ /****************************************************************************/ INT NS_DIM_PREFIX AdaptMultiGrid (MULTIGRID *theMG, INT flag, INT seq, INT mgtest) { INT nrefined,nadapted; /* check necessary condition */ if (!MG_COARSE_FIXED(theMG)) return (GM_COARSE_NOT_FIXED); if (PreProcessAdaptMultiGrid(theMG)) REP_ERR_RETURN(1); #ifdef ModelP { /* check and restrict partitioning of elements */ if (CheckPartitioning(theMG)) { /* Each call to RestrictPartitioning fixes the partitionings of children with * respect to their fathers. To fix also fix the partitionings of the grandchildren, * the method has to be called again. To be on the save side we call it once for * every level. * If I omit the loop (the way it was until 11.4.2014 I get assertion failures here * when mixing load balancing and adaptive refinement. I am not really sure whether * the loop is the correct fix, or whether it just papers over the problem. * Anyway, no crashes for now. */ for (int level = 0; level < TOPLEVEL(theMG); level++) if (RestrictPartitioning(theMG)) RETURN(GM_FATAL); if (CheckPartitioning(theMG)) assert(0); } } #endif #ifdef STAT_OUT Manage_Adapt_Timer(1); #endif START_TIMER(adapt_timer) /* set up information in refine_info */ #ifndef ModelP if (TOPLEVEL(theMG) == 0) #else if (UG_GlobalMaxINT(theMG->ppifContext(), TOPLEVEL(theMG)) == 0) #endif { SETREFINESTEP(REFINEINFO(theMG),0); } /* set info for refinement prediction */ SetRefineInfo(theMG); /* evaluate prediction */ if (mgtest) { UserWriteF("refinetest: predicted_new0=%9.0f predicted_new1=%9.0f\n", PREDNEW0(REFINEINFO(theMG)), PREDNEW1(REFINEINFO(theMG))); } /* set flags for different modes */ rFlag=flag & 0x03; /* copy local or all */ hFlag=!((flag>>2)&0x1); /* use hanging nodes */ fifoFlag=(flag>>3)&0x1; /* use fifo */ refine_seq = seq; No_Green_Update=0; Green_Marks=0; /* drop marks to regular elements */ if (hFlag) if (DropMarks(theMG)) RETURN(GM_ERROR); /* prepare algebra (set internal flags correctly) */ START_TIMER(algebra_timer) PrepareAlgebraModification(theMG); SUM_TIMER(algebra_timer) const INT toplevel = TOPLEVEL(theMG); REFINE_MULTIGRID_LIST(1,theMG,"AdaptMultiGrid()","","") /* compute modification of coarser levels from above */ START_TIMER(closure_timer) for (INT level = toplevel; level > 0; level--) { GRID *theGrid = GRID_ON_LEVEL(theMG,level); if (hFlag) { PRINTDEBUG(gm,1,("Begin GridClosure(%d,down):\n",level)) if ((nrefined = GridClosure(GRID_ON_LEVEL(theMG,level)))<0) { PrintErrorMessage('E',"AdaptMultiGrid","error in GridClosure"); RETURN(GM_ERROR); } REFINE_GRID_LIST(1,theMG,level,("End GridClosure(%d,down):\n",level),""); } #ifdef ModelP else { ExchangeElementRefine(theGrid); } #endif /* restrict marks on next lower grid level */ if (RestrictMarks(GRID_ON_LEVEL(theMG,level-1))!=GM_OK) RETURN(GM_ERROR); REFINE_GRID_LIST(1,theMG,level-1,("End RestrictMarks(%d,down):\n",level),""); } SUM_TIMER(closure_timer) #ifdef ModelP IdentifyInit(theMG); #endif INT newlevel = 0; for (INT level = 0; level <= toplevel; level++) { GRID *theGrid = GRID_ON_LEVEL(theMG,level); GRID *FinerGrid = nullptr; if (level < toplevel) FinerGrid = GRID_ON_LEVEL(theMG,level+1); START_TIMER(closure_timer) /* reset MODIFIED flags for grid and nodes */ SETMODIFIED(theGrid,0); for (NODE *theNode = FIRSTNODE(theGrid); theNode != nullptr; theNode = SUCCN(theNode)) { SETMODIFIED(theNode,0); } if (hFlag) { /* leave only regular marks */ for (ELEMENT *theElement = PFIRSTELEMENT(theGrid); theElement != nullptr; theElement = SUCCE(theElement)) { if ((ECLASS(theElement)==RED_CLASS) && MARKCLASS(theElement)==RED_CLASS) continue; SETMARK(theElement,NO_REFINEMENT); } PRINTDEBUG(gm,1,("Begin GridClosure(%d,up):\n",level)); /* determine regular and irregular elements on next level */ if ((nrefined = GridClosure(theGrid))<0) { PrintErrorMessage('E',"AdaptMultiGrid","error in 2. GridClosure"); RETURN(GM_ERROR); } REFINE_GRID_LIST(1,theMG,level,("End GridClosure(%d,up):\n",level),""); } #ifdef ModelP else { ExchangeElementRefine(theGrid); } #endif nrefined += ComputeCopies(theGrid); /** \todo bug fix to force new level creation */ if (!hFlag) { /* set this variable>0 */ nrefined = 1; } /* create a new grid level, if at least one element is refined on finest level */ if (nrefined>0 && level==toplevel) newlevel = 1; #ifdef ModelP newlevel = UG_GlobalMaxINT(theMG->ppifContext(), newlevel); #endif if (newlevel) { if (CreateNewLevel(theMG)==NULL) RETURN(GM_FATAL); FinerGrid = GRID_ON_LEVEL(theMG,toplevel+1); } PRINTDEBUG(gm,1,(PFMT "AdaptMultiGrid(): toplevel=%d nrefined=%d newlevel=%d\n", me,toplevel,nrefined,newlevel)); SUM_TIMER(closure_timer) /* now really manipulate the next finer level */ START_TIMER(gridadapt_timer) nadapted = 0; if (level=GREEN_CLASS || (rFlag==GM_COPY_ALL)) { SeedNodeClasses(theElement); } PropagateNodeClasses(FinerGrid); SUM_TIMER(algebra_timer) } } #ifdef ModelP IdentifyExit(); /* now repair inconsistencies */ /* former done on each grid level (s.l. 980522) */ START_TIMER(gridcons_timer); ConstructConsistentMultiGrid(theMG); SUM_TIMER(gridcons_timer) #endif DisposeTopLevel(theMG); if (TOPLEVEL(theMG) > 0) DisposeTopLevel(theMG); if (PostProcessAdaptMultiGrid(theMG)) REP_ERR_RETURN(1); return(GM_OK); }