static INT ComputeSurfaceGridStats (MULTIGRID *theMG, COVISE_HEADER *covise) { NODE *theNode; INT l, n_vertices, n_elem, n_conn; /* surface grid up to current level */ n_vertices = n_elem = n_conn = 0; for (l=covise->min_level; l<=covise->max_level; l++) { ELEMENT *theElement; GRID *theGrid = GRID_ON_LEVEL(theMG,l); /* reset USED flags in all vertices to be counted */ for (theNode=FIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) { SETUSED(MYVERTEX(theNode),0); } /* count geometric objects */ for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if ((EstimateHere(theElement)) || (l==covise->max_level)) { int i, coe = CORNERS_OF_ELEM(theElement); n_elem++; for (i=0; i<coe; i++) { theNode = CORNER(theElement,i); n_conn++; if (USED(MYVERTEX(theNode))) continue; SETUSED(MYVERTEX(theNode),1); if ((SONNODE(theNode)==NULL) || (l==covise->max_level)) { #ifdef ModelP if (PRIO(theNode) == PrioMaster) #endif n_vertices++; } } } } } #ifdef ModelP n_vertices = UG_GlobalSumINT(n_vertices); n_elem = UG_GlobalSumINT(n_elem); n_conn = UG_GlobalSumINT(n_conn); #endif covise->n_vertices = n_vertices; covise->n_elems = n_elem; covise->n_conns = n_conn; return(0); }
/* TODO renumber doesn't work in parallel */ static INT RenumberVertices (MULTIGRID *theMG, INT min_level, INT max_level) { INT l, i; ResetVertexFlags(theMG, min_level, max_level); /* reset used flags in vertices */ i = 0; for (l=min_level; l<=max_level; l++) { NODE *theNode; GRID *theGrid = GRID_ON_LEVEL(theMG,l); /* reset USED flags in all vertices */ for (theNode=FIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) { if (USED(MYVERTEX(theNode))) continue; SETUSED(MYVERTEX(theNode),1); ID(MYVERTEX(theNode)) = i; i++; } } return(0); }
void pVVECT(int *key, float *V) { MULTIGRID *mg; ELEMENT *e; VERTEX *v; PreprocessingProcPtr pre; ElementVectorProcPtr foo; double *cc[MAX_CORNERS_OF_ELEM], lc[3], vv[3]; int i, k; k = (*key)-1; mg = GetCurrentMultigrid(); pre = eval[k].v->PreprocessProc; if (pre != NULL) pre(eval_name[k], mg); foo = eval[k].v->EvalProc; mg = GetCurrentMultigrid(); ClearVertexMarkers(mg); SURFACE_LOOP_BEGIN(mg, e) for (i = 0; i < CORNERS_OF_ELEM(e); i++) cc[i] = CVECT(MYVERTEX(CORNER(e, i))); for (i = 0; i < CORNERS_OF_ELEM(e); i++) { v = MYVERTEX(CORNER(e, i)); if (USED(v)) continue; SETUSED(v, 1); LocalCornerCoordinates(3, TAG(e), i, lc); foo(e, cc, lc, vv); *V++ = (float)vv[0]; *V++ = (float)vv[1]; *V++ = (float)vv[2]; } SURFACE_LOOP_END }
static void ClearVertexMarkers(MULTIGRID *mg) { VERTEX *v; int i; for (i = 0; i <= TOPLEVEL(mg); i++) for (v = FIRSTVERTEX(GRID_ON_LEVEL(mg, i)); v != NULL; v = SUCCV(v)) SETUSED(v,0); }
void pVSTRUC(int *knode, int *kequiv, int *kcel1, int *kcel2, int *kcel3, int *kcel4, int *knptet, int *kptet, int *knblock, int *blocks, int *kphedra, int *ksurf, int *knsurf, int *hint) { MULTIGRID *mg; ELEMENT *e; VERTEX *v; int i; *knode = *kcel1 = *kcel2 = *kcel3 = *kcel4 = *ksurf = 0; mg = GetCurrentMultigrid(); ClearVertexMarkers(mg); SURFACE_LOOP_BEGIN(mg, e) switch (TAG(e)) { case TETRAHEDRON : (*kcel1)++; break; case PYRAMID : (*kcel2)++; break; case PRISM : (*kcel3)++; break; case HEXAHEDRON : (*kcel4)++; } for (i = 0; i < CORNERS_OF_ELEM(e); i++) { v = MYVERTEX(CORNER(e, i)); if (USED(v)) continue; SETUSED(v, 1); ID(v) = *knode; /* number vertices */ (*knode)++; } /* check for domain boundary sides */ if (OBJT(e) == BEOBJ) { for (i = 0; i < SIDES_OF_ELEM(e); i++) if (SIDE_ON_BND(e, i) && !InnerBoundary(e, i)) (*ksurf)++; } SURFACE_LOOP_END *kequiv = 0; *knptet = 0; *kptet = 0; *knblock = 0; *kphedra = 0; *knsurf = 1; }
static int Scatter_ElementRestriction (DDD_OBJ obj, void *data) { ELEMENT *theElement = (ELEMENT *)obj; int used; PRINTDEBUG(gm,4,(PFMT "Scatter_ElementRestriction(): e=" EID_FMTX "\n", me,EID_PRTX(theElement))) if (EMASTER(theElement)) { PRINTDEBUG(gm,4,(PFMT "Scatter_ElementRestriction(): restricting sons of e=" EID_FMTX "\n", me,EID_PRTX(theElement))) used = MAX(USED(theElement),((int *)data)[0]); SETUSED(theElement,used); } return(GM_OK); }
/*---------------------------------------------------------------------- * test if a word is in the dictionary. If so, set its "used" flag *----------------------------------------------------------------------*/ static int use_word(const char *chars) { int i,j,k,cmp; /* tracef("Word %s ?", chars);*/ for (i=0,j=nword; j > i; ) { /* perform binary chop */ k = (i + j) / 2; /* look in the middle */ cmp = strcmp(chars, dict[k]->chars); if (cmp == 0) { /* exact match */ SETUSED(dict[k]); /* mark as used */ /* tracef(" yes");*/ return TRUE; }else if (cmp < 0) { j = k; /* look in first half */ }else{ i = k+1; /* look in second half */ } } return FALSE; }
static INT ResetVertexFlags (MULTIGRID *theMG, INT min_level, INT max_level) { INT l; /* reset used flags in vertices */ for (l=min_level; l<=max_level; l++) { NODE *theNode; GRID *theGrid = GRID_ON_LEVEL(theMG,l); /* reset USED flags in all vertices */ for (theNode=FIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) { SETUSED(MYVERTEX(theNode),0); } } return(0); /* no error */ }
void pVGRID(float *xyz) { MULTIGRID *mg; ELEMENT *e; VERTEX *v; int i; mg = GetCurrentMultigrid(); ClearVertexMarkers(mg); SURFACE_LOOP_BEGIN(mg, e) for (i = 0; i < CORNERS_OF_ELEM(e); i++) { v = MYVERTEX(CORNER(e, i)); if (USED(v)) continue; SETUSED(v, 1); *xyz++ = XC(v); *xyz++ = YC(v); *xyz++ = ZC(v); } SURFACE_LOOP_END }
static INT SendSolution (MULTIGRID *theMG, COVISE_HEADER *covise, INT idx_sol) { INT l, remaining, sent, n_comp_sol; TokenBuffer tb; Message* msg = new Message; msg->type = (covise_msg_type)0; printf("CoviseIF: SendSolution start, idx_sol=%d\n", idx_sol); n_comp_sol = covise->solutions[idx_sol].n_components; /* reset vertex flags */ ResetVertexFlags(theMG, covise->min_level, covise->max_level); /* start first buffer */ tb.reset(); remaining = MIN(covise->n_vertices,MAX_ITEMS_SENT); tb << MT_UGSCALAR; tb << idx_sol; tb << remaining; sent = 0; /* extract data, loop from max_level to min_level! */ /* TODO: special handling in ModelP */ for (l=covise->max_level; l>=covise->min_level; l--) { NODE *theNode; GRID *theGrid = GRID_ON_LEVEL(theMG,l); for (theNode=FIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) { VECTOR *theVector; INT i; INT vid; if (USED(MYVERTEX(theNode))) continue; SETUSED(MYVERTEX(theNode),1); /* NOTE: vid is sent along with data! this increases msg sizes, but is the secure solution (resistent to message order a.s.o.) */ vid = ID(MYVERTEX(theNode)); tb << (INT32)vid; theVector = NVECTOR(theNode); /* extract data from vector */ for(i=0; i<n_comp_sol; i++) { INT comp = covise->solutions[idx_sol].comps[i]; tb << (FLOAT32) VVALUE(theVector,comp); } remaining--; sent++; if (remaining==0) { /* send this buffer */ msg->data = (char*)tb.get_data(); msg->length = tb.get_length(); covise_connection->send_msg(msg); /* start next buffer */ tb.reset(); remaining = MIN(covise->n_vertices - sent, MAX_ITEMS_SENT); tb << MT_UGSCALAR; tb << idx_sol; tb << remaining; } } } delete msg; printf("CoviseIF: SendSolution stop\n"); return(0); }
static INT SendSurfaceGrid (MULTIGRID *theMG, COVISE_HEADER *covise) { INT l, remaining, sent; TokenBuffer tb; Message* msg = new Message; msg->type = (covise_msg_type)0; printf("CoviseIF: SendSurfaceGrid start\n"); /* renumber vertex IDs */ /* TODO doesn't work in ModelP */ RenumberVertices(theMG, covise->min_level, covise->max_level); /* send surface vertices, part1: set flags */ ResetVertexFlags(theMG, covise->min_level, covise->max_level); /* send surface vertices, part2: send data */ sent = 0; /* start first buffer */ tb.reset(); remaining = MIN(covise->n_vertices,MAX_ITEMS_SENT); tb << MT_UGGRIDV; tb << remaining; for (l=covise->min_level; l<=covise->max_level; l++) { NODE *theNode; GRID *theGrid = GRID_ON_LEVEL(theMG,l); for (theNode=FIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) { INT vid; DOUBLE *pos; if (USED(MYVERTEX(theNode))) continue; SETUSED(MYVERTEX(theNode),1); /* extract data from vertex */ /* TODO use VXGID in ModelP */ vid = ID(MYVERTEX(theNode)); pos = CVECT(MYVERTEX(theNode)); tb << (INT32)vid; tb << (FLOAT32)pos[0]; tb << (FLOAT32)pos[1]; tb << (FLOAT32)pos[2]; remaining--; sent++; if (remaining==0) { /* send this buffer */ msg->data = (char*)tb.get_data(); msg->length = tb.get_length(); covise_connection->send_msg(msg); /* start next buffer */ tb.reset(); tb << MT_UGGRIDV; remaining = MIN(covise->n_vertices - sent, MAX_ITEMS_SENT); tb << remaining; } } } printf("CoviseIF: SendSurfaceGrid ...\n"); /* next buffer */ tb.reset(); tb << MT_UGGRIDE; remaining = MIN(covise->n_elems,MAX_ITEMS_SENT); tb << remaining; sent = 0; /* send surface elems and connectivity */ for (l=covise->min_level; l<=covise->max_level; l++) { ELEMENT *theElement; GRID *theGrid = GRID_ON_LEVEL(theMG,l); for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if ((EstimateHere(theElement)) || (l==covise->max_level)) { int i, coe = CORNERS_OF_ELEM(theElement); tb << (INT32)coe; for (i=0; i<coe; i++) { NODE *theNode = CORNER(theElement,i); INT vid; vid = ID(MYVERTEX(theNode)); /* TODO use VXGID in ModelP */ tb << (INT32)vid; } remaining--; sent++; if (remaining==0) { /* send this buffer */ msg->data = (char*)tb.get_data(); msg->length = tb.get_length(); covise_connection->send_msg(msg); /* start next buffer */ tb.reset(); tb << MT_UGGRIDE; remaining = MIN(covise->n_elems - sent, MAX_ITEMS_SENT); tb << remaining; } } } } /* cleanup */ delete msg; printf("CoviseIF: SendSurfaceGrid stop\n"); return(0); }
INT NS_DIM_PREFIX RestrictPartitioning (MULTIGRID *theMG) { INT i,j; ELEMENT *theElement; ELEMENT *theFather; ELEMENT *SonList[MAX_SONS]; GRID *theGrid; /* reset used flags */ for (i=TOPLEVEL(theMG); i>=0; i--) { theGrid = GRID_ON_LEVEL(theMG,i); for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { SETUSED(theElement,0); } } /* set flags on elements which violate restriction */ for (i=TOPLEVEL(theMG); i>=0; i--) { theGrid = GRID_ON_LEVEL(theMG,i); for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (GLEVEL(theGrid) == 0) break; if (LEAFELEM(theElement) || USED(theElement)) { theFather = theElement; while (EMASTER(theFather) && ECLASS(theFather)!=RED_CLASS && LEVEL(theFather)>0) { theFather = EFATHER(theFather); } /* if father with red refine class is not master */ /* partitioning must be restricted */ if (!EMASTER(theFather)) { /* the sons of father will be sent to partition of father */ SETUSED(theFather,1); } /* if element is marked for coarsening and father */ /* of element is not master -> restriction is needed */ if (COARSEN(theFather)) { /* level 0 elements are not coarsened */ if (LEVEL(theFather)<=1) continue; if (!EMASTER(EFATHER(theFather))) SETUSED(EFATHER(theFather),1); } } } /* transfer restriction flags to master copies of father */ DDD_IFAOneway(ElementVHIF,GRID_ATTR(theGrid),IF_BACKWARD,sizeof(INT), Gather_ElementRestriction, Scatter_ElementRestriction); } /* send restricted sons to partition of father */ for (i=0; i<=TOPLEVEL(theMG); i++) { theGrid = GRID_ON_LEVEL(theMG,i); /* transfer (new) partitions of elements to non master copies */ DDD_IFAOnewayX(ElementVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), Gather_RestrictedPartition, Scatter_RestrictedPartition); for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (!USED(theElement)) continue; /* push partition to the sons */ GetAllSons(theElement,SonList); for (j=0; SonList[j]!=NULL; j++) { SETUSED(SonList[j],1); if (EMASTER(SonList[j])) PARTITION(SonList[j]) = PARTITION(theElement); } } } if (TransferGrid(theMG) != 0) RETURN(GM_FATAL); return(GM_OK); }
void NS_DIM_PREFIX SetGhostObjectPriorities (GRID *theGrid) { ELEMENT *theElement,*theNeighbor,*SonList[MAX_SONS]; NODE *theNode; EDGE *theEdge; VECTOR *theVector; INT i,prio,*proclist,hghost,vghost; /* reset USED flag for objects of ghostelements */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { SETUSED(theElement,0); SETTHEFLAG(theElement,0); for (i=0; i<EDGES_OF_ELEM(theElement); i++) { theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0)), CORNER(theElement,CORNER_OF_EDGE(theElement,i,1))); ASSERT(theEdge != NULL); SETUSED(theEdge,0); SETTHEFLAG(theEdge,0); } if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) for (i=0; i<SIDES_OF_ELEM(theElement); i++) { theVector = SVECTOR(theElement,i); if (theVector != NULL) { SETUSED(theVector,0); SETTHEFLAG(theVector,0); } } } /* to reset also nodes which are at corners of the boundary */ /* reset of nodes need to be done through the node list */ for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) { SETUSED(theNode,0); SETTHEFLAG(theNode,0); SETMODIFIED(theNode,0); } /* set FLAG for objects of horizontal and vertical overlap */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (PARTITION(theElement) == me) continue; /* check for horizontal ghost */ hghost = 0; for (i=0; i<SIDES_OF_ELEM(theElement); i++) { theNeighbor = NBELEM(theElement,i); if (theNeighbor == NULL) continue; if (PARTITION(theNeighbor) == me) { hghost = 1; break; } } /* check for vertical ghost */ vghost = 0; GetAllSons(theElement,SonList); for (i=0; SonList[i]!=NULL; i++) { if (PARTITION(SonList[i]) == me) { vghost = 1; break; } } /* one or both of vghost and hghost should be true here */ /* except for elements which will be disposed during Xfer */ if (vghost) SETTHEFLAG(theElement,1); if (hghost) SETUSED(theElement,1); for (i=0; i<CORNERS_OF_ELEM(theElement); i++) { theNode = CORNER(theElement,i); if (vghost) SETTHEFLAG(theNode,1); if (hghost) SETUSED(theNode,1); } for (i=0; i<EDGES_OF_ELEM(theElement); i++) { theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement,i,0), CORNER_OF_EDGE_PTR(theElement,i,1)); ASSERT(theEdge != NULL); if (vghost) SETTHEFLAG(theEdge,1); if (hghost) SETUSED(theEdge,1); } if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) for (i=0; i<SIDES_OF_ELEM(theElement); i++) { theVector = SVECTOR(theElement,i); if (theVector != NULL) { if (vghost) SETTHEFLAG(theVector,1); if (hghost) SETUSED(theVector,1); } } } DEBUG_TIME(0); /* set USED flag for objects of master elements */ /* reset FLAG for objects of master elements */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (PARTITION(theElement) != me) continue; SETUSED(theElement,0); SETTHEFLAG(theElement,0); for (i=0; i<CORNERS_OF_ELEM(theElement); i++) { theNode = CORNER(theElement,i); SETUSED(theNode,0); SETTHEFLAG(theNode,0); SETMODIFIED(theNode,1); } for (i=0; i<EDGES_OF_ELEM(theElement); i++) { theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement,i,0), CORNER_OF_EDGE_PTR(theElement,i,1)); ASSERT(theEdge != NULL); SETUSED(theEdge,0); SETTHEFLAG(theEdge,0); } if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) for (i=0; i<SIDES_OF_ELEM(theElement); i++) { theVector = SVECTOR(theElement,i); if (theVector != NULL) { SETUSED(theVector,0); SETTHEFLAG(theVector,0); } } } DEBUG_TIME(0); /* set object priorities for ghostelements */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { if (PARTITION(theElement) == me) continue; if (USED(theElement) || THEFLAG(theElement)) { prio = PRIO_CALC(theElement); PRINTDEBUG(gm,1,("SetGhostObjectPriorities(): e=" EID_FMTX " new prio=%d\n", EID_PRTX(theElement),prio)) SETEPRIOX(theElement,prio); if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,ELEMVEC)) { theVector = EVECTOR(theElement); if (theVector != NULL) SETPRIOX(theVector,prio); } } /* set edge priorities */ for (i=0; i<EDGES_OF_ELEM(theElement); i++) { theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0)), CORNER(theElement,CORNER_OF_EDGE(theElement,i,1))); ASSERT(theEdge != NULL); if (USED(theEdge) || THEFLAG(theEdge)) { PRINTDEBUG(dddif,3,(PFMT " dddif_SetGhostObjectPriorities():" " downgrade edge=" EDID_FMTX " from=%d to PrioHGhost\n", me,EDID_PRTX(theEdge),prio)); EDGE_PRIORITY_SET(theGrid,theEdge,PRIO_CALC(theEdge)); } else EDGE_PRIORITY_SET(theGrid,theEdge,PrioMaster); } #ifdef __THREEDIM__ /* if one(all) of the side nodes is (are) a hghost (vghost) node */ /* then its a hghost (vghost) side vector */ if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) for (i=0; i<SIDES_OF_ELEM(theElement); i++) { if (USED(theVector) || THEFLAG(theVector)) SETPRIOX(theVector,PRIO_CALC(theVector)); } #endif } /* to set also nodes which are at corners of the boundary */ /* set them through the node list */ for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode)) { /* check if its a master node */ if (USED(theNode) || THEFLAG(theNode)) { PRINTDEBUG(dddif,3,(PFMT " dddif_SetGhostObjectPriorities():" " downgrade node=" ID_FMTX " from=%d to PrioHGhost\n", me,ID_PRTX(theNode),prio)); /* set node priorities of node to ghost */ NODE_PRIORITY_SET(theGrid,theNode,PRIO_CALC(theNode)) } else if (MODIFIED(theNode) == 0)