// 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: ugm.c */ /* */ /* Purpose: unstructured grid manager */ /* */ /* Author: Peter Bastian */ /* Interdisziplinaeres Zentrum fuer Wissenschaftliches Rechnen */ /* Universitaet Heidelberg */ /* Im Neuenheimer Feld 368 */ /* 6900 Heidelberg */ /* email: ug@ica3.uni-stuttgart.de */ /* */ /* History: 09.03.92 begin, ug version 2.0 */ /* Aug 28 1996, ug version 3.4 */ /* */ /* Remarks: */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* defines to exclude functions */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* include files */ /* system include files */ /* application include files */ /* */ /****************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "cw.h" #include "evm.h" #include "gm.h" #include "rm.h" #include "dlmgr.h" #include "algebra.h" #include "ugm.h" #include "shapes.h" #include "refine.h" #include #include "pargm.h" #ifdef ModelP #include #include #endif #include USING_UG_NAMESPACE USING_UGDIM_NAMESPACE using namespace PPIF; /****************************************************************************/ /* */ /* defines in the following order */ /* */ /* compile time constants defining static data size (i.e. arrays) */ /* other constants */ /* macros */ /* */ /****************************************************************************/ #define RESOLUTION 20 /* resolution for creating boundary midnode */ #define SMALL1 0.001 #define LINKTABLESIZE 32 /* max number of inks per node for ordering */ /** \brief macro for controlling debugging output by conditions on objects */ #define UGM_CDBG(x,y) /****************************************************************************/ /* */ /* data structures used in this source file (exported data structures are */ /* in the corresponding include file!) */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* definition of variables global to this source file only (static!) */ /* */ /****************************************************************************/ /** \brief General purpose text buffer */ static char buffer[4*256]; static INT theMGDirID; /* env var ID for the multigrids */ static INT theMGRootDirID; /* env dir ID for the multigrids */ static UINT UsedOBJT; /* for the dynamic OBJECT management */ /****************************************************************************/ /* */ /* forward declarations of functions used before they are defined */ /* */ /****************************************************************************/ static INT DisposeVertex (GRID *theGrid, VERTEX *theVertex); static INT DisposeEdge (GRID *theGrid, EDGE *theEdge); /****************************************************************************/ /** \brief Get an object type id not occupied in theMG * * This function gets an object type id not occupied in theMG. * * @return
    *
  • id of object type if ok
  • *
  • -1 when error occurred
  • *
*/ /****************************************************************************/ GM_OBJECTS NS_DIM_PREFIX GetFreeOBJT () { INT i; /* skip predefined object types, they cannot be re-allocated */ for (i=NPREDEFOBJ; i
  • pointer to an object of the requested type
  • NULL if object of requested type is not available
  • * */ /****************************************************************************/ #ifdef ModelP static void ConstructDDDObject (DDD::DDDContext& context, void *obj, INT size, INT type) { if (obj!=NULL && type!=NOOBJ) { memset(obj,0,size); /* link this object to DDD management */ if (HAS_DDDHDR(context, type)) { DDD_TYPE dddtype = DDDTYPE(context, type); DDD_HDR dddhdr = (DDD_HDR)(((char *)obj) + DDD_InfoHdrOffset(context, dddtype)); DDD_HdrConstructor(context, dddhdr, dddtype, PrioMaster, 0); } } } #endif void * NS_DIM_PREFIX GetMemoryForObject (MULTIGRID *theMG, INT size, INT type) { void * obj = GetMem(MGHEAP(theMG),size); if (obj != NULL) memset(obj,0,size); #ifdef ModelP ConstructDDDObject(theMG->dddContext(), obj,size,type); #endif return obj; } /****************************************************************************/ /** \brief Put an object in the free list \fn PutFreeObject * @param theMG - pointer to multigrid * @param object - object to insert in free list * @param size - size of the object * @param type - type of the requested object This function puts an object in the free list. @return
    • 0 if ok
    • 1 when error occurred.
    • *
    */ /****************************************************************************/ #ifdef ModelP static void DestructDDDObject(DDD::DDDContext& context, void *object, INT type) { if (type!=NOOBJ) { /* unlink object from DDD management */ if (HAS_DDDHDR(context, type)) { DDD_HDR dddhdr = (DDD_HDR) (((char *)object)+DDD_InfoHdrOffset(context, DDDTYPE(context, type))); DDD_HdrDestructor(context, dddhdr); } } } #endif INT NS_DIM_PREFIX PutFreeObject (MULTIGRID *theMG, void *object, INT size, GM_OBJECTS type) { #ifdef ModelP DestructDDDObject(theMG->dddContext(), object,type); #endif DisposeMem(MGHEAP(theMG), object); return 0; } /****************************************************************************/ /** \brief Return pointer to a new boundary vertex structure * * @param theGrid grid where vertex should be inserted * * This function creates and initializes a new boundary vertex structure * and returns a pointer to it. * * @return
      *
    • pointer to requested object
    • *
    • NULL if out of memory
    • *
    */ /****************************************************************************/ static VERTEX *CreateBoundaryVertex (GRID *theGrid) { VERTEX *pv; INT i; pv = (VERTEX*)GetMemoryForObject(MYMG(theGrid),sizeof(struct bvertex),BVOBJ); if (pv==NULL) return(NULL); VDATA(pv) = NULL; /* initialize data */ CTRL(pv) = 0; SETOBJT(pv,BVOBJ); SETNOOFNODE(pv,0); SETLEVEL(pv,theGrid->level); ID(pv) = (theGrid->mg->vertIdCounter)++; VFATHER(pv) = NULL; #ifdef TOPNODE TOPNODE(pv) = NULL; #endif for (i=0; i
  • pointer to requested object
  • NULL if out of memory
  • */ /****************************************************************************/ static VERTEX *CreateInnerVertex (GRID *theGrid) { VERTEX *pv; INT i; pv = (VERTEX*)GetMemoryForObject(MYMG(theGrid),sizeof(struct ivertex),IVOBJ); if (pv==NULL) return(NULL); VDATA(pv) = NULL; /* initialize data */ CTRL(pv) = 0; SETOBJT(pv,IVOBJ); SETNOOFNODE(pv,0); SETLEVEL(pv,theGrid->level); ID(pv) = (theGrid->mg->vertIdCounter)++; VFATHER(pv) = NULL; #ifdef TOPNODE TOPNODE(pv) = NULL; #endif SETMOVE(pv,DIM); #ifdef ModelP DDD_AttrSet(PARHDRV(pv),GRID_ATTR(theGrid)); /* SETVXPRIO(pv,PrioMaster); */ #endif for (i=0; i
  • pointer to requested object
  • NULL if out of memory
  • */ /****************************************************************************/ static NODE *CreateNode (GRID *theGrid, VERTEX *vertex, GEOM_OBJECT *Father, INT NodeType) { NODE *pn; pn = (NODE *)GetMemoryForObject(MYMG(theGrid),sizeof(NODE),NDOBJ); if (pn==NULL) return(NULL); /* initialize data */ SETOBJT(pn,NDOBJ); SETLEVEL(pn,theGrid->level); #ifdef ModelP DDD_AttrSet(PARHDR(pn),GRID_ATTR(theGrid)); /* SETPRIO(pn,PrioMaster); */ pn->message_buffer_ = nullptr; pn->message_buffer_size_ = 0; #endif ID(pn) = (theGrid->mg->nodeIdCounter)++; START(pn) = NULL; SONNODE(pn) = NULL; MYVERTEX(pn) = vertex; if (NOOFNODE(vertex)status |= 1; /* recalculate stiffness matrix */ /* insert in vertex list */ GRID_LINK_NODE(theGrid,pn,PrioMaster); return(pn); } /****************************************************************************/ /** \brief Return pointer to a new node structure on an edge * @param theGrid - grid where vertex should be inserted * @param FatherNode - node father This function creates and initializes a new node structure at the midpoint of an element edge and returns a pointer to it. @return
    • pointer to requested object
    • NULL if out of memory
    */ /****************************************************************************/ NODE *NS_DIM_PREFIX CreateSonNode (GRID *theGrid, NODE *FatherNode) { NODE *pn; VERTEX *theVertex; theVertex = MYVERTEX(FatherNode); pn = CreateNode(theGrid,theVertex,(GEOM_OBJECT *)FatherNode,CORNER_NODE); if (pn == NULL) return(NULL); SONNODE(FatherNode) = pn; #ifdef TOPNODE TOPNODE(theVertex) = pn; #endif return(pn); } /****************************************************************************/ /** \brief Return pointer to a new node structure on an edge * @param theGrid - grid where node should be inserted * @param theElement - pointer to an element * @param theVertex - pointer to vertex if already existing * @param edge - id of an element edge This function creates and initializes a new node structure at the midpoint of an element edge and returns a pointer to it. @return
    • pointer to requested object
    • NULL if out of memory
    */ /****************************************************************************/ NODE *NS_DIM_PREFIX CreateMidNode (GRID *theGrid, ELEMENT *theElement, VERTEX *theVertex, INT edge) { BNDP *bndp; DOUBLE *x[MAX_CORNERS_OF_ELEM]; DOUBLE_VECTOR bnd_global,global; DOUBLE diff; INT n,move; const INT co0 = CORNER_OF_EDGE(theElement,edge,0); const INT co1 = CORNER_OF_EDGE(theElement,edge,1); VERTEX* v0 = MYVERTEX(CORNER(theElement,co0)); VERTEX* v1 = MYVERTEX(CORNER(theElement,co1)); V_DIM_LINCOMB(0.5, CVECT(v0), 0.5, CVECT(v1), global); /* set MIDNODE pointer */ EDGE* theEdge = GetEdge(CORNER(theElement,co0),CORNER(theElement,co1)); ASSERT(theEdge!=NULL); /* allocate vertex */ const bool vertex_null = (theVertex==NULL); if (theVertex==NULL) { if ((OBJT(v0) == BVOBJ) && (OBJT(v1) == BVOBJ)) #ifdef UG_DIM_2 if (OBJT(theElement) == BEOBJ) if (SIDE_ON_BND(theElement,edge)) #endif #ifdef UG_DIM_3 if (EDSUBDOM(theEdge) == 0) #endif { bndp = BNDP_CreateBndP(MGHEAP(MYMG(theGrid)),V_BNDP(v0),V_BNDP(v1),0.5); if (bndp != NULL) { theVertex = CreateBoundaryVertex(theGrid); if (theVertex == NULL) return(NULL); if (BNDP_Global(bndp,bnd_global)) return(NULL); if (BNDP_BndPDesc(bndp,&move)) return(NULL); SETMOVE(theVertex,move); V_BNDP(theVertex) = bndp; V_DIM_COPY(bnd_global,CVECT(theVertex)); FieldVector& local = LCVECT(theVertex); V_DIM_EUKLIDNORM_OF_DIFF(bnd_global,global,diff); if (diff > MAX_PAR_DIST) { SETMOVED(theVertex,1); CORNER_COORDINATES(theElement,n,x); UG_GlobalToLocal(n,(const DOUBLE **)x,bnd_global,local); } else V_DIM_LINCOMB(0.5, LOCAL_COORD_OF_ELEM(theElement,co0), 0.5, LOCAL_COORD_OF_ELEM(theElement,co1),local); PRINTDEBUG(gm,1,("local = %f %f %f\n",local[0],local[1],local[2])); } } if (theVertex == NULL) { /* we need an inner vertex */ theVertex = CreateInnerVertex(theGrid); if (theVertex==NULL) return(NULL); V_DIM_COPY(global,CVECT(theVertex)); V_DIM_LINCOMB(0.5, LOCAL_COORD_OF_ELEM(theElement,co0), 0.5, LOCAL_COORD_OF_ELEM(theElement,co1), LCVECT(theVertex)); } VFATHER(theVertex) = theElement; SETONEDGE(theVertex,edge); } /* allocate node */ NODE* theNode = CreateNode(theGrid,theVertex,(GEOM_OBJECT *)theEdge,MID_NODE); if (theNode==NULL && vertex_null) { DisposeVertex(theGrid,theVertex); return(NULL); } MIDNODE(theEdge) = theNode; #ifdef TOPNODE if (TOPNODE(theVertex)==NULL || LEVEL(TOPNODE(theVertex))ppifContext().me(),ID_PRTX(theNode),NTYPE(theNode), OBJT(NFATHER(theNode)),NFATHER(theNode))); return(theNode); } NODE * NS_DIM_PREFIX GetMidNode (const ELEMENT *theElement, INT edge) { EDGE *theEdge; NODE *theNode; VERTEX *theVertex; theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,edge,0)), CORNER(theElement,CORNER_OF_EDGE(theElement,edge,1))); if (theEdge == NULL) return(NULL); theNode = MIDNODE(theEdge); if (theNode == NULL) return(NULL); /** \todo This is a bad place for the following code (s.l. 981015) */ theVertex = MYVERTEX(theNode); if (theVertex!=NULL && VFATHER(theVertex) == NULL) { /** \todo Strange that this cast has to be here. O.S. 060902 */ VFATHER(theVertex) = (ELEMENT*)theElement; SETONEDGE(theVertex,edge); V_DIM_LINCOMB(0.5, LOCAL_COORD_OF_ELEM(theElement, CORNER_OF_EDGE(theElement,edge,0)), 0.5, LOCAL_COORD_OF_ELEM(theElement, CORNER_OF_EDGE(theElement,edge,1)), LCVECT(theVertex)); } return(theNode); } /****************************************************************************/ /** \brief ??? */ /****************************************************************************/ static INT SideOfNbElement(const ELEMENT *theElement, INT side) { ELEMENT *nb; NODE *nd[MAX_CORNERS_OF_SIDE]; INT i,j,m,n,num; nb = NBELEM(theElement,side); if (nb == NULL) return(MAX_SIDES_OF_ELEM); for (j=0; j
  • pointer to requested object
  • NULL if out of memory
  • */ /****************************************************************************/ NODE *NS_DIM_PREFIX CreateSideNode (GRID *theGrid, ELEMENT *theElement, VERTEX *theVertex, INT side) { DOUBLE_VECTOR bnd_global,global; FieldVector local; DOUBLE *x[MAX_CORNERS_OF_ELEM]; NODE *theNode; BNDP *bndp; BNDS *bnds; DOUBLE fac, diff; INT n,j,k,move,vertex_null; n = CORNERS_OF_SIDE(theElement,side); fac = 1.0 / n; V_DIM_CLEAR(local); V_DIM_CLEAR(global); for (j=0; j bnd_local; if (n == 3) bnd_local[0] = bnd_local[1] = 0.33333333333333; else if (n == 4) bnd_local[0] = bnd_local[1] = 0.5; bndp = BNDS_CreateBndP(MGHEAP(MYMG(theGrid)),bnds,bnd_local); if (bndp != NULL) { theVertex = CreateBoundaryVertex(theGrid); if (theVertex == NULL) return(NULL); if (BNDP_BndPDesc(bndp,&move)) return(NULL); SETMOVE(theVertex,move); if (BNDP_Global(bndp,bnd_global)) return(NULL); V_BNDP(theVertex) = bndp; V_DIM_COPY(bnd_global,CVECT(theVertex)); V_DIM_EUKLIDNORM_OF_DIFF(bnd_global,global,diff); if (diff > MAX_PAR_DIST) { SETMOVED(theVertex,1); CORNER_COORDINATES(theElement,k,x); UG_GlobalToLocal(k,(const DOUBLE **)x,bnd_global,local); PRINTDEBUG(gm,1,("local = %f %f %f\n",local[0],local[1],local[2])); } } } } if (theVertex == NULL) { theVertex = CreateInnerVertex(theGrid); if (theVertex == NULL) return(NULL); V_DIM_COPY(global,CVECT(theVertex)); } VFATHER(theVertex) = theElement; SETONSIDE(theVertex,side); SETONNBSIDE(theVertex,SideOfNbElement(theElement,side)); V_DIM_COPY(local,LCVECT(theVertex)); } /* create node */ theNode = CreateNode(theGrid,theVertex, (GEOM_OBJECT *)theElement,SIDE_NODE); if (theNode==NULL && vertex_null) { DisposeVertex(theGrid,theVertex); return(NULL); } #ifdef TOPNODE if (TOPNODE(theVertex) == NULL || LEVEL(TOPNODE(theVertex))status |= 1; return(theNode); } static NODE *GetSideNodeX (const ELEMENT *theElement, INT side, INT n, NODE **MidNodes) { ELEMENT *theFather; NODE *theNode; VERTEX *theVertex; LINK *theLink0,*theLink1,*theLink2,*theLink3; DOUBLE fac; INT i; if (n == 4) { for (theLink0=START(MidNodes[0]); theLink0!=NULL; theLink0=NEXT(theLink0)) { theNode = NBNODE(theLink0); if (NTYPE(theNode) != SIDE_NODE) continue; for (theLink1=START(MidNodes[1]); theLink1!=NULL; theLink1=NEXT(theLink1)) { if (theNode != NBNODE(theLink1)) continue; for (theLink2=START(MidNodes[2]); theLink2!=NULL; theLink2=NEXT(theLink2)) { if (theNode != NBNODE(theLink2)) continue; for (theLink3=START(MidNodes[3]); theLink3!=NULL; theLink3=NEXT(theLink3)) { if (theNode != NBNODE(theLink3)) continue; theVertex = MYVERTEX(theNode); theFather = VFATHER(theVertex); if (theFather == theElement) { #ifndef ModelP /* HEAPFAULT in theFather possible, if in a previous call of DisposeElement some son is not reached by GetAllSons */ assert(ONSIDE(theVertex) == side); #endif SETONSIDE(theVertex,side); return(theNode); } else if (theFather == NBELEM(theElement,side)) { SETONNBSIDE(theVertex,side); return(theNode); } else if (theFather == NULL) { /** \todo Strange that this cast has to be here */ VFATHER(theVertex) = (ELEMENT*)theElement; SETONSIDE(theVertex,side); SETONNBSIDE(theVertex, SideOfNbElement(theElement,side)); fac = 1.0 / n; Dune::FieldVector& local = LCVECT(theVertex); V_DIM_CLEAR(local); for (i=0; i& local = LCVECT(theVertex); V_DIM_CLEAR(local); for (i=0; i
  • pointer to center node
  • NULL no node found
  • */ /****************************************************************************/ NODE * NS_DIM_PREFIX GetCenterNode (const ELEMENT *theElement) { INT i,j; NODE *theNode; ELEMENT *SonList[MAX_SONS],*theSon; #ifdef __CENTERNODE__ return(CENTERNODE(theElement)); #endif theNode = NULL; if (GetAllSons(theElement,SonList) != GM_OK) assert(0); for (i=0; i *
  • pointer to new node
  • *
  • NULL: could not allocate
  • */ /****************************************************************************/ /* #define MOVE_MIDNODE */ NODE * NS_DIM_PREFIX CreateCenterNode (GRID *theGrid, ELEMENT *theElement, VERTEX *theVertex) { DOUBLE_VECTOR diff; INT n,j,moved,vertex_null; VERTEX *VertexOnEdge[MAX_EDGES_OF_ELEM]; NODE *theNode; EDGE *theEdge; DOUBLE fac; DOUBLE *x[MAX_CORNERS_OF_ELEM]; #ifdef MOVE_MIDNODE #ifndef ModelP DOUBLE len_opp,len_bnd; #endif #endif /* check if moved side nodes exist */ CORNER_COORDINATES(theElement,n,x); moved = 0; vertex_null = (theVertex==NULL); if (theVertex==NULL && OBJT(theElement) == BEOBJ) { for (j=0; jstatus |= 1; if (!vertex_null) return(theNode); FieldVector& global = CVECT(theVertex); FieldVector& local = LCVECT(theVertex); V_DIM_CLEAR(local); fac = 1.0 / n; for (j=0; j
  • GM_OK if ok
  • != GM_OK if not ok
  • */ /****************************************************************************/ INT NS_DIM_PREFIX GetNodeContext (const ELEMENT *theElement, NODE **theElementContext) { NODE *theNode, **MidNodes, **CenterNode; EDGE *theEdge; INT i,Corner0, Corner1; #ifdef UG_DIM_3 NODE **SideNodes; #endif /* reset context */ for(i=0; i
  • pointer to specified object
  • NULL if not found
  • */ /****************************************************************************/ EDGE * NS_DIM_PREFIX GetSonEdge (const EDGE *theEdge) { EDGE *SonEdge=NULL; NODE *Node0,*Node1,*SonNode0,*SonNode1; Node0 = NBNODE(LINK0(theEdge)); Node1 = NBNODE(LINK1(theEdge)); SonNode0 = SONNODE(Node0); SonNode1 = SONNODE(Node1); if (SonNode0!=NULL && SonNode1!=NULL) SonEdge = GetEdge(SonNode0,SonNode1); return(SonEdge); } /****************************************************************************/ /** \brief Return pointer to son edges if it exists * @param theEdge - edge for which son is searched * @param SonEdges - array of pointers will be filled with son edges This function returns the pointer to the son edges if existing. @return
    • number of found edges (0,1,2)
    */ /****************************************************************************/ INT NS_DIM_PREFIX GetSonEdges (const EDGE *theEdge, EDGE *SonEdges[MAX_SON_EDGES]) { INT nedges; NODE *Node0,*Node1,*SonNode0,*SonNode1,*MidNode; nedges = 0; SonEdges[0] = NULL; SonEdges[1] = NULL; Node0 = NBNODE(LINK0(theEdge)); Node1 = NBNODE(LINK1(theEdge)); if (GID(Node0)
  • pointer to specified object
  • NULL if not found
  • */ /****************************************************************************/ EDGE * NS_DIM_PREFIX GetFatherEdge (const EDGE *theEdge) { NODE *theNode0 = NBNODE(LINK0(theEdge)); NODE *theNode1 = NBNODE(LINK1(theEdge)); EDGE *FatherEdge = NULL; /* one node is center node -> no father edge */ if (CENTERTYPE(theNode0) || CENTERTYPE(theNode1)) return(NULL); #ifdef UG_DIM_3 /* one node is side node -> no father edge */ if (SIDETYPE(theNode0) || SIDETYPE(theNode1)) return(NULL); #endif /* both nodes are mid nodes -> no father edge */ if (MIDTYPE(theNode0) && MIDTYPE(theNode1)) return(NULL); /* one node is mid node -> no father edge */ if (MIDTYPE(theNode0) || MIDTYPE(theNode1)) { NODE *FatherNode0,*FatherNode1, *theNode; if (MIDTYPE(theNode1)) { theNode = theNode0; theNode0 = theNode1; theNode1 = theNode; } FatherEdge = (EDGE *) NFATHER(theNode0); if (FatherEdge == NULL) return(NULL); FatherNode0 = NBNODE(LINK0(FatherEdge)); FatherNode1 = NBNODE(LINK1(FatherEdge)); if (SONNODE(FatherNode0)==theNode1 || SONNODE(FatherNode1)==theNode1) return(FatherEdge); else return(NULL); } /* both nodes are corner nodes -> try to get the edge */ if (CORNERTYPE(theNode0) && CORNERTYPE(theNode1)) { if (NFATHER(theNode0)!=NULL && NFATHER(theNode1)!=NULL) return(GetEdge(NFATHER(theNode0),NFATHER(theNode1))); else return(NULL); } /* No father available */ return NULL; } #ifdef UG_DIM_3 /****************************************************************************/ /** \brief Return pointer to father edge if it exists * @param SideNodes - nodes of the side * @param ncorners - number of sidenodes * @param Nodes - corners of edge for which father is searched * @param theEdge - edge for which father is searched This function returns the pointer to the father edge if it exists. @return
    • pointer to specified object
    • NULL if not found
    */ /****************************************************************************/ EDGE * NS_DIM_PREFIX FatherEdge (NODE **SideNodes, INT ncorners, NODE **Nodes, EDGE *theEdge) { INT pos0,pos1; EDGE *fatherEdge = NULL; ASSERT(Nodes[0]!=NULL); ASSERT(Nodes[1]!=NULL); /* one node is side node -> no father edge */ if (NTYPE(Nodes[0])==SIDE_NODE || NTYPE(Nodes[1])==SIDE_NODE) return(NULL); /* both nodes are side nodes -> no father edge */ if (NTYPE(Nodes[0])==MID_NODE && NTYPE(Nodes[1])==MID_NODE) return(NULL); for (pos0=0; pos0=ncorners); ASSERT(pos0<2*ncorners); if ((pos0+1)%ncorners == pos1) { ASSERT(OBJT(NFATHER(SideNodes[pos0%ncorners])) == NDOBJ); fatherEdge = GetEdge((NODE *)NFATHER(SideNodes[pos0%ncorners]), (NODE *)NFATHER(Nodes[1])); ASSERT(fatherEdge!=NULL); } if (pos0%ncorners == pos1) { ASSERT(OBJT(NFATHER(SideNodes[(pos0+1)%ncorners])) == NDOBJ); fatherEdge = GetEdge((NODE *)NFATHER(SideNodes[(pos0+1)%ncorners]), (NODE *)NFATHER(Nodes[1])); ASSERT(fatherEdge!=NULL); } break; case (SIDE_NODE) : /* this edge has no father edge */ fatherEdge = NULL; break; default : assert(0); break; } IFDEBUG(dddif,1) INT i; EDGE* edge0, *edge1; edge0 = edge1 = NULL; /* test whether theEdge lies above fatherEdge */ if (fatherEdge!=NULL) { if (MIDNODE(fatherEdge)!=NULL) { edge0 = GetEdge(MIDNODE(fatherEdge),SONNODE(NBNODE(LINK0(fatherEdge)))); edge1 = GetEdge(MIDNODE(fatherEdge),SONNODE(NBNODE(LINK1(fatherEdge)))); } else edge0 = GetEdge(SONNODE(NBNODE(LINK0(fatherEdge))), SONNODE(NBNODE(LINK1(fatherEdge)))); IFDEBUG(dddif,5) UserWriteF("fatherEdge=%x theEdge=%x edge0=%x edge1=%x\n", fatherEdge,theEdge,edge0,edge1); UserWriteF("Nodes[0]=%d Nodes[1]=%d\n",ID(Nodes[0]),ID(Nodes[1])); UserWriteF("SideNodes\n"); for (i=0; i
  • pointer to specified object
  • NULL if not found
  • */ /****************************************************************************/ EDGE * NS_DIM_PREFIX GetEdge (const NODE *from, const NODE *to) { LINK *pl; /* run through neighbor list */ for (pl=START(from); pl!=NULL; pl = NEXT(pl)) if (NBNODE(pl)==to) return(MYEDGE(pl)); /* return not found */ return(NULL); } /****************************************************************************/ /** \brief Return pointer to a new edge structure * @param theGrid - grid where vertex should be inserted * @param theElement - pointer to element * @param edge - number of edge * @param with_vector - also create vector for edge (true/false) This function returns a pointer to a new edge structure. @return
    • pointer to requested object
    • NULL if out of memory
    */ /****************************************************************************/ #ifndef ModelP static #endif EDGE * #ifdef ModelP NS_DIM_PREFIX #endif CreateEdge (GRID *theGrid, ELEMENT *theElement, INT edge, bool with_vector) { ELEMENT *theFather; EDGE *pe,*father_edge; NODE *from,*to,*n1,*n2; LINK *link0,*link1; #ifdef UG_DIM_3 VERTEX *theVertex; NODE *nbn1,*nbn2,*nbn3,*nbn4; INT sc,found,side,k,j; #endif from = CORNER(theElement,CORNER_OF_EDGE(theElement,edge,0)); to = CORNER(theElement,CORNER_OF_EDGE(theElement,edge,1)); /* check if edge exists already */ if( (pe = GetEdge(from, to)) != NULL ) { if (NO_OF_ELEM(pe)mg,sizeof(EDGE)-sizeof(VECTOR*),EDOBJ); if (pe==NULL) return(NULL); /* initialize data */ link0 = LINK0(pe); link1 = LINK1(pe); SETOBJT(pe,EDOBJ); SETLOFFSET(link0,0); SETLOFFSET(link1,1); pe->id = (theGrid->mg->edgeIdCounter)++; SETLEVEL(pe,GLEVEL(theGrid)); #ifdef ModelP DDD_AttrSet(PARHDR(pe), GRID_ATTR(theGrid)); /* SETPRIO(pe,PrioMaster); */ #endif #ifdef IDENT_ONLY_NEW if (GET_IDENT_MODE() == IDENT_ON) SETNEW_EDIDENT(pe,1); #endif UGM_CDBG(pe, UserWriteF(PFMT "create edge=" EDID_FMTX " from=" ID_FMTX "tf=%d to=" ID_FMTX "tt=%d" "elem=" EID_FMTX "edge=%d\n", theGrid->ppifContext().me(),EDID_PRTX(pe),ID_PRTX(from),NTYPE(from),ID_PRTX(to),NTYPE(to), EID_PRTX(theElement),edge); if (0) UserWriteF(PFMT "nfatherf=" ID_FMTX "nfathert=" ID_FMTX " fatheredge=" EDID_FMTX "\n", theGrid->ppifContext().me(),ID_PRTX((NODE*)NFATHER(from)),ID_PRTX((NODE*)NFATHER(to)), EDID_PRTX(GetEdge((NODE*)NFATHER(from),(NODE*)NFATHER(to))));) NBNODE(link0) = to; NBNODE(link1) = from; SET_NO_OF_ELEM(pe,1); SETEDGENEW(pe,1); /* set edge-subdomain from topological information with respect to father-element */ SETEDSUBDOM(pe,SUBDOMAIN(theElement)); theFather = EFATHER(theElement); if (theFather!=NULL) { SETEDSUBDOM(pe,SUBDOMAIN(theFather)); if (NTYPE(from)=0 && (OBJT(theFather)==BEOBJ) && SIDE_ON_BND(theFather,side)) SETEDSUBDOM(pe,0); } break; case (MID_NODE | (MID_NODE<<4)) : father_edge = NFATHEREDGE(n1); assert(father_edge!=NULL); nbn1 = NBNODE(LINK0(father_edge)); nbn2 = NBNODE(LINK1(father_edge)); father_edge = NFATHEREDGE(n2); assert(father_edge!=NULL); nbn3 = NBNODE(LINK0(father_edge)); nbn4 = NBNODE(LINK1(father_edge)); /* do all nodes nbn1, nbn2, nbn3, nbn4 ly on the same side of father? */ side=-1; for (j=0; j=0 && (OBJT(theFather)==BEOBJ) && SIDE_ON_BND(theFather,side)) SETEDSUBDOM(pe,0); break; case (CORNER_NODE | (SIDE_NODE<<4)) : theVertex = MYVERTEX(n2); if (VFATHER(theVertex) == theFather) side = ONSIDE(theVertex); else side = ONNBSIDE(theVertex); if ((OBJT(theFather)==BEOBJ) && SIDE_ON_BND(theFather,side)) for (k=0; k
  • pointer to specified link
  • NULL if not found.
  • */ /****************************************************************************/ LINK *GetLink (const NODE *from, const NODE *to) { LINK *pl; /* run through neighbor list */ for (pl=START(from); pl!=NULL; pl = NEXT(pl)) if (NBNODE(pl)==to) return(pl); /* return not found */ return(NULL); } /****************************************************************************/ /** \brief Return a pointer to a new element structure * @param theGrid - grid structure to extend * @param tag - the element type * @param objtype - inner element (IEOBJ) or boundary element (BEOBJ) * @param nodes - list of corner nodes in reference numbering * @param Father - pointer to father element (NULL on base level) * @param with_vector - This function creates and initializes a new element and returns a pointer to it. @return
    • pointer to requested object
    • NULL if out of memory
    */ /****************************************************************************/ ELEMENT * NS_DIM_PREFIX CreateElement (GRID *theGrid, INT tag, INT objtype, NODE **nodes, ELEMENT *Father, bool with_vector) { ELEMENT *pe; INT i,s_id; if (objtype == IEOBJ) pe = (ELEMENT*)GetMemoryForObject(MYMG(theGrid),INNER_SIZE_TAG(tag), MAPPED_INNER_OBJT_TAG(tag)); else if (objtype == BEOBJ) pe = (ELEMENT*)GetMemoryForObject(MYMG(theGrid),BND_SIZE_TAG(tag), MAPPED_BND_OBJT_TAG(tag)); else std::abort(); if (pe==NULL) return(NULL); /* initialize data */ SETNEWEL(pe,1); SETOBJT(pe,objtype); SETTAG(pe,tag); SETLEVEL(pe,theGrid->level); #ifdef ModelP DDD_AttrSet(PARHDRE(pe),GRID_ATTR(theGrid)); /* SETEPRIO(theGrid->dddContext(), pe,PrioMaster); */ PARTITION(pe) = theGrid->ppifContext().me(); #endif ID(pe) = (theGrid->mg->elemIdCounter)++; /* subdomain id */ s_id = (Father != NULL) ? SUBDOMAIN(Father) : 0; SETSUBDOMAIN(pe,s_id); #ifdef __CENTERNODE__ SET_CENTERNODE(pe,NULL); #endif SET_EFATHER(pe,Father); /* set corner nodes */ for (i=0; ilevel>0) { INT where = PRIO2INDEX(PrioMaster); #ifndef ModelP ASSERT(Father != NULL); #endif if (Father != NULL) { if (SON(Father,where) == NULL) SET_SON(Father,where,pe); SETNSONS(Father,NSONS(Father)+1); } } /* return ok */ return(pe); } /****************************************************************************/ /** \brief Creates the element sides of son elements * @param theGrid - grid for which to create * @param theElement - pointer to a boundary element * @param side - side id of a side of the element * @param theSon - pointer to a son element * @param son_side - side id of a side of the son This function creates and initializes an element side of a son element. Here also the side vector (iff at all) is inspected in 'ReinspectSonSideVector'. The latter function eventually reallocates the vector if its size has changed. @return
    • GM_OK if ok
    • GM_ERROR when error occurred.
    */ /****************************************************************************/ INT NS_DIM_PREFIX CreateSonElementSide (GRID *theGrid, ELEMENT *theElement, INT side, ELEMENT *theSon, INT son_side) { INT n,i; BNDS *bnds; BNDP *bndp[MAX_CORNERS_OF_ELEM]; ASSERT (OBJT(theElement) == BEOBJ); ASSERT (ELEM_BNDS(theElement,side) != NULL); /* check if Edges of theElement, which are on the side 'side' have EDSUBDOM 0 */ n = CORNERS_OF_SIDE(theElement,side); for (i=0; ippifContext().me(),EID_PRTX(theElement),EID_PRTX(theSon),VID_PRTX(MYVERTEX(CORNER(theSon,CORNER_OF_SIDE(theSon,son_side,i))))); printf(PFMT "NTYPE = MID_NODE\n",theGrid->ppifContext().me()); theFatherEdge = NFATHEREDGE(theNode); printf(PFMT "EDSUBDOM = %d\n",theGrid->ppifContext().me(),(int)EDSUBDOM(theFatherEdge)); t1 = (OBJT(MYVERTEX(NBNODE(LINK0(theFatherEdge))))==BVOBJ); t2 = (OBJT(MYVERTEX(NBNODE(LINK1(theFatherEdge))))==BVOBJ); printf(PFMT "BVOBJ(theFatherEdge): %d %d\n",theGrid->ppifContext().me(),(int)t1,(int)t2); break; case SIDE_NODE : printf("NTYPE = SIDE_NODE"); break; case CENTER_NODE : printf("NTYPE = CENTER_NODE"); break; } ASSERT(0); } bndp[i] = V_BNDP(MYVERTEX(CORNER(theSon,CORNER_OF_SIDE(theSon,son_side,i)))); } bnds = BNDP_CreateBndS(MGHEAP(MYMG(theGrid)),bndp,n); if (bnds == NULL) RETURN(GM_ERROR); SET_BNDS(theSon,son_side,bnds); #ifdef UG_DIM_2 const EDGE* theEdge = GetEdge(CORNER(theSon,CORNER_OF_EDGE(theSon,son_side,0)), CORNER(theSon,CORNER_OF_EDGE(theSon,son_side,1))); ASSERT(theEdge != NULL); SETEDSUBDOM(theEdge,0); #endif #ifdef UG_DIM_3 /** \todo is this necessary? for (i=0; i
  • pointer to requested object
  • NULL if out of memory
  • */ /****************************************************************************/ GRID * NS_DIM_PREFIX CreateNewLevel (MULTIGRID *theMG) { GRID *theGrid; if (TOPLEVEL(theMG)+1>=MAXLEVEL) return(NULL); INT l = TOPLEVEL(theMG)+1; /* allocate grid object */ theGrid = (GRID*)GetMemoryForObject(theMG,sizeof(GRID),GROBJ); if (theGrid==NULL) return(NULL); /* fill in data */ CTRL(theGrid) = 0; SETOBJT(theGrid,GROBJ); GLEVEL(theGrid) = l; NE(theGrid) = 0; /* other counters are init in INIT fcts below */ GSTATUS(theGrid,0); GRID_INIT_ELEMENT_LIST(theGrid); GRID_INIT_NODE_LIST(theGrid); GRID_INIT_VERTEX_LIST(theGrid); GRID_INIT_VECTOR_LIST(theGrid); if (l>0) { DOWNGRID(theGrid) = GRID_ON_LEVEL(theMG,l-1); UPGRID(GRID_ON_LEVEL(theMG,l-1)) = theGrid; UPGRID(theGrid) = NULL; } else if (l==0) { DOWNGRID(theGrid) = NULL; UPGRID(theGrid) = NULL; } else { UPGRID(theGrid) = GRID_ON_LEVEL(theMG,l+1); DOWNGRID(theGrid) = NULL; DOWNGRID(GRID_ON_LEVEL(theMG,l+1)) = theGrid; } MYMG(theGrid) = theMG; GRID_ON_LEVEL(theMG,l) = theGrid; TOPLEVEL(theMG) = l; return(theGrid); } /****************************************************************************/ /** \brief Create a multigrid environment item * @param name - name of the multigrid This function creates a multigrid environment directory. @return
    • pointer to new MULTIGRID
    • NULL if error occurred
    */ /****************************************************************************/ MULTIGRID * NS_DIM_PREFIX MakeMGItem (const char *name, std::shared_ptr ppifContext) { MULTIGRID *theMG; if (ChangeEnvDir("/Multigrids") == NULL) return (NULL); if (strlen(name)>=NAMESIZE || strlen(name)<=1) return (NULL); theMG = (MULTIGRID *) MakeEnvItem(name,theMGDirID,sizeof(MULTIGRID)); if (theMG == NULL) return(NULL); new(theMG) multigrid; #if ModelP theMG->ppifContext_ = ppifContext; theMG->dddContext_ = std::make_shared( theMG->ppifContext_, std::make_shared() ); InitDDD(theMG->dddContext()); globalDDDContext(theMG->dddContext_); #else theMG->ppifContext_ = std::make_shared(); #endif return (theMG); } /****************************************************************************/ /** \todo Please doc me! * @param theMG * @param FromLevel * @param ToLevel * @param mask DESCRIPTION: @return INT */ /****************************************************************************/ INT NS_DIM_PREFIX ClearMultiGridUsedFlags (MULTIGRID *theMG, INT FromLevel, INT ToLevel, INT mask) { int i,level,elem,node,edge,vertex,vector; GRID *theGrid; ELEMENT *theElement; NODE *theNode; EDGE *theEdge; VECTOR *theVector; elem = mask & MG_ELEMUSED; node = mask & MG_NODEUSED; edge = mask & MG_EDGEUSED; vertex = mask & MG_VERTEXUSED; vector = mask & MG_VECTORUSED; for (level=FromLevel; level<=ToLevel; level++) { theGrid = GRID_ON_LEVEL(theMG,level); if (elem || edge) for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (elem) SETUSED(theElement,0); if (edge) { for (i=0; i
  • pointer to MULTIGRID
  • NULL if not found.
  • */ /****************************************************************************/ MULTIGRID * NS_DIM_PREFIX GetMultigrid (const char *name) { return ((MULTIGRID *) SearchEnv(name,"/Multigrids", theMGDirID,theMGRootDirID)); } /****************************************************************************/ /** \brief Return a pointer to the first multigrid This function returns a pointer to the first multigrid in the /Multigrids directory. @return
    • pointer to MULTIGRID
    • NULL if not found.
    */ /****************************************************************************/ MULTIGRID * NS_DIM_PREFIX GetFirstMultigrid () { ENVDIR *theMGRootDir; MULTIGRID *theMG; theMGRootDir = ChangeEnvDir("/Multigrids"); assert (theMGRootDir!=NULL); theMG = (MULTIGRID *) ENVDIR_DOWN(theMGRootDir); if (theMG != NULL) { #ifdef ModelP InitCurrMG(theMG); #endif } return (theMG); } /****************************************************************************/ /** \brief Return a pointer to the next multigrid * @param theMG - multigrid structure This function returns a pointer to the next multigrid in the /Multigrids directory. @return
    • pointer to MULTIGRID
    • NULL if not found.
    */ /****************************************************************************/ MULTIGRID * NS_DIM_PREFIX GetNextMultigrid (const MULTIGRID *theMG) { MULTIGRID *MG; MG = (MULTIGRID *) NEXT_ENVITEM(theMG); if (MG != NULL) { #ifdef ModelP InitCurrMG(MG); #endif } return (MG); } /****************************************************************************/ /** \brief Return a pointer to new multigrid structure * @param MultigridName - name of multigrid * @param domain - name of domain description from environment * @param problem - name of problem description from environment * @param format - name of format description from environment * @param optimizedIE - allocate NodeElementList This function creates and initializes a new multigrid structure including allocation of heap, combining the domain and the boundary conditions and creation of the fixed corners of the domain. @return
    • pointer to new object
    • NULL if an error occurred.
    */ /****************************************************************************/ MULTIGRID * NS_DIM_PREFIX CreateMultiGrid (char *MultigridName, STD_BVP *theBVP, const char *format, INT optimizedIE, INT insertMesh, std::shared_ptr ppifContext) { HEAP *theHeap; MULTIGRID *theMG; INT i; MESH mesh; INT MarkKey; if (not ppifContext) ppifContext = std::make_shared(); /* allocate multigrid envitem */ theMG = MakeMGItem(MultigridName, ppifContext); if (theMG==NULL) return(NULL); #ifdef ModelP InitCurrMG(theMG); #endif /* allocate the heap */ /* When using the system heap: allocate just enough memory for the actual bookkeeping data structure */ theHeap = NewHeap(SIMPLE_HEAP, sizeof(HEAP), malloc(sizeof(HEAP))); if (theHeap==NULL) { UserWriteF("CreateMultiGrid: cannot allocate %ld bytes\n", sizeof(HEAP)); PrintErrorMessage('E', "CreateMultiGrid","Cannot allocate heap!"); DisposeMultiGrid(theMG); return(NULL); } /* mark temp memory here, release it after coarse grid construction in FixCoarseGrid */ MarkTmpMem(theHeap,&MarkKey); MG_MARK_KEY(theMG) = MarkKey; if (insertMesh) BVP_Init(theBVP,theHeap,&mesh,MarkKey); else BVP_Init(theBVP,theHeap,NULL,MarkKey); if (theBVP==NULL) { PrintErrorMessage('E',"CreateMultiGrid","BVP not found"); return(NULL); } theMG->BVP_Name = "dummy BVP name"; /* 1: general user data space */ // As we are using this version only with DUNE, we will never have UG user data /* 2: user heap */ // As we are using this version only with DUNE, we will never need the user heap /* fill multigrid structure */ theMG->status = 0; MG_COARSE_FIXED(theMG) = 0; theMG->vertIdCounter = 0; theMG->nodeIdCounter = 0; theMG->elemIdCounter = 0; theMG->edgeIdCounter = 0; #ifndef ModelP theMG->vectorIdCounter = 0; #endif theMG->topLevel = -1; MG_BVP(theMG) = theBVP; RESETMGSTATUS(theMG); theMG->theHeap = theHeap; for (i=0; ippifContext().isMaster()) { #endif if (InsertMesh(theMG,&mesh)) { DisposeMultiGrid(theMG); return(NULL); } #ifdef ModelP } #endif ASSERT(mesh.mesh_status!=MESHSTAT_NOTINIT); if (mesh.mesh_status==MESHSTAT_MESH) if (FixCoarseGrid(theMG)) { DisposeMultiGrid(theMG); return(NULL); } } /* return ok */ return(theMG); } /****************************************************************************/ /** \brief Remove edge from the data structure * @param theGrid - grid to remove from * @param theEdge - edge to remove This function remove an edge from the data structure including its vector (if one) and inserts them into the free list. @return
    • 0 if ok
    • 1 if an error occurred.
    */ /****************************************************************************/ static INT DisposeEdge (GRID *theGrid, EDGE *theEdge) { LINK *link0,*link1,*pl; NODE *from,*to; INT found; /* reconstruct data */ link0 = LINK0(theEdge); link1 = LINK1(theEdge); from = NBNODE(link1); to = NBNODE(link0); found = 0; /* delete link0 in from vertex */ if (START(from)==link0) { START(from) = NEXT(link0); found++; } else { for (pl=START(from); pl!=NULL; pl = NEXT(pl)) { if (NEXT(pl)==link0) { NEXT(pl) = NEXT(link0); found++; break; } } } /* delete link1 in to vertex */ if (START(to)==link1) { START(to) = NEXT(link1); found++; } else { for (pl=START(to); pl!=NULL; pl = NEXT(pl)) { if (NEXT(pl)==link1) { NEXT(pl) = NEXT(link1); found++; break; } } } /* reset pointer of midnode to edge */ if (MIDNODE(theEdge) != NULL) SETNFATHER(MIDNODE(theEdge),NULL); PutFreeObject(theGrid->mg,theEdge,sizeof(EDGE)-sizeof(VECTOR*),EDOBJ); /* check error condition */ if (found!=2) RETURN(1); /* return ok */ NE(theGrid)--; return(0); } /****************************************************************************/ /** \brief Remove node including its edges from the data structure * @param theGrid - grid to remove from * @param theNode - node to remove This function removes node including its edges and vector (if one) from the data structure and inserts all objects into the free list. @return
    • 0 if ok
    • 1 when error occurred.
    */ /****************************************************************************/ INT NS_DIM_PREFIX DisposeNode (GRID *theGrid, NODE *theNode) { VERTEX *theVertex; GEOM_OBJECT *father; /* call DisposeElement first! */ assert(START(theNode) == NULL); #ifdef ModelP if (SONNODE(theNode) != NULL) { SETNFATHER(SONNODE(theNode),NULL); } #else assert(SONNODE(theNode) == NULL); #endif /* remove node from node list */ GRID_UNLINK_NODE(theGrid,theNode); theVertex = MYVERTEX(theNode); father = (GEOM_OBJECT *)NFATHER(theNode); if (father != NULL) { switch (NTYPE(theNode)) { case (CORNER_NODE) : ASSERT(OBJT(father) == NDOBJ); SONNODE((NODE *)father) = NULL; #ifdef TOPNODE if (theVertex != NULL) TOPNODE(theVertex) = (NODE *)father; #endif break; case (MID_NODE) : ASSERT(OBJT(father) == EDOBJ); MIDNODE((EDGE *)father) = NULL; break; #ifdef __CENTERNODE__ case (CENTER_NODE) : ASSERT(OBJT(father)==IEOBJ || OBJT(father)==BEOBJ); SET_CENTERNODE((ELEMENT *)father,NULL); break; #endif default : ASSERT(0); break; } } /** \todo delete old vertex handling */ if (0) if (theVertex != NULL) { #ifdef ModelP /* vertices have to be linked and unlinked */ /* relative to the level they are created for */ INT levelofvertex = LEVEL(theVertex); MULTIGRID *MG = MYMG(theGrid); GRID *GridOfVertex = GRID_ON_LEVEL(MG,levelofvertex); if (SONNODE(theNode) == NULL) DisposeVertex(GridOfVertex,theVertex); #else DisposeVertex(theGrid,theVertex); #endif } if (NOOFNODE(theVertex)<1) RETURN(GM_ERROR); if (NOOFNODE(theVertex)==1) DisposeVertex(theGrid,theVertex); else DECNOOFNODE(theVertex); #ifdef ModelP /* free message buffer */ theNode->message_buffer_free(); #endif PutFreeObject(theGrid->mg,theNode,sizeof(NODE),NDOBJ); /* return ok */ return(0); } /****************************************************************************/ /** \brief Remove vertex from the data structure * @param theGrid - grid to remove from * @param theVertex - vertex to remove This function removes a vertex from the data structure and puts it into the free list. @return
    • 0 if ok
    • 1 no valid object number
    */ /****************************************************************************/ static INT DisposeVertex (GRID *theGrid, VERTEX *theVertex) { // The following call to HEAPFAULT triggers a failing assertion in some // distributed settings. I don't know whether this is the sign of a hidden bug // somewhere, or whether HEAPFAULT is an obsolete left-over of UG3's // hand-written manual memory heap. //HEAPFAULT(theVertex); PRINTDEBUG(gm,1,(PFMT "DisposeVertex(): Gridlevel=%d theVertex=" VID_FMTX "\n", theGrid->ppifContext().me(),GLEVEL(theGrid),VID_PRTX(theVertex))); theGrid = GRID_ON_LEVEL(MYMG(theGrid),LEVEL(theVertex)); /* remove vertex from vertex list */ GRID_UNLINK_VERTEX(theGrid,theVertex); if( OBJT(theVertex) == BVOBJ ) { BNDP_Dispose(MGHEAP(MYMG(theGrid)),V_BNDP(theVertex)); PutFreeObject(MYMG(theGrid),theVertex,sizeof(struct bvertex),BVOBJ); } else PutFreeObject(MYMG(theGrid),theVertex,sizeof(struct ivertex),IVOBJ); return(0); } /****************************************************************************/ /** \brief Remove element from the data structure * @param theGrid - grid to remove from * @param theElement - element to remove This function removes an element from the data structure and inserts it into the free list. This includes all elementsides, sidevectors and the elementvector if they exist. @return
    • 0 if ok
    • 1 no valid object number.
    */ /****************************************************************************/ INT NS_DIM_PREFIX DisposeElement (GRID *theGrid, ELEMENT *theElement) { INT j,tag; NODE *theNode; VERTEX *theVertex; EDGE *theEdge; BNDS *bnds; ELEMENT *theFather; ELEMENT *succe = SUCCE(theElement); #ifdef UG_DIM_3 VECTOR *theVector; DOUBLE fac; INT k,m,o,l; #endif GRID_UNLINK_ELEMENT(theGrid,theElement); #ifdef __CENTERNODE__ { theNode = CENTERNODE(theElement); if (theNode != NULL) SETNFATHER(theNode,NULL); } #endif theFather = EFATHER(theElement); if (LEVEL(theElement)>0) { #ifndef ModelP ASSERT(theFather != NULL); #endif /* check intergrid pointer from father */ if (theFather != NULL) { #ifdef ModelP int index = PRIO2INDEX(EPRIO(theElement)); #else int index = 0; #endif ELEMENT *Next = NULL; ASSERT(index!=-1 && index<2); if (SON(theFather,index) == theElement) { if (succe != NULL) { if (EFATHER(succe)==theFather) #ifdef ModelP if (PRIO2INDEX(EPRIO(succe)) == PRIO2INDEX(EPRIO(theElement))) #endif { Next = succe; } } SET_SON(theFather,index,Next); } SETNSONS(theFather,NSONS(theFather)-1); PRINTDEBUG(gm,2,(PFMT "DisposeElement(): elem=" EID_FMTX " father=" EID_FMTX " son0=%x son1=%x\n", theGrid->ppifContext().me(),EID_PRTX(theElement),EID_PRTX(theFather), SON(theFather,0),SON(theFather,1))); } } #ifdef ModelP /* reset father pointers of sons */ /** \todo possibly some son cannot be reached by GetAllSons, */ /* because their father has not been on this proc and */ /* they lost their father pointers */ if (NSONS(theElement)>0) { ELEMENT *SonList[MAX_SONS]; if (GetAllSons(theElement,SonList)) RETURN(GM_FATAL); INT i = 0; while (ippifContext().me(),EID_PRTX(theElement),EID_PRTX(SonList[i]))); SET_EFATHER(SonList[i],NULL); /* reset VFATHER of centernode vertex */ for (j=0; j& local = LCVECT(theVertex); fac = 1.0 / m; V_DIM_CLEAR(local); for (o=0; omessage_buffer_free(); #endif /* dispose element */ /* give it a new tag ! (I know this is somewhat ugly) */ tag = TAG(theElement); if (OBJT(theElement)==BEOBJ) { SETOBJT(theElement,MAPPED_BND_OBJT_TAG(tag)); PutFreeObject(theGrid->mg,theElement, BND_SIZE_TAG(tag),MAPPED_BND_OBJT_TAG(tag)); } else { SETOBJT(theElement,MAPPED_INNER_OBJT_TAG(tag)); PutFreeObject(theGrid->mg,theElement,INNER_SIZE_TAG(tag), MAPPED_INNER_OBJT_TAG(tag)); } return(0); } #ifndef ModelP #define DO_NOT_DISPOSE return (2) #else #define DO_NOT_DISPOSE dispose=0 #endif /****************************************************************************/ /** \brief Construct coarse grid from surface * @param theMG - multigrid to collapse This function constructs coarse grid from surface. ATTENTION: Use refine $g to cover always the whole domain with the grid on each level. @return
    • 0 if ok
    • 1 no valid object number
    • 2 grid structure not empty or level 0
    */ /****************************************************************************/ INT NS_DIM_PREFIX Collapse (MULTIGRID *theMG) { GRID *theGrid; ELEMENT *theElement; NODE *theNode; EDGE *theEdge; VERTEX *theVertex; #ifdef ModelP VECTOR *vec; #endif INT tl = TOPLEVEL(theMG); INT l,i; #ifdef ModelP DDD_XferBegin(theMG->dddContext()); #ifdef DDDOBJMGR DDD_ObjMgrBegin(); #endif #endif for (l=tl-1; l>=0; l--) { theGrid = GRID_ON_LEVEL(theMG,l); for (theNode=PFIRSTNODE(theGrid); theNode != NULL; theNode = SUCCN(theNode)) { SONNODE(theNode) = NULL; SETNFATHER(theNode,NULL); } for (theElement=PFIRSTELEMENT(theGrid); theElement != NULL; theElement = SUCCE(theElement)) { SETNSONS(theElement,0); SET_SON(theElement,0,NULL); #ifdef ModelP SET_SON(theElement,1,NULL); #endif for (i=0; idddContext()); #endif /* move top level grid to bottom (level 0) */ theGrid = GRID_ON_LEVEL(theMG,tl); theGrid->finer = NULL; theGrid->coarser = NULL; theGrid->level = 0; GRID_ON_LEVEL(theMG,tl) = NULL; GRID_ON_LEVEL(theMG,0) = theGrid; theMG->topLevel = 0; theMG->fullrefineLevel = 0; for (theNode=PFIRSTNODE(theGrid); theNode != NULL; theNode = SUCCN(theNode)) { SETNFATHER(theNode,NULL); SETNTYPE(theNode,LEVEL_0_NODE); SETNCLASS(theNode,3); SETNNCLASS(theNode,0); SETLEVEL(theNode,0); VFATHER(MYVERTEX(theNode)) = NULL; #ifdef ModelP DDD_AttrSet(PARHDR(theNode),GRID_ATTR(theGrid)); #endif } for (theElement=PFIRSTELEMENT(theGrid); theElement != NULL; theElement = SUCCE(theElement)) { SETECLASS(theElement,RED_CLASS); SET_EFATHER(theElement,NULL); SETLEVEL(theElement,0); #ifdef ModelP DDD_AttrSet(PARHDRE(theElement),GRID_ATTR(theGrid)); #endif for (i=0; idddContext()); #endif if (MG_COARSE_FIXED(theMG)) if (CreateAlgebra(theMG)) REP_ERR_RETURN(1); return(0); } /****************************************************************************/ /** \brief Remove top level grid from multigrid structure * @param theMG - multigrid to remove from This function removes the top level grid from multigrid structure. @return
    • 0 if ok
    • 1 no valid object number
    • 2 grid structure not empty or level 0
    */ /****************************************************************************/ INT NS_DIM_PREFIX DisposeTopLevel (MULTIGRID *theMG) { int l; GRID *theGrid; #ifdef ModelP int dispose = 1; #endif /* level 0 can not be deleted */ l = theMG->topLevel; if (l<=0) DO_NOT_DISPOSE; theGrid = GRID_ON_LEVEL(theMG,l); /* is level empty */ if (PFIRSTELEMENT(theGrid)!=NULL) DO_NOT_DISPOSE; if (PFIRSTVERTEX(theGrid)!=NULL) DO_NOT_DISPOSE; if (PFIRSTNODE(theGrid)!=NULL) DO_NOT_DISPOSE; #ifdef ModelP dispose = UG_GlobalMinINT(theMG->ppifContext(), dispose); if (!dispose) return(2); #endif /* remove from grids array */ GRID_ON_LEVEL(theMG,l) = NULL; GRID_ON_LEVEL(theMG,l-1)->finer = NULL; (theMG->topLevel)--; PutFreeObject(theMG,theGrid,sizeof(GRID),GROBJ); return(0); } /****************************************************************************/ /** \brief Dispose top level grid * @param theGrid - grid to be removed This function removes the top level grid from multigrid structure. @return
    • 0 if ok
    • 1 no valid object number
    • 2 grid structure not empty or level 0
    */ /****************************************************************************/ INT NS_DIM_PREFIX DisposeGrid (GRID *theGrid) { MULTIGRID *theMG; if (theGrid == NULL) return(0); theMG = MYMG(theGrid); if (GLEVEL(theGrid)<0) return (1); if (theGrid->finer != NULL) return(1); /* clear level */ while (PFIRSTELEMENT(theGrid)!=NULL) if (DisposeElement(theGrid,PFIRSTELEMENT(theGrid))) return(2); while (PFIRSTNODE(theGrid)!=NULL) if (DisposeNode(theGrid,PFIRSTNODE(theGrid))) return(2); while (PFIRSTVERTEX(theGrid)!=NULL) if (DisposeVertex(theGrid,PFIRSTVERTEX(theGrid))) return(4); /* level 0 can not be deleted */ if (GLEVEL(theGrid) > 0) return(DisposeTopLevel(theMG)); /* remove from grids array */ GRID_ON_LEVEL(theMG,0) = NULL; theMG->topLevel = -1; theMG->nodeIdCounter = 0; theMG->vertIdCounter = 0; theMG->elemIdCounter = 0; PutFreeObject(theMG,theGrid,sizeof(GRID),GROBJ); return(0); } /****************************************************************************/ /** \brief Release memory for the whole multigrid structure * @param theMG - multigrid to remove This function releases the memory for the whole multigrid structure. @return
    • GM_OK if ok
    • GM_ERROR when error occurred.
    */ /****************************************************************************/ INT NS_DIM_PREFIX DisposeMultiGrid (MULTIGRID *theMG) { INT level; #ifdef ModelP /* tell DDD that we will 'inconsistently' delete objects. this is a dangerous mode as it switches DDD warnings off. */ DDD_SetOption(theMG->dddContext(), OPT_WARNING_DESTRUCT_HDR, OPT_OFF); #endif for (level = TOPLEVEL(theMG); level >= 0; level --) if (DisposeGrid(GRID_ON_LEVEL(theMG,level))) RETURN(1); #ifdef ModelP /* stop dangerous mode. from now on DDD will issue warnings again. */ DDD_SetOption(theMG->dddContext(), OPT_WARNING_DESTRUCT_HDR, OPT_ON); /* rebuild DDD-interfaces because distributed vectors have been deleted without communication */ DDD_IFRefreshAll(theMG->dddContext()); #endif /** \todo Normally the MG-heap should be cleaned-up before freeing. DDD depends on storage in the heap, even if no DDD objects are allocated!! (due to free-lists, DDD type definitions etc.) therefore, repeated new/close commands are inhibited explicitly in dune/uggrid/parallel/dddif/initddd.c(InitCurrMG()). */ DisposeHeap(MGHEAP(theMG)); /* dispose BVP */ delete MG_BVP(theMG); /* first unlock the mg */ ((ENVITEM*) theMG)->v.locked = false; #ifdef ModelP ExitDDD(theMG->dddContext()); globalDDDContext(nullptr); #endif theMG->~multigrid(); /* delete mg */ if (ChangeEnvDir("/Multigrids")==NULL) RETURN (GM_ERROR); if (RemoveEnvDir ((ENVITEM *)theMG)) RETURN (GM_ERROR); return(GM_OK); } /****************************************************************************/ /** \brief Determine neighbor and side of neighbor that goes back to element * * @param theElement - considered element * @param Side - side of that element * @param theNeighbor - handle to neighbor * @param NeighborSide - number of side of neighbor that goes back to elem * This function determines the neighbor and side of the neighbor that goes back to elem. @return
    • 0 if ok
    • 1 when error occurred.
    */ /****************************************************************************/ INT NS_DIM_PREFIX FindNeighborElement (const ELEMENT *theElement, INT Side, ELEMENT **theNeighbor, INT *NeighborSide) { INT i; /* find neighbor */ *theNeighbor = NBELEM(theElement,Side); if (*theNeighbor == NULL) return (0); /* search the side */ for (i=0; i *
  • pointer to new node if ok
  • *
  • NULL when error occurred
  • * */ /****************************************************************************/ NODE * NS_DIM_PREFIX InsertInnerNode (GRID *theGrid, const DOUBLE *pos) { VERTEX *theVertex; NODE *theNode; INT i; /* create objects */ theVertex = CreateInnerVertex(theGrid); if (theVertex==NULL) { PrintErrorMessage('E',"InsertInnerNode","cannot create vertex"); return(NULL); } theNode = CreateNode(theGrid,theVertex,NULL,LEVEL_0_NODE); if (theNode==NULL) { DisposeVertex(theGrid,theVertex); PrintErrorMessage('E',"InsertInnerNode","cannot create node"); return(NULL); } /* fill data */ for (i=0; i
  • GM_OK if ok
  • GM_ERROR when error occurred.
  • */ /****************************************************************************/ NODE * NS_DIM_PREFIX InsertBoundaryNode (GRID *theGrid, BNDP *bndp) { NODE *theNode; VERTEX *theVertex; INT move; /* create objects */ theVertex = CreateBoundaryVertex(theGrid); if (theVertex==NULL) { BNDP_Dispose(MGHEAP(MYMG(theGrid)),bndp); PrintErrorMessage('E',"InsertBoundaryNode","cannot create vertex"); REP_ERR_RETURN(NULL); } if (BNDP_Global(bndp,CVECT(theVertex))) { DisposeVertex(theGrid,theVertex); return(NULL); } if (BNDP_BndPDesc(bndp,&move)) { DisposeVertex(theGrid,theVertex); return(NULL); } SETMOVE(theVertex,move); V_BNDP(theVertex) = bndp; theNode = CreateNode(theGrid,theVertex,NULL,LEVEL_0_NODE); if (theNode==NULL) { DisposeVertex(theGrid,theVertex); PrintErrorMessage('E',"InsertBoundaryNode","cannot create node"); REP_ERR_RETURN(NULL); } #ifdef TOPNODE TOPNODE(theVertex) = theNode; #endif PRINTDEBUG(dom,1,(" ipn %ld nd %x bndp %x \n", ID(theNode),theNode,V_BNDP(theVertex))); return(theNode); } /****************************************************************************/ /** \brief Delete a node * @param theGrid - grid structure * @param theNode - node to delete This function deletes a node from level 0. @return
    • GM_OK if ok
    • GM_ERROR when error occurred.
    */ /****************************************************************************/ INT NS_DIM_PREFIX DeleteNode (GRID *theGrid, NODE *theNode) { VERTEX *theVertex; ELEMENT *theElement; INT i; if (theNode==NULL) { PrintErrorMessage('E',"DeleteNode","node not found"); RETURN(GM_ERROR); } /* check corner */ theVertex = MYVERTEX(theNode); if (MOVE(theVertex)==0) { PrintErrorMessage('E',"DeleteNode","corners cannot be deleted"); RETURN(GM_ERROR); } /* check if some element needs that node */ for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) for (i=0; i NeighborSearch_O_nn", "neighbor relation inconsistent"); return(1); } Nbr[i] = theOther; NbrS[i] = jj; } } } } /* ... O(n*n)InsertElement */ #else /*O(n*n)InsertElement ...*/ /* for all sides of the element to be created */ MULTIGRID::FaceNodes faceNodes; for (int i=0; ifacemap.emplace(faceNodes,std::make_pair(theElement,i)); // if this failed (i.e. result.second == false) an entry already exists if (! result.second) { // update neighbor list the other entry, stored in result.first->second auto & data = result.first->second; ELEMENT* theOther = data.first; int idx = data.second; Nbr[i] = theOther; NbrS[i] = idx; theMG->facemap.erase(faceNodes); } } #endif return(0); /*... O(n)InsertElement ...*/ } /*of static INT NeighborSearch_O_n()*/ /****************************************************************************/ /** \todo Please doc me! Neighbor_Direct_Insert - SYNOPSIS: static INT Neighbor_Direct_Insert(INT n, ELEMENT **ElemList, INT *NbgSdList, INT* NbrS, ELEMENT **Nbr); * @param tag Element type * @param ElemList * @param NbgSdList * @param NbrS * @param Nbr DESCRIPTION: @return INT */ /****************************************************************************/ static INT Neighbor_Direct_Insert(INT tag, ELEMENT **ElemList, const INT *NbgSdList, INT* NbrS, ELEMENT **Nbr) { INT i; for (i=0; ifacemap.bucket_count() <= 1) { // try to allocate the right size a-priori to avoid rehashing theMG->facemap.rehash(theMG->nodeIdCounter); // theMG->facemap.max_load_factor(1000); } /* check parameters */ #ifdef UG_DIM_2 switch (n) { case 3 : tag = TRIANGLE; break; case 4 : tag = QUADRILATERAL; break; default : PrintErrorMessage('E',"InsertElement","only triangles and quadrilaterals allowed in 2D"); return(NULL); } #endif #ifdef UG_DIM_3 switch (n) { case 4 : tag = TETRAHEDRON; break; case 5 : tag = PYRAMID; break; case 6 : tag = PRISM; break; case 8 : tag = HEXAHEDRON; break; default : PrintErrorMessage('E',"InsertElement","only tetrahedra, prisms, pyramids, and hexahedra are allowed in the 3D coarse grid"); return(NULL); } #endif /* init vertices */ for (i=0; ierror */ /* or: if bnds_flag==NULL, the domain decides whether there */ /* should be a bnds or not (never an error) */ for (j=0; j= MAX_SIDES_OF_ELEM) { PrintErrorMessage('E',"InsertElement", "neighbor relation inconsistent"); return(NULL); } SET_NBELEM(Neighbor[i],NeighborSide[i],theElement); #ifdef UG_DIM_3 if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) if (DisposeDoubledSideVector(theGrid,Neighbor[i], NeighborSide[i],theElement,i)) return(NULL); #endif } } SET_EFATHER(theElement,NULL); SETECLASS(theElement,RED_CLASS); return(theElement); } /****************************************************************************/ /** \brief Delete an element * @param theMG - multigrid structure * @param theElement - element to delete This function deletes an element from level 0. @return
    • GM_OK if ok
    • GM_ERROR when error occurred.
    */ /****************************************************************************/ INT NS_DIM_PREFIX DeleteElement (MULTIGRID *theMG, ELEMENT *theElement) /* 3D VERSION */ { GRID *theGrid; INT i,j,found; /* check level */ if (TOPLEVEL(theMG)!=0) { PrintErrorMessage('E',"DeleteElement", "only a multigrid with exactly one level can be edited"); RETURN(GM_ERROR); } theGrid = GRID_ON_LEVEL(theMG,0); /* delete pointers in neighbors */ for (i=0; i
  • GM_OK if ok
  • GM_ERROR when error occurred.
  • */ /****************************************************************************/ INT NS_DIM_PREFIX InsertMesh (MULTIGRID *theMG, MESH *theMesh) { GRID *theGrid; ELEMENT *theElement; NODE **NList,*Nodes[MAX_CORNERS_OF_ELEM]; VERTEX **VList; INT i,k,n,nv,j,maxlevel,l,move; INT ElemSideOnBnd[MAX_SIDES_OF_ELEM]; INT MarkKey = MG_MARK_KEY(theMG); if (theMesh == NULL) return(GM_OK); if (theMesh->nElements == NULL) { assert(theMesh->VertexLevel==NULL); theGrid = GRID_ON_LEVEL(theMG,0); for (i=0; inBndP; i++) if (InsertBoundaryNode(theGrid,theMesh->theBndPs[i]) == NULL) REP_ERR_RETURN(GM_ERROR); for (i=0; inInnP; i++) if (InsertInnerNode(theGrid,theMesh->Position[i]) == NULL) REP_ERR_RETURN(GM_ERROR); return(GM_OK); } /* prepare */ nv = theMesh->nBndP + theMesh->nInnP; VList = (VERTEX **) GetTmpMem(MGHEAP(theMG),nv*sizeof(VERTEX *),MarkKey); if (VList == NULL) return(GM_ERROR); NList = (NODE **) GetTmpMem(MGHEAP(theMG),nv*sizeof(NODE *),MarkKey); if (NList == NULL) return(GM_ERROR); for (j=0; jVertexLevel!=NULL) { for (i=0; inBndP; i++) { theGrid = GRID_ON_LEVEL(theMG,theMesh->VertexLevel[i]); VList[i] = CreateBoundaryVertex(theGrid); assert(VList[i]!=NULL); if (BNDP_Global(theMesh->theBndPs[i],CVECT(VList[i]))) assert(0); if (BNDP_BndPDesc(theMesh->theBndPs[i],&move)) return(GM_OK); SETMOVE(VList[i],move); V_BNDP(VList[i]) = theMesh->theBndPs[i]; maxlevel = std::max(maxlevel,(INT)theMesh->VertexLevel[i]); } for (i=theMesh->nBndP; iVertexLevel[i]); VList[i] = CreateInnerVertex(theGrid); V_DIM_COPY(theMesh->Position[i-theMesh->nBndP],CVECT(VList[i])); maxlevel = std::max(maxlevel,(INT)theMesh->VertexLevel[i]); } } else { theGrid = GRID_ON_LEVEL(theMG,0); for (i=0; inBndP; i++) { VList[i] = CreateBoundaryVertex(theGrid); assert(VList[i]!=NULL); if (BNDP_Global(theMesh->theBndPs[i],CVECT(VList[i]))) assert(0); if (BNDP_BndPDesc(theMesh->theBndPs[i],&move)) return(GM_OK); SETMOVE(VList[i],move); V_BNDP(VList[i]) = theMesh->theBndPs[i]; } for (i=theMesh->nBndP; iPosition[i-theMesh->nBndP],CVECT(VList[i])); } } if (theMesh->nElements == NULL) return(GM_OK); for (j=1; j<=1; j++) for (k=0; knElements[j]; k++) { if (theMesh->ElementLevel!=NULL) i = theMesh->ElementLevel[j][k]; else i=0; theGrid = GRID_ON_LEVEL(theMG,i); n = theMesh->Element_corners[j][k]; for (l=0; lElement_corner_ids[j][k][l]]; if (curListNode == NULL || LEVEL(curListNode) < i) { Nodes[l] = CreateNode(theGrid,VList[theMesh->Element_corner_ids[j][k][l]],NULL,LEVEL_0_NODE); if (Nodes[l]==NULL) assert(0); NList[theMesh->Element_corner_ids[j][k][l]] = Nodes[l]; if (curListNode == NULL || LEVEL(curListNode) < i-1) { SETNFATHER(Nodes[l],NULL); } else { SETNFATHER(Nodes[l],(GEOM_OBJECT *)curListNode); SONNODE(curListNode) = Nodes[l]; } } else { Nodes[l] = curListNode; } } if (theMesh->ElemSideOnBnd==NULL) theElement = InsertElement (theGrid,n,Nodes,NULL,NULL,NULL); else { for (l=0; lElemSideOnBnd[j][k]&(1<& corner = CVECT(MYVERTEX(CORNER(theElement,i))); V_DIM_ADD(center_of_mass,corner,center_of_mass); } V_DIM_SCALE(1.0/nr_corners,center_of_mass); } /****************************************************************************/ /** \brief Calculate an (hopefully) unique key for the geometric object * @param obj - geometric object which from the key is needed (can be one of VERTEX, ELEMENT, NODE or VECTOR) This function calculates an (hopefully) unique key for VERTEX, ELEMENT, NODE, EDGE and VECTOR typed objects. The heuristic is: calculate a 2D/3D position for the geometric object and transform this position to a single number by a weighted summation of the leading digits of the 2 resp. 3 coordinates and taking from this again the sigificant digits and adding the level number. APPLICATION: Use always an explicit cast to avoid compiler warnings, e.g. NODE *theNode; KeyForObject((KEY_OBJECT *)theNode); * \sa VERTEX, ELEMENT, NODE, EDGE, VECTOR @return * the resulting key */ /****************************************************************************/ INT NS_DIM_PREFIX KeyForObject( KEY_OBJECT *obj ) { int dummy,i; /* dummy variable */ DOUBLE_VECTOR coord; if (obj==NULL) return (-1); switch( OBJT(obj) ) { /* vertex */ case BVOBJ : case IVOBJ : /* both together cover all vertex types */ return LEVEL(obj)+COORDINATE_TO_KEY(CVECT((VERTEX*)obj),&dummy); /* element */ case BEOBJ : case IEOBJ : for (i=0; iBVP_Name.c_str()); else UserWriteF(" %c %-20.20s\n",c,ENVITEM_NAME(theMG)); } /****************************************************************************/ /** \brief List information about refinement type distribution * @param theMG - structure to list * @param gridflag - * @param greenflag * @param lbflag * @param verbose This function lists information about multigrids element types. * \todo Please return value! */ /****************************************************************************/ INT NS_DIM_PREFIX MultiGridStatus (const MULTIGRID *theMG, INT gridflag, INT greenflag, INT lbflag, INT verbose) { INT i,j,sons,maxsons; INT red, green, yellow; INT mg_red,mg_green,mg_yellow; INT mg_greenrulesons[MAXLEVEL+1][MAX_SONS+1],mg_greenrules[MAXLEVEL+1]; INT markcount[MAXLEVEL+1],closuresides[MAXLEVEL+1]; FLOAT sum,sum_div_red,redplusgreen_div_red; FLOAT mg_sum,mg_sum_div_red,mg_redplusgreen_div_red; ELEMENT *theElement; GRID *theGrid; #ifdef ModelP INT MarkKey; INT total_elements,sum_elements; INT master_elements,hghost_elements,vghost_elements,vhghost_elements; #endif #ifdef ModelP const auto& ppifContext = theMG->ppifContext(); const int me = ppifContext.me(); const int procs = ppifContext.procs(); #endif mg_red = mg_green = mg_yellow = mg_sum = 0; mg_sum_div_red = mg_redplusgreen_div_red = 0.0; for (i=0; i infobuffer((procs+1)*(MAXLEVEL+1)*ELEMENT_PRIOS, 0); std::vector lbinfo(procs+1); for (i=0; i 0) { sum_div_red = sum / red; redplusgreen_div_red = ((float)(red+green)) / red; } else { sum_div_red = 0.0; redplusgreen_div_red = 0.0; } if (verbose && gridflag) UserWriteF(" %2d %9d %9d %9d %9.0f %2.3f %2.3f\n", i,red,green,yellow,sum,sum_div_red,redplusgreen_div_red); mg_red += red; mg_green += green; mg_yellow += yellow; mg_sum += sum; } if (mg_red > 0) { mg_sum_div_red = mg_sum / mg_red; mg_redplusgreen_div_red = ((float)(mg_red + mg_green)) / mg_red; } else { mg_sum_div_red = 0.0; mg_redplusgreen_div_red = 0.0; } if (verbose && gridflag) UserWriteF(" ALL %9d %9d %9d %9.0f %2.3f %2.3f\n", mg_red,mg_green,mg_yellow,mg_sum,mg_sum_div_red,mg_redplusgreen_div_red); /* set heap info in refine info */ if (gridflag) { float New; float newpergreen; SETMARKCOUNT(REFINEINFO(theMG),markcount[MAXLEVEL]); New = markcount[MAXLEVEL]*(2<<(DIM-1))*mg_sum_div_red; SETPREDNEW0(REFINEINFO(theMG),New); if (mg_greenrules[MAXLEVEL] > 0) newpergreen = ((float)mg_greenrulesons[MAXLEVEL][MAX_SONS])/mg_greenrules[MAXLEVEL]; else newpergreen = 0; New = markcount[MAXLEVEL]*(2<<(DIM-1))+newpergreen*closuresides[MAXLEVEL]; SETPREDNEW1(REFINEINFO(theMG),New); SETREAL(REFINEINFO(theMG),mg_sum); } /* list heap info */ if (verbose && gridflag) { UserWriteF(" EST %2d ELEMS=%9.0f MARKCOUNT=%9.0f PRED_NEW0=%9.0f PRED_NEW1=%9.0f\n", REFINESTEP(REFINEINFO(theMG)),REAL(REFINEINFO(theMG)),MARKCOUNT(REFINEINFO(theMG)), PREDNEW0(REFINEINFO(theMG)),PREDNEW1(REFINEINFO(theMG))); UserWriteF(" EST TRACE step=%d\n",refine_info.step); for (i=0; i mych(procs, nullptr); for (i=1; i= 3) { UserWriteF(" LEVEL"); for (i=0; i= 2) { float memeff; UserWriteF("%5s %9s %9s %9s %9s %9s %6s\n", "LEVEL","SUM","MASTER","HGHOST","VGHOST","VHGHOST","MEMEFF"); for (i=0; i<=TOPLEVEL(theMG); i++) { sum_elements = lbinfo[procs][ELEMENT_PRIOS*i]+lbinfo[procs][ELEMENT_PRIOS*i+1]+ lbinfo[procs][ELEMENT_PRIOS*i+2]+lbinfo[procs][ELEMENT_PRIOS*i+3]; if (sum_elements > 0) memeff = ((float)lbinfo[procs][ELEMENT_PRIOS*i])/sum_elements*100; else memeff = 0.0; UserWriteF("%4d %9d %9d %9d %9d %9d %3.2f\n",i,sum_elements, lbinfo[procs][ELEMENT_PRIOS*i],lbinfo[procs][ELEMENT_PRIOS*i+1], lbinfo[procs][ELEMENT_PRIOS*i+2],lbinfo[procs][ELEMENT_PRIOS*i+3],memeff); } UserWrite("\n"); UserWriteF("%4s %9s %9s %9s %9s %9s %6s\n", "PROC","SUM","MASTER","HGHOST","VGHOST","VHGHOST","MEMEFF"); for (i=0; i 0) memeff = ((float)lbinfo[i][ELEMENT_PRIOS*MAXLEVEL])/sum_elements*100; else memeff = 0.0; UserWriteF("%4d %9d %9d %9d %9d %9d %3.2f\n",i,sum_elements, lbinfo[i][ELEMENT_PRIOS*MAXLEVEL],lbinfo[i][ELEMENT_PRIOS*MAXLEVEL+1], lbinfo[i][ELEMENT_PRIOS*MAXLEVEL+2],lbinfo[i][ELEMENT_PRIOS*MAXLEVEL+3],memeff); } UserWrite("\n"); } if (lbflag >= 1) { float memeff; for (i=0; i 0) memeff = ((float)master_elements)/total_elements*100; else memeff = 0.0; UserWriteF("%9s %9s %9s %9s %9s %6s\n","TOTAL","MASTER","HGHOST","VGHOST","VHGHOST","MEMEFF"); UserWriteF("%9d %9d %9d %9d %9d %3.2f\n",total_elements,master_elements,hghost_elements, vghost_elements,vhghost_elements,memeff); } } ReleaseTmpMem(MGHEAP(theMG),MarkKey); #endif return (GM_OK); } /****************************************************************************/ /** \brief List general information about grids of multigrid * @param theMG - multigrid structure This function lists general information about the grids of a multigrid. */ /****************************************************************************/ void NS_DIM_PREFIX ListGrids (const MULTIGRID *theMG) { GRID *theGrid; ELEMENT *theElement,*NBElem; VERTEX *myVertex,*nbVertex,*v0,*v1; NODE *theNode,*n0,*n1; EDGE *theEdge; LINK *theLink; VECTOR *vec; DOUBLE hmin,hmax,h; INT l,minl,i,soe,eos,coe,side,e; INT nn,ne,nt,ns,nvec,nc; UserWriteF("grids of '%s':\n",ENVITEM_NAME(theMG)); UserWrite("level maxlevel #vert #node #edge #elem #side #vect #conn"); UserWrite(" minedge maxedge\n"); for (l=0; l<=TOPLEVEL(theMG); l++) { theGrid = GRID_ON_LEVEL(theMG,l); /* calculate minimal and maximal edge */ hmin = MAX_C; hmax = 0.0; for (theNode=FIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) { myVertex = MYVERTEX(theNode); for (theLink=START(theNode); theLink!=NULL; theLink=NEXT(theLink)) { nbVertex = MYVERTEX(NBNODE(theLink)); V_DIM_EUKLIDNORM_OF_DIFF(CVECT(myVertex),CVECT(nbVertex),h); hmin = std::min(hmin,h); hmax = std::max(hmax,h); } } ns = 0; for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) if (OBJT(theElement) == BEOBJ) for (i=0; i0) continue; /* objects of this side will be counted by the neighbour */ eos = EDGES_OF_SIDE(theElement,side); for (i=0; i0) continue; /* objects of this side will be counted by the neighbour */ eos = EDGES_OF_SIDE(theElement,side); for (i=0; ippifContext(), nn); ne = UG_GlobalSumINT(theMG->ppifContext(), ne); nt = UG_GlobalSumINT(theMG->ppifContext(), nt); ns = UG_GlobalSumINT(theMG->ppifContext(), ns); nvec = UG_GlobalSumINT(theMG->ppifContext(), nvec); nc = UG_GlobalSumINT(theMG->ppifContext(), nc); hmin = UG_GlobalMinDOUBLE(theMG->ppifContext(), hmin); hmax = UG_GlobalMaxDOUBLE(theMG->ppifContext(), hmax); UserWrite("\nsurface of all processors up to top level:\n"); UserWriteF("%c %3d %8d %8s %8ld %8s %8ld %8ld %8ld %8s %9.3e %9.3e\n", ' ',minl,TOPLEVEL(theMG), "---",(long)nn," ",(long)nt, (long)ns,(long)nvec," ",(float)hmin,(float)hmax); #endif } /****************************************************************************/ /** \brief List information about node in multigrid * @param theMG - structure containing the node * @param theNode - node to list * @param dataopt - list user data if true * @param bopt - list boundary info if true * @param nbopt - list info about neighbors if true * @param vopt - list more information This function lists information about a node in a multigrid. */ /****************************************************************************/ void NS_DIM_PREFIX ListNode (const MULTIGRID *theMG, const NODE *theNode, INT dataopt, INT bopt, INT nbopt, INT vopt) { VERTEX *theVertex; LINK *theLink; INT i; theVertex = MYVERTEX(theNode); /******************************/ /* print standard information */ /******************************/ /* line 1 */ UserWriteF("NODEID=" ID_FFMTE " CTRL=%8lx VEID=" VID_FMTX " LEVEL=%2d", ID_PRTE(theNode),(long)CTRL(theNode), VID_PRTX(theVertex),LEVEL(theNode)); /* print coordinates of that node */ for(i=0; i
  • 0 if ok
  • 1 if error occurred.
  • */ /****************************************************************************/ static INT MaxNodeClass (const ELEMENT *theElement) { INT m = 0; INT i; for (i=0; i
  • 0 if ok
  • 1 if error occurred.
  • */ /****************************************************************************/ INT NS_DIM_PREFIX MaxNextNodeClass (const ELEMENT *theElement) { INT m = 0; INT i; for (i=0; i
  • 0 if ok
  • 1 if error occurred.
  • */ /****************************************************************************/ INT NS_DIM_PREFIX MinNodeClass (const ELEMENT *theElement) { INT m = 3; INT i; for (i=0; i
  • 0 if ok
  • 1 if error occurred.
  • */ /****************************************************************************/ INT NS_DIM_PREFIX MinNextNodeClass (const ELEMENT *theElement) { INT m = 3; INT i; for (i=0; i
  • 0 if ok
  • 1 if error occurred.
  • */ /****************************************************************************/ INT NS_DIM_PREFIX SeedNodeClasses (ELEMENT *theElement) { INT i; for (i=0; i
  • 0 if ok
  • 1 if error occurred.
  • */ /****************************************************************************/ INT NS_DIM_PREFIX ClearNodeClasses (GRID *theGrid) { NODE *theNode; /* reset class of each Node to 0 */ for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) SETNCLASS(theNode,0); return(0); } #ifdef ModelP static int Gather_NodeClass (DDD::DDDContext&, DDD_OBJ obj, void *data) { NODE *theNode = (NODE *)obj; ((INT *)data)[0] = NCLASS(theNode); return(0); } static int Scatter_NodeClass (DDD::DDDContext&, DDD_OBJ obj, void *data) { NODE *theNode = (NODE *)obj; SETNCLASS(theNode,std::max((INT)NCLASS(theNode),((INT *)data)[0])); return(0); } static int Scatter_GhostNodeClass (DDD::DDDContext&, DDD_OBJ obj, void *data) { NODE *theNode = (NODE *)obj; SETNCLASS(theNode,((INT *)data)[0]); return(0); } #endif /****************************************************************************/ /** \brief Compute Node classes after initialization * @param theGrid - pointer to grid After Node classes have been reset and initialized, this function now computes the class 2 and class 1 Nodes. @return
    • 0 if ok
    • 1 if error occurred
    */ /****************************************************************************/ static INT PropagateNodeClass (GRID *theGrid, INT nclass) { ELEMENT *theElement; INT i; for (theElement=FIRSTELEMENT(theGrid); theElement!= NULL; theElement = SUCCE(theElement)) if (MaxNodeClass(theElement) == nclass) for (i=0; idddContext(); const auto& dddctrl = ddd_ctrl(context); PRINTDEBUG(gm,1,("\n" PFMT "PropagateNodeClasses():" " 1. communication on level %d\n",theGrid->ppifContext().me(),GLEVEL(theGrid))) /* exchange NCLASS of Nodes */ DDD_IFAExchange(context, dddctrl.BorderNodeSymmIF,GRID_ATTR(theGrid),sizeof(INT), Gather_NodeClass, Scatter_NodeClass); #endif /* set Node classes in the algebraic neighborhood to 2 */ if (PropagateNodeClass(theGrid,3)) REP_ERR_RETURN(1); #ifdef ModelP PRINTDEBUG(gm,1,("\n" PFMT "PropagateNodeClasses(): 2. communication\n", theGrid->ppifContext().me())) /* exchange NCLASS of Nodes */ DDD_IFAExchange(context, dddctrl.BorderNodeSymmIF,GRID_ATTR(theGrid),sizeof(INT), Gather_NodeClass, Scatter_NodeClass); #endif /* set Node classes in the algebraic neighborhood to 1 */ if (PropagateNodeClass(theGrid,2)) REP_ERR_RETURN(1); #ifdef ModelP PRINTDEBUG(gm,1,("\n" PFMT "PropagateNodeClasses(): 3. communication\n", theGrid->ppifContext().me())) /* exchange NCLASS of Nodes */ DDD_IFAExchange(context, dddctrl.BorderNodeSymmIF,GRID_ATTR(theGrid),sizeof(INT), Gather_NodeClass, Scatter_NodeClass); /* send NCLASS to ghosts */ DDD_IFAOneway(context, dddctrl.NodeIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), Gather_NodeClass, Scatter_GhostNodeClass); #endif return(0); } /****************************************************************************/ /** \brief Reset class of the Nodes on the next level * @param theGrid - pointer to grid This function clears NNCLASS flag in all Nodes. This is the first step to compute the class of the dofs on the *NEXT* level, which is also the basis for determining copies. @return
    • 0 if ok
    • 1 if error occurred.
    */ /****************************************************************************/ INT NS_DIM_PREFIX ClearNextNodeClasses (GRID *theGrid) { NODE *theNode; /* reset class of each Node to 0 */ for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) SETNNCLASS(theNode,0); /* now the refinement algorithm will initialize the class 3 Nodes */ /* on the *NEXT* level. */ return(0); } /****************************************************************************/ /** \brief Set 'NNCLASS' in all Nodes associated with element * @param theElement - pointer to element Set 'NNCLASS' in all nodes associated with the element to 3. @return
    • 0 if ok
    • 1 if error occurred.
    */ /****************************************************************************/ INT NS_DIM_PREFIX SeedNextNodeClasses (ELEMENT *theElement) { INT i; for (i=0; i
  • 0 if ok
  • 1 if error occurred
  • */ /****************************************************************************/ #ifdef ModelP static int Gather_NextNodeClass (DDD::DDDContext&, DDD_OBJ obj, void *data) { NODE *theNode = (NODE *)obj; ((INT *)data)[0] = NNCLASS(theNode); return(GM_OK); } static int Scatter_NextNodeClass (DDD::DDDContext&, DDD_OBJ obj, void *data) { NODE *theNode = (NODE *)obj; SETNNCLASS(theNode,std::max((INT)NNCLASS(theNode),((INT *)data)[0])); return(GM_OK); } static int Scatter_GhostNextNodeClass (DDD::DDDContext&, DDD_OBJ obj, void *data) { NODE *theNode = (NODE *)obj; SETNNCLASS(theNode,((INT *)data)[0]); return(GM_OK); } #endif static INT PropagateNextNodeClass (GRID *theGrid, INT nnclass) { ELEMENT *theElement; INT i; for (theElement=FIRSTELEMENT(theGrid); theElement!= NULL; theElement = SUCCE(theElement)) if (MaxNextNodeClass(theElement) == nnclass) for (i=0; idddContext(); const auto& dddctrl = ddd_ctrl(context); PRINTDEBUG(gm,1,("\n" PFMT "PropagateNextNodeClasses(): 1. communication\n",theGrid->ppifContext().me())) /* exchange NNCLASS of Nodes */ DDD_IFAExchange(context, dddctrl.BorderNodeSymmIF,GRID_ATTR(theGrid),sizeof(INT), Gather_NextNodeClass, Scatter_NextNodeClass); #endif if (PropagateNextNodeClass(theGrid,3)) REP_ERR_RETURN(1); #ifdef ModelP PRINTDEBUG(gm,1,("\n" PFMT "PropagateNextNodeClasses(): 2. communication\n",theGrid->ppifContext().me())) /* exchange NNCLASS of Nodes */ DDD_IFAExchange(context, dddctrl.BorderNodeSymmIF,GRID_ATTR(theGrid),sizeof(INT), Gather_NextNodeClass, Scatter_NextNodeClass); #endif if (PropagateNextNodeClass(theGrid,2)) REP_ERR_RETURN(1); #ifdef ModelP PRINTDEBUG(gm,1,("\n" PFMT "PropagateNextNodeClasses(): 3. communication\n",theGrid->ppifContext().me())) /* exchange NNCLASS of Nodes */ DDD_IFAExchange(context, dddctrl.BorderNodeSymmIF,GRID_ATTR(theGrid),sizeof(INT), Gather_NextNodeClass, Scatter_NextNodeClass); /* send NNCLASSn to ghosts */ DDD_IFAOneway(context, dddctrl.NodeIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), Gather_NextNodeClass, Scatter_GhostNextNodeClass); #endif return(0); } /****************************************************************************/ /** \brief Set subdomain id on level 0 edges * @param id - the id of the block to be allocated This function sets the subdomain id taken from the elements for level 0 edges. @return
    • GM_OK if ok
    • GM_ERROR if error occurred
    */ /****************************************************************************/ static INT SetEdgeAndNodeSubdomainFromElements (GRID *theGrid) { ELEMENT *theElement; NODE *n0,*n1; EDGE *ed; INT s_id,s,i,k; /* first set subdomain id for all edges */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { /* all edges of the element acquire the subdomain id of the element */ s_id = SUBDOMAIN(theElement); for (k=0; k
  • GM_OK if ok
  • GM_ERROR if error occurred
  • */ /****************************************************************************/ static INT RemoveSpuriousBoundarySides (HEAP *heap, ELEMENT *elem, INT side) { ELEMENT *nb=NBELEM(elem,side); BNDS *nbbside,*bside=ELEM_BNDS(elem,side); INT nbside; ASSERT(bside!=NULL); ASSERT(OBJT(elem)==BEOBJ); ASSERT(nb!=NULL); ASSERT(OBJT(nb)==BEOBJ); /* search nbside */ for (nbside=0; nbside *
  • GM_OK if ok
  • *
  • GM_ERROR if error occurred
  • ** */ /****************************************************************************/ static INT BElem2IElem (GRID *grid, ELEMENT **elemH) { ELEMENT *nb[MAX_SIDES_OF_ELEM],*elem=*elemH,*ielem; NODE *nodes[MAX_CORNERS_OF_ELEM]; INT i,j,nbside[MAX_SIDES_OF_ELEM],s_id; ASSERT(GLEVEL(grid)==0); /* save context */ for (i=0; i
  • GM_OK if ok
  • GM_ERROR if error occurred
  • */ /****************************************************************************/ static INT FinishGrid (MULTIGRID *mg) { GRID *grid; ELEMENT *elem,*nb,*succ; HEAP *heap=MGHEAP(mg); FIFO unused,shell; INT MarkKey = MG_MARK_KEY(mg); INT side,nbid,s_id; INT *sd_table; void *fifoBuffer; /* prepare */ if (TOPLEVEL(mg)<0) REP_ERR_RETURN (GM_ERROR); grid = GRID_ON_LEVEL(mg,0); if (!NT(grid)) return (GM_OK); for (elem=PFIRSTELEMENT(grid); elem!=NULL; elem=SUCCE(elem)) { SETUSED(elem,false); SETTHEFLAG(elem,false); } /* table for subdomain ids */ const INT nsd = 2; sd_table = (INT*)GetTmpMem(heap,nsd*sizeof(INT),MarkKey); if (sd_table==NULL) REP_ERR_RETURN (GM_ERROR); /* init two fifos */ fifoBuffer = (void *)GetTmpMem(heap, sizeof(ELEMENT*)*NT(grid), MarkKey); if (fifoBuffer == NULL) REP_ERR_RETURN (GM_ERROR); fifo_init(&unused, fifoBuffer, sizeof(ELEMENT*)*NT(grid)); fifoBuffer = (void *)GetTmpMem(heap, sizeof(ELEMENT*)*NT(grid), MarkKey); if (fifoBuffer == NULL) REP_ERR_RETURN (GM_ERROR); fifo_init(&shell, fifoBuffer, sizeof(ELEMENT*)*NT(grid)); /* outermost loop handles nonconnected domains */ while (true) { for (elem=PFIRSTELEMENT(grid); elem!=NULL; elem=SUCCE(elem)) if (!USED(elem)) break; if (elem!=NULL) fifo_in(&unused,elem); else break; while (!fifo_empty(&unused)) { /* grab next !USED element */ do elem = (ELEMENT*) fifo_out(&unused); while (USED(elem) && !fifo_empty(&unused)); if (USED(elem)) /* we are done */ break; /* shell algo (using FLAG): neighbours, but not across bside */ fifo_clear(&shell); fifo_in(&shell,elem); SETTHEFLAG(elem,true); for (INT i=0; i<=nsd; i++) sd_table[i] = 0; INT found = false; while (!fifo_empty(&shell)) { elem = (ELEMENT*) fifo_out(&shell); if (OBJT(elem)==BEOBJ) for (side=0; side0); s_id = nbid; found = true; break; } if (nbid==0) { ASSERT(id>0); s_id = id; found = true; break; } ++sd_table[id]; if (sd_table[id]>1) { s_id = id; found = true; break; } } if (found) break; /* push neighbours not across boundary */ if (OBJT(elem)==BEOBJ) { for (side=0; side2) /* FATAL: algorithm relies on assumptions obviously not fulfilled! */ ASSERT(false); /* again shell algo starting from last element */ /* set USED, propagate subdomain ids and remove spurious bsides (has to have NB!) */ /* use PRINTDEBUG */ fifo_clear(&shell); fifo_in(&shell,elem); SETUSED(elem,true); SETSUBDOMAIN(elem,s_id); while (!fifo_empty(&shell)) { elem = (ELEMENT*) fifo_out(&shell); if (OBJT(elem)==BEOBJ) { for (side=0; side=SIDES_OF_ELEM(elem)) if (BElem2IElem(grid,&elem)) REP_ERR_RETURN(1); } if (SetEdgeAndNodeSubdomainFromElements(grid)) REP_ERR_RETURN (GM_ERROR); return (GM_OK); } /****************************************************************************/ /** \brief SetSubdomainIDfromBndInfo - set subdomain id on level 0 elements and edges * @param id - the id of the block to be allocated This function sets the subdomain for level 0 elements and edges. @return
    • GM_OK if ok
    • GM_ERROR if error occurred
    */ /****************************************************************************/ INT NS_DIM_PREFIX SetSubdomainIDfromBndInfo (MULTIGRID *theMG) { HEAP *theHeap; GRID *theGrid; ELEMENT *theElement, *theNeighbor; NODE *theNode; void *fifoBuffer; INT i,n,id,nbid,j; FIFO myfifo; INT MarkKey = MG_MARK_KEY(theMG); /* prepare */ if (TOPLEVEL(theMG)<0) REP_ERR_RETURN (GM_ERROR); theGrid = GRID_ON_LEVEL(theMG,0); n = NT(theGrid); if (n==0) return(0); /* allocate fifo and init */ theHeap = MYMG(theGrid)->theHeap; fifoBuffer = (void *)GetTmpMem(theHeap, sizeof(ELEMENT*)*n, MarkKey); fifo_init(&myfifo, fifoBuffer, sizeof(ELEMENT*)*n); for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) SETUSED(theElement,0); /* insert all boundary elements */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) if (OBJT(theElement)==BEOBJ && !USED(theElement)) { for (i=0; i0); SETSUBDOMAIN(theElement,id); SETUSED(theElement,1); fifo_in(&myfifo,(void *)theElement); PRINTDEBUG(gm,1,("elem %3d sid %d\n",ID(theElement),SUBDOMAIN(theElement))); for (i=0; i
  • GM_OK if ok
  • GM_ERROR if error occurred
  • * */ /****************************************************************************/ INT NS_DIM_PREFIX FixCoarseGrid (MULTIGRID *theMG) { if (MG_COARSE_FIXED(theMG)) return (GM_OK); /** \todo (HRR 971031): check that before check-in! if (FinishGrid(theMG)) REP_ERR_RETURN (GM_ERROR);*/ /** \todo (HRR 971031): remove if above works */ if (SetSubdomainIDfromBndInfo(theMG)) REP_ERR_RETURN (GM_ERROR); /* set this flag here because it is checked by CreateAlgebra */ if (CreateAlgebra(theMG) != GM_OK) REP_ERR_RETURN (GM_ERROR); /* here all temp memory since CreateMultiGrid is released */ ReleaseTmpMem(MGHEAP(theMG),MG_MARK_KEY(theMG)); MG_MARK_KEY(theMG) = 0; return (GM_OK); } /****************************************************************************/ /** \brief Init what is necessary * * This function initializes the grid manager. * * @return
      *
    • GM_OK if ok
    • *
    • > 0 line in which error occurred
    • *
    */ /****************************************************************************/ INT NS_DIM_PREFIX InitUGManager () { INT i; /* install the /Multigrids directory */ if (ChangeEnvDir("/")==NULL) { PrintErrorMessage('F',"InitUGManager","could not changedir to root"); return(__LINE__); } theMGRootDirID = GetNewEnvDirID(); if (MakeEnvItem("Multigrids",theMGRootDirID,sizeof(ENVDIR))==NULL) { PrintErrorMessage('F',"InitUGManager","could not install /Multigrids dir"); return(__LINE__); } theMGDirID = GetNewEnvDirID(); /* init the OBJT management */ UsedOBJT = 0; for (i=0; i