CDECL void FEM_Set_roccom_pconn(int fem_mesh,const int *paneFmChunk,const int *src,int total_len,int ghost_len) { const char *caller="FEM_Set_roccom_pconn"; FEMAPI(caller); FEM_Mesh *m=FEM_Mesh_lookup(fem_mesh,caller); /// FIXME: only sets shared nodes for now (should grab ghosts too) makeIDXLside(src,paneFmChunk,m->node.shared); }
void FEM_mesh_smooth(int mesh, int *nodes, int nNodes, int attrNo) { vector2d newPos, *coords, *ghostCoords,theCoord; int nNod, nGn, *boundVals, nodesInChunk; int neighbors[3], *adjnodes; int gIdxN; FEM_Mesh *meshP = FEM_Mesh_lookup(mesh, "driver"); nodesInChunk = FEM_Mesh_get_length(mesh,FEM_NODE); boundVals = new int[nodesInChunk]; nGn = FEM_Mesh_get_length(mesh, FEM_GHOST + FEM_NODE); coords = new vector2d[nodesInChunk+nGn]; FEM_Mesh_data(mesh, FEM_NODE, FEM_BOUNDARY, (int*) boundVals, 0, nodesInChunk, FEM_INT, 1); FEM_Mesh_data(mesh, FEM_NODE, attrNo, (double*)coords, 0, nodesInChunk, FEM_DOUBLE, 2); IDXL_Layout_t coord_layout = IDXL_Layout_create(IDXL_DOUBLE, 2); FEM_Update_ghost_field(coord_layout,-1, coords); ghostCoords = &(coords[nodesInChunk]); // FEM_Mesh_data(FEM_Mesh_default_write(), FEM_GHOST+FEM_NODE, attrNo, (double*)ghostCoords, 0, nGn, FEM_DOUBLE, 2); for (int i=0; i<nNodes; i++) { newPos.x=0; newPos.y=0; CkAssert(nodes[i]<nodesInChunk); if (FEM_is_valid(mesh, FEM_NODE, i) && boundVals[i]>-1) //node must be internal { meshP->n2n_getAll(i, &adjnodes, &nNod); // for (int j=0; j<nNod; j++) CkPrintf("node[%d]: %d\n", i,adjnodes[j]); for (int j=0; j<nNod; j++) { //for all adjacent nodes, find coords if (adjnodes[j]<-1) { gIdxN = FEM_From_ghost_index(adjnodes[j]); newPos.x += theCoord.x=ghostCoords[gIdxN].x; newPos.y += theCoord.y=ghostCoords[gIdxN].y; } else { newPos.x += theCoord.x=coords[adjnodes[j]].x; newPos.y += theCoord.y=coords[adjnodes[j]].y; } int rank=FEM_My_partition(); if (rank==0 && i==3 || rank==1 && i==17) { CkPrintf("node[%d]: %d\n", i,adjnodes[j]); CkPrintf("%d: (%f, %f)\n", j, theCoord.x, theCoord.y); } } newPos.x/=nNod; newPos.y/=nNod; FEM_set_entity_coord2(mesh, FEM_NODE, nodes[i], newPos.x, newPos.y); delete [] adjnodes; } } // FEM_Update_field(coord_layout, coords); // FEM_Mesh_data(FEM_Mesh_default_write(), FEM_NODE, attrNo, (double*)coords, 0, nodesInChunk, FEM_DOUBLE, 2); if (coords) delete [] coords; delete [] boundVals; }
/** Based on shared node communication list, compute FEM_NODE FEM_GLOBALNO and FEM_NODE_PRIMARY */ CDECL void FEM_Make_node_globalno(int fem_mesh,FEM_Comm_t comm_context) { const char *caller="FEM_Make_node_globalno"; FEMAPI(caller); FEM_Mesh *m=FEM_Mesh_lookup(fem_mesh,caller); int n, nNo=m->node.size(); const IDXL_Side &shared=m->node.shared; CkVec<int> globalNo(nNo); CkVec<char> nodePrimary(nNo); // Figure out how each of our nodes is shared int nLocal=0; for (n=0;n<nNo;n++) { switch (commState(n,shared)) { case comm_unshared: nodePrimary[n]=0; globalNo[n]=nLocal++; break; case comm_shared: nodePrimary[n]=0; globalNo[n]=-1; // will be filled in during sendsum, below break; case comm_primary: nodePrimary[n]=1; globalNo[n]=nLocal++; break; }; } // Compute global numbers across processors // as the sum of local (unshared and primary) nodes: MPI_Comm comm=(MPI_Comm)comm_context; int firstGlobal=0; // global number of first local element MPI_Scan(&nLocal,&firstGlobal, 1,MPI_INT, MPI_SUM,comm); firstGlobal-=nLocal; /* sum of all locals before me, but *not* including */ for (n=0;n<nNo;n++) { if (globalNo[n]==-1) globalNo[n]=0; else globalNo[n]+=firstGlobal; } // Get globalNo for shared nodes, by copying from primary. IDXL_Layout_t l=IDXL_Layout_create(IDXL_INT,1); IDXL_Comm_t c=IDXL_Comm_begin(72173841,comm_context); IDXL_Comm_sendsum(c,FEM_Comm_shared(fem_mesh,FEM_NODE),l,&globalNo[0]); IDXL_Comm_wait(c); IDXL_Layout_destroy(l); // Copy globalNo and primary into fem FEM_Mesh_set_data(fem_mesh,FEM_NODE, FEM_GLOBALNO, &globalNo[0], 0,nNo, FEM_INDEX_0,1); FEM_Mesh_set_data(fem_mesh,FEM_NODE, FEM_NODE_PRIMARY, &nodePrimary[0], 0,nNo, FEM_BYTE,1); }
CDECL void FEM_Add_elem2face_tuples(int fem_mesh, int elem_type, int nodesPerTuple, int tuplesPerElem,const int *elem2tuple) { FEMAPI("FEM_Add_elem2face_tuples"); FEM_Mesh *m = FEM_Mesh_lookup(fem_mesh,"FEM_Add_elem2face_tuples"); FEM_ElemAdj_Layer *cur=m->getElemAdjLayer(); // creates the structure on first access cur->initialized = 1; if(cur->elem[elem_type].tuplesPerElem != 0) CkPrintf("FEM> WARNING: Don't call FEM_Add_elem2face_tuples() repeatedly with the same element type\n"); int idxBase=0; cur->nodesPerTuple=nodesPerTuple; cur->elem[elem_type].tuplesPerElem=tuplesPerElem; cur->elem[elem_type].elem2tuple=CkCopyArray(elem2tuple, tuplesPerElem*cur->nodesPerTuple,idxBase); }
void rebuildArrays (int mesh, myGlobals &g) { CkPrintf("Rebuilding arrays. \n"); delete [] g.conn; delete [] g.coord; delete [] g.vCoord; delete [] g.vConn; g.nelems=FEM_Mesh_get_length(mesh, FEM_ELEM); g.nnodes=FEM_Mesh_get_length(mesh, FEM_NODE); g.nVnodes = FEM_count_valid(mesh, FEM_NODE); g.nVelems = FEM_count_valid(mesh, FEM_ELEM); g.coord=new vector2d[g.nnodes]; g.conn=new connRec[g.nelems]; g.vConn = new connRec[g.nVelems]; g.vCoord = new vector2d[g.nVnodes]; FEM_Mesh_data(mesh, FEM_NODE, FEM_DATA, (double *)g.coord, 0, g.nnodes, FEM_DOUBLE, 2); int j=0; for (int i=0; i<g.nnodes;i++) { if (FEM_is_valid(mesh, FEM_NODE, i)) { // CkPrintf("g.coord[%d]: (%f, %f) \n", i, g.coord[i].x, g.coord[i].y); g.vCoord[j]=g.coord[i]; j++; } } j=0; for (int i=0; i<g.nelems;i++) { FEM_Mesh_lookup(mesh, "driver")->e2n_getAll(i, (int *)g.conn[i]); if (FEM_is_valid(mesh, FEM_ELEM, i)) { // CkPrintf("g.conn[%d]: (%d, %d, %d) \n", i, g.conn[i][0], g.conn[i][1], g.conn[i][2]); for (int k=0; k<3; k++) g.vConn[j][k]=g.conn[i][k]; j++; } } }
CDECL void FEM_Mesh_get2ElementsOnEdgeSorted(int fem_mesh, int n1, int n2, int *e1, int *e2){ const char *caller="FEM_Mesh_get2ElementsOnEdge"; FEMAPI(caller); FEM_Mesh *m=FEM_Mesh_lookup(fem_mesh,caller); m->get2ElementsOnEdgeSorted(n1, n2, e1, e2); }
CDECL void FEM_Mesh_create_elem_elem_adjacency(int fem_mesh){ const char *caller="FEM_Mesh_create_elem_elem_adjacency"; FEMAPI(caller); FEM_Mesh *m=FEM_Mesh_lookup(fem_mesh,caller); m->createElemElemAdj(); }
// A driver() function // driver() is required in all FEM programs extern "C" void driver(void) { int *neighbors, *adjnodes, adjSz, *adjelems; int nnodes,nelems,nelems2,ignored; int i,t=0, myId=FEM_My_partition(); myGlobals g; g.coord=NULL; g.conn=NULL; g.vCoord=NULL; g.vConn=NULL; FEM_Register(&g,(FEM_PupFn)pup_myGlobals); int mesh=FEM_Mesh_default_read(); // Tell framework we are reading data from the mesh FEM_Mesh *meshP = FEM_Mesh_lookup(mesh, "driver"); _registerFEMMeshModify(); printf("partition %d is in driver\n", myId); { int j, t=0; const int triangleFaces[6] = {0,1,1,2,2,0}; FEM_Add_elem2face_tuples(mesh, 0, 2, 3, triangleFaces); FEM_Mesh_create_elem_elem_adjacency(mesh); FEM_Mesh_allocate_valid_attr(mesh, FEM_ELEM+0); FEM_Mesh_allocate_valid_attr(mesh, FEM_NODE); FEM_Mesh_create_node_elem_adjacency(mesh); FEM_Mesh_create_node_node_adjacency(mesh); FEM_Print_Mesh_Summary(mesh); int tuplesPerElem = 3; int elementNum = 0; int rank = 0; MPI_Comm comm = MPI_COMM_WORLD; MPI_Comm_rank(comm,&rank); MPI_Barrier(comm); FEM_REF_INIT(mesh); MPI_Barrier(comm); //********************* Test mesh modification here **************************// double meanArea=0.0; FEM_Adapt *adaptor= meshP->getfmMM()->getfmAdaptL(); doNetFEM(t, mesh, g); FEM_Adapt_Algs *adaptAlgs= meshP->getfmMM()->getfmAdaptAlgs(); adaptAlgs->FEM_Adapt_Algs_Init(FEM_DATA+0, FEM_BOUNDARY); FEM_Interpolate *interp = meshP->getfmMM()->getfmInp(); interp->FEM_SetInterpolateNodeEdgeFnPtr(interpolate); /* adaptor->edge_contraction(5,2); adaptor->edge_contraction(1,4); adaptor->edge_contraction(25,13); adaptor->edge_contraction(43,47); adaptor->edge_contraction(40,39); adaptor->edge_contraction(21,22); adaptor->edge_contraction(9,52); adaptor->edge_contraction(19,29); adaptor->edge_contraction(42,14); adaptor->edge_contraction(12,50); adaptor->edge_contraction(26,46);*/ doNetFEM(t, mesh, g); CkPrintf("*************** CONTRACTION *************** \n"); printQualityInfo(g, meanArea); int *nodes=NULL, *adjnodes, nNod; for (int c=0; c<3; c++) { for (int i=0; i<g.nelems; i++) { if (FEM_is_valid(mesh, FEM_ELEM, i)) adaptAlgs->refine_element_leb(i); } doNetFEM(t, mesh, g); CkPrintf("*************** REFINEMENT *************** \n"); printQualityInfo(g, meanArea); /* if (rank==0) { meshP->n2n_getAll(3, &adjnodes, &nNod); for (int j=0; j<nNod; j++) CkPrintf("node[%d]: %d\n", 3,adjnodes[j]); } else if (rank==1) { meshP->n2n_getAll(17, &adjnodes, &nNod); for (int j=0; j<nNod; j++) CkPrintf("node[%d]: %d\n", 17,adjnodes[j]); } // CkPrintf("%d: (%f, %f)\n", j, theCoord.x, theCoord.y); */ delete[] nodes; nodes = NULL; // for (int i=0; i<g.nnodes; i++) nodes[i]=i; for (int i=0; i<3; i++) { adaptAlgs->FEM_mesh_smooth(meshP, NULL, g.nnodes, FEM_DATA+0); doNetFEM(t, mesh, g); CkPrintf("*************** SMOOTHING **************** \n"); printQualityInfo(g, meanArea); } } FEM_Print_Mesh_Summary(mesh); CkPrintf("Chunk %d Waiting for Synchronization\n",rank); MPI_Barrier(comm); CkPrintf("Synchronized\n"); CkExit(); } CkPrintf("Driver finished.\n"); }
// A driver() function // driver() is required in all FEM programs extern "C" void driver(void) { int nnodes,nelems,nelems2,ignored; int i, myId=FEM_My_partition(); myGlobals g; FEM_Register(&g,(FEM_PupFn)pup_myGlobals); _registerFEMMeshModify(); printf("partition %d is in driver\n", myId); int mesh=FEM_Mesh_default_read(); // Tell framework we are reading data from the mesh // Get node data nnodes=FEM_Mesh_get_length(mesh,FEM_NODE); // Get number of nodes g.nnodes=nnodes; g.coord=new vector3d[nnodes]; // Get node positions FEM_Mesh_data(mesh, FEM_NODE, FEM_DATA+0, (double*)g.coord, 0, nnodes, FEM_DOUBLE, 3); // Get element data nelems=FEM_Mesh_get_length(mesh,FEM_ELEM+0); // Get number of elements g.nelems=nelems; g.conn=new connRec[nelems]; // Get connectivity for elements FEM_Mesh_data(mesh, FEM_ELEM+0, FEM_CONN, (int *)g.conn, 0, nelems, FEM_INDEX_0, 4); double* tridata =new double[nelems]; FEM_Mesh_data(mesh, FEM_ELEM+0, FEM_DATA, (int *)tridata, 0, nelems, FEM_DOUBLE, 1); int nelemsghost=FEM_Mesh_get_length(mesh,FEM_ELEM+0+FEM_GHOST); double* trighostdata =new double[nelemsghost]; FEM_Mesh_data(mesh, FEM_ELEM+0+FEM_GHOST, FEM_DATA, (int *)trighostdata, 0, nelemsghost, FEM_DOUBLE, 1); int nnodesghost=FEM_Mesh_get_length(mesh,FEM_NODE+0+FEM_GHOST); double* nodeghostdata =new double[3*nnodesghost]; FEM_Mesh_data(mesh, FEM_NODE+0+FEM_GHOST, FEM_DATA, (int *)nodeghostdata, 0, nnodesghost, FEM_DOUBLE, 3); { const int triangleFaces[12] = {0,1,2,1,2,3,2,3,0,0,3,1}; FEM_Add_elem2face_tuples(mesh, 0, 3, 4, triangleFaces); FEM_Mesh_create_elem_elem_adjacency(mesh); FEM_Mesh_allocate_valid_attr(mesh, FEM_ELEM+0); FEM_Mesh_allocate_valid_attr(mesh, FEM_NODE); FEM_Mesh_create_node_elem_adjacency(mesh); FEM_Mesh_create_node_node_adjacency(mesh); int netIndex = 0; publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif int rank = 0; MPI_Comm comm = MPI_COMM_WORLD; MPI_Comm_rank(comm,&rank); MPI_Barrier(comm); FEM_REF_INIT(mesh); FEM_Mesh *meshP = FEM_Mesh_lookup(FEM_Mesh_default_read(),"driver"); FEM_AdaptL *ada = meshP->getfmMM()->getfmAdaptL(); int ret_op = -1; FEM_Adapt_Algs *adaptAlgs= meshP->getfmMM()->getfmAdaptAlgs(); adaptAlgs->FEM_Adapt_Algs_Init(FEM_DATA+0,FEM_DATA+4); FEM_Interpolate *interp = meshP->getfmMM()->getfmInp(); //interp->FEM_SetInterpolateNodeEdgeFnPtr(interpolate); MPI_Barrier(comm); //CkPrintf("Shadow arrays have been bound\n"); /* #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif CkPrintf("Marking 5 nodes and one element as invalid\n"); FEM_set_entity_invalid(mesh, FEM_NODE, 5); FEM_set_entity_invalid(mesh, FEM_NODE, 6); FEM_set_entity_invalid(mesh, FEM_NODE, 7); FEM_set_entity_invalid(mesh, FEM_NODE, 8); FEM_set_entity_invalid(mesh, FEM_NODE, 9); FEM_set_entity_invalid(mesh, FEM_ELEM, 9); #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif CkPrintf("Marking 5 nodes and one element as valid again\n"); FEM_set_entity_valid(mesh, FEM_NODE, 5); FEM_set_entity_valid(mesh, FEM_NODE, 6); FEM_set_entity_valid(mesh, FEM_NODE, 7); FEM_set_entity_valid(mesh, FEM_NODE, 8); FEM_set_entity_valid(mesh, FEM_NODE, 9); FEM_set_entity_valid(mesh, FEM_ELEM, 9); */ #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif int adjs[4]; int elemid; if(rank == 0) { adjs[0] = 0; adjs[1] = 1; adjs[2] = 2; adjs[3] = 3; elemid = 0; } else if(rank == 1) { adjs[0] = 19; adjs[1] = 5; adjs[2] = 7; adjs[3] = 21; elemid = 21; } else if(rank == 2) { adjs[0] = 8; adjs[1] = 11; adjs[2] = 6; adjs[3] = 21; elemid = 7; } else { adjs[0] = 0; adjs[1] = 1; adjs[2] = 2; adjs[3] = 3; elemid = 0; } int newel1 = 0; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); FEM_Print_n2e(mesh,adjs[0]); FEM_Print_n2e(mesh,adjs[1]); FEM_Print_n2e(mesh,adjs[2]); FEM_Print_n2e(mesh,adjs[3]); FEM_Print_n2n(mesh,adjs[0]); FEM_Print_n2n(mesh,adjs[1]); FEM_Print_n2n(mesh,adjs[2]); FEM_Print_n2n(mesh,adjs[3]); FEM_Print_e2n(mesh,elemid); FEM_Print_e2e(mesh,elemid); #endif //FEM_Modify_Lock(mesh, adjs, 3, adjs, 0); if(rank == 0) { FEM_remove_element(mesh, elemid, 0, 1); } //FEM_Modify_Unlock(mesh); MPI_Barrier(comm); #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif //FEM_Modify_Lock(mesh, adjs, 3, adjs, 0); if(rank == 0) { newel1 = FEM_add_element(mesh,adjs,4,0,0); CkPrintf("New Element\n"); } //FEM_Modify_Unlock(mesh); publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); FEM_Print_n2e(mesh,adjs[0]); FEM_Print_n2e(mesh,adjs[1]); FEM_Print_n2e(mesh,adjs[2]); FEM_Print_n2e(mesh,adjs[3]); FEM_Print_n2n(mesh,adjs[0]); FEM_Print_n2n(mesh,adjs[1]); FEM_Print_n2n(mesh,adjs[2]); FEM_Print_n2n(mesh,adjs[3]); FEM_Print_e2n(mesh,newel1); FEM_Print_e2e(mesh,newel1); #endif /* if(rank==0){ FEM_Print_Mesh_Summary(mesh); CkPrintf("%d: Removing element \n", rank); int nelemsghost =FEM_Mesh_get_length(mesh,FEM_ELEM+0+FEM_GHOST); int numvalidghost =FEM_count_valid(mesh,FEM_ELEM+0+FEM_GHOST); CkPrintf("nelemsghost=%d numvalidghost=%d\n", nelemsghost, numvalidghost); for(int i=1;i<20;i++){ if(FEM_is_valid(mesh, FEM_ELEM+FEM_GHOST, i)){ double data[1]; FEM_Mesh_data(mesh, FEM_ELEM+FEM_GHOST, FEM_DATA, (int *)data, i, 1, FEM_DOUBLE, 1); CkPrintf("%d: Eating ghost element %d with value %f\n", rank, i, data[1]); int conn[3]; FEM_Mesh_data(mesh, FEM_ELEM+FEM_GHOST, FEM_CONN, (int *)conn, i, 1, FEM_INDEX_0, 3); CkPrintf("conn for element is: %d %d %d\n", conn[0], conn[1], conn[2]); FEM_Modify_Lock(mesh, conn, 3, conn, 0); FEM_remove_element(mesh, FEM_From_ghost_index(i), 0, 1); FEM_Modify_Unlock(mesh); MPI_Barrier(comm); FEM_Print_Mesh_Summary(mesh); FEM_Modify_Lock(mesh, conn, 3, conn, 0); FEM_add_element(mesh, conn, 3, 0, rank); // add locally FEM_Modify_Unlock(mesh); CkPrintf("New conn for element is: %d %d %d\n", conn[0], conn[1], conn[2]); publish_data_netfem(netIndex,g); netIndex++; FEM_Print_Mesh_Summary(mesh); } else{ // CkPrintf("invalid element %d\n", i); } } } else { CkPrintf("Rank %d\n", rank); for(int i=1;i<20;i++){ MPI_Barrier(comm); FEM_Print_Mesh_Summary(mesh); publish_data_netfem(netIndex,g); netIndex++; FEM_Print_Mesh_Summary(mesh); } } publish_data_netfem(netIndex,g); netIndex++; */ /* CkPrintf("Starting Local edge flips on individual chunks\n"); int flip[4]; if(rank == 0) { flip[0] = 1; flip[1] = 2; flip[2] = 0; flip[3] = 3; } else if(rank == 1) { flip[0] = 1; flip[1] = 2; flip[2] = 0; flip[3] = 4; } else if(rank == 2) { flip[0] = 13; flip[1] = 14; flip[2] = 15; flip[3] = 7; } else { flip[0] = 0; flip[1] = 1; flip[2] = 2; flip[3] = 3; } #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif ret_op = ada->edge_flip(flip[0],flip[1]); publish_data_netfem(netIndex,g); netIndex++; ret_op = ada->edge_flip(flip[2],flip[3]); publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif CkPrintf("Starting shared edge flips on individual chunks\n"); int sflip[4]; if(rank == 0) { sflip[0] = 19; sflip[1] = 18; sflip[2] = 1; sflip[3] = -4; } else if(rank == 1) { sflip[0] = 5; sflip[1] = 6; sflip[2] = 7; sflip[3] = -5; } else if(rank == 2) { sflip[0] = 11; sflip[1] = 2; sflip[2] = 0; sflip[3] = -2; } else { sflip[0] = 0; sflip[1] = 1; sflip[2] = 2; sflip[3] = 3; } #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif ret_op = ada->edge_flip(sflip[0],sflip[1]); publish_data_netfem(netIndex,g); netIndex++; if(ret_op > 0) { if(sflip[2]<0) sflip[2] = ret_op; else if(sflip[3]<0) sflip[3] = ret_op; } ret_op = ada->edge_flip(sflip[2],sflip[3]); publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif CkPrintf("Starting Local edge bisect on individual chunks\n"); int bisect[2]; if(rank == 0) { bisect[0] = 16; bisect[1] = 21; } else if(rank == 1) { bisect[0] = 5; bisect[1] = 6; } else if(rank == 2) { bisect[0] = 8; bisect[1] = 11; } else { bisect[0] = 0; bisect[1] = 1; } if(rank==2) ret_op = ada->edge_bisect(bisect[0],bisect[1]); publish_data_netfem(netIndex,g); netIndex++; adaptAlgs->tests(); MPI_Barrier(comm); #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif CkPrintf("Starting Local vertex remove on individual chunks\n"); int vr[2]; if(rank == 0) { vr[0] = ret_op; vr[1] = 6; } else if(rank == 1) { vr[0] = ret_op; vr[1] = 13; } else if(rank == 2) { vr[0] = ret_op; vr[1] = 21; } else { vr[0] = ret_op; vr[1] = 1; } #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif ret_op = ada->vertex_remove(vr[0],vr[1]); publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif CkPrintf("Starting shared edge bisect on individual chunks\n"); int sbisect[2]; if(rank == 0) { sbisect[0] = 1;//4;//21; sbisect[1] = 19;//20; } else if(rank == 1) { sbisect[0] = 0; sbisect[1] = 21; } else if(rank == 2) { sbisect[0] = 20;//9;//3; sbisect[1] = 8;//2;//19; } else { sbisect[0] = 0; sbisect[1] = 1; } #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif ret_op = ada->edge_bisect(sbisect[0],sbisect[1]); publish_data_netfem(netIndex,g); netIndex++; CkPrintf("Starting shared vertex remove on individual chunks\n"); int svr[2]; if(rank == 0) { svr[0] = ret_op; svr[1] = 19; } else if(rank == 1) { svr[0] = ret_op; svr[1] = 21; } else if(rank == 2) { svr[0] = ret_op; svr[1] = 20; } else { svr[0] = ret_op; svr[1] = 1; } #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif ret_op = ada->vertex_remove(svr[0],svr[1]); publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif CkPrintf("Starting Local edge contract on individual chunks\n"); int contract[2]; if(rank == 0) { contract[1] = 16; contract[0] = 21; } else if(rank == 1) { contract[0] = 5; contract[1] = 6; } else if(rank == 2) { contract[0] = 19; contract[1] = 17; } else { contract[0] = 0; contract[1] = 1; } #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif if(rank==0) ret_op = ada->edge_contraction(contract[0],contract[1]); publish_data_netfem(netIndex,g); netIndex++; //CkPrintf("Starting Local vertex split on individual chunks\n"); /* int vs[3]; if(rank == 0) { vs[0] = ret_op; vs[1] = 9; vs[2] = 13; } else if(rank == 1) { vs[0] = ret_op; vs[1] = 8; vs[2] = 7; } else if(rank == 2) { vs[0] = ret_op; vs[1] = 14; vs[2] = 23; } else { vs[0] = ret_op; vs[1] = 2; vs[2] = 3; } #ifdef SUMMARY_ON //FEM_Print_Mesh_Summary(mesh); #endif //ret_op = ada->vertex_split(vs[0],vs[1],vs[2]); //publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif */ /* CkPrintf("Starting shared edge contract on individual chunks\n"); int scontract[2]; if(rank == 0) { scontract[0] = 9; scontract[1] = 10; } else if(rank == 1) { scontract[0] = 5; scontract[1] = 6; } else if(rank == 2) { scontract[0] = 11; scontract[1] = 2; } else { scontract[0] = 0; scontract[1] = 1; } #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif ret_op = ada->edge_contraction(scontract[0],scontract[1]); publish_data_netfem(netIndex,g); netIndex++; /* //CkPrintf("Starting shared vertex split on individual chunks\n"); int svs[3]; if(rank == 0) { svs[0] = ret_op; svs[1] = 1; svs[2] = -6; } else if(rank == 1) { svs[0] = ret_op; svs[1] = 7; svs[2] = 7; } else if(rank == 2) { svs[0] = ret_op; svs[1] = 0; svs[2] = -2; } else { svs[0] = ret_op; svs[1] = 2; svs[2] = 3; } #ifdef SUMMARY_ON //FEM_Print_Mesh_Summary(mesh); #endif //ret_op = ada->vertex_split(svs[0],svs[1],svs[2]); //publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif */ /* CkPrintf("Starting LEB on individual chunks\n"); int *leb_elem = (int*)malloc(1*sizeof(int)); if(rank==0) { leb_elem[0] = 2; } else if(rank==1) { leb_elem[0] = 13; //4; } else if(rank==2) { leb_elem[0] = 20; //26; } else if (rank == 3){ leb_elem[0] = 14; } else { leb_elem[0] = 0; } adaptAlgs->refine_element_leb(leb_elem[0]); publish_data_netfem(netIndex,g); netIndex++; */ /* int nEle; //for(int tstep = 0; tstep < 2; tstep++) { nEle = FEM_Mesh_get_length(mesh, FEM_ELEM); for (int i=0; i<nEle; i++) if (FEM_is_valid(mesh, FEM_ELEM, i)) adaptAlgs->refine_element_leb(i); publish_data_netfem(netIndex,g); netIndex++; FEM_Print_Mesh_Summary(mesh); //} */ double targetArea = 0.00004; for(int tstep = 0; tstep < 0; tstep++) { adaptAlgs->simple_refine(targetArea); publish_data_netfem(netIndex,g); netIndex++; adaptAlgs->tests(); MPI_Barrier(comm); //int *nodes = new int[g.nnodes]; //for (int i=0; i<g.nnodes; i++) nodes[i]=i; //FEM_mesh_smooth(mesh, nodes, g.nnodes, FEM_DATA+0); //publish_data_netfem(netIndex,g); netIndex++; //delete [] nodes; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif adaptAlgs->simple_coarsen(targetArea); publish_data_netfem(netIndex,g); netIndex++; adaptAlgs->tests(); MPI_Barrier(comm); //int *nodes = new int[g.nnodes]; //for (int i=0; i<g.nnodes; i++) nodes[i]=i; //FEM_mesh_smooth(mesh, nodes, g.nnodes, FEM_DATA+0); //publish_data_netfem(netIndex,g); netIndex++; //delete [] nodes; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif } targetArea = 0.00004; for(int tstep = 0; tstep < 0; tstep++) { adaptAlgs->simple_refine(targetArea); publish_data_netfem(netIndex,g); netIndex++; adaptAlgs->tests(); MPI_Barrier(comm); //int *nodes = new int[g.nnodes]; //for (int i=0; i<g.nnodes; i++) nodes[i]=i; //FEM_mesh_smooth(mesh, nodes, g.nnodes, FEM_DATA+0); //publish_data_netfem(netIndex,g); netIndex++; //delete [] nodes; targetArea *= 0.5; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif } targetArea /= 0.4; for(int tstep = 0; tstep < 0; tstep++) { adaptAlgs->simple_coarsen(targetArea); publish_data_netfem(netIndex,g); netIndex++; adaptAlgs->tests(); MPI_Barrier(comm); //int *nodes = new int[g.nnodes]; //for (int i=0; i<g.nnodes; i++) nodes[i]=i; //FEM_mesh_smooth(mesh, nodes, g.nnodes, FEM_DATA+0); //publish_data_netfem(netIndex,g); netIndex++; //delete [] nodes; targetArea *= 1.5; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif } //wave propagation on a bar targetArea = 0.00004; double xmin = 0.00; double xmax = 0.1; double ymin = 0.00; double ymax = 0.01; for(int tstep = 0; tstep < 0; tstep++) { targetArea = 0.000002; adaptAlgs->simple_refine(targetArea, xmin, ymin, xmax, ymax); publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif targetArea = 0.0000014; adaptAlgs->simple_coarsen(targetArea, xmin, ymin, xmax, ymax); publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif ymin += 0.01; ymax += 0.01; } //crack propagation on a block targetArea = 0.00004; xmin = 0.00; xmax = 0.2; double xcrackmin = 0.09; double xcrackmax = 0.10; ymin = 0.00; ymax = 0.02; for(int tstep = 0; tstep < 0; tstep++) { targetArea = 0.000025; adaptAlgs->simple_refine(targetArea, xmin, ymin, xmax, ymax); publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif targetArea = 0.00005; adaptAlgs->simple_coarsen(targetArea, xmin, ymin, xmax, ymax); //publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif /*if(tstep > 2) { targetArea = 0.000025; adaptAlgs->simple_refine(targetArea, xcrackmin, ymin, xcrackmax, ymax); //publish_data_netfem(netIndex,g); netIndex++; #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif xcrackmin -= 0.004; xcrackmax += 0.004; } */ ymin += 0.02; ymax += 0.02; } CkPrintf("chunk %d Waiting for Synchronization\n",rank); MPI_Barrier(comm); CkPrintf("Synchronized\n"); #ifdef SUMMARY_ON FEM_Print_Mesh_Summary(mesh); #endif publish_data_netfem(netIndex,g); netIndex++; CkExit(); } }
void FEM_mesh_smooth(int mesh, int *nodes, int nNodes, int attrNo) { vector3d *centroids, newPos, *coords, *ghostCoords, *vGcoords; int nEle, nGn, *boundVals, nodesInChunk, nVg; int neighbors[3], *adjelems; int gIdxN; int j=0; double x[3], y[3]; FEM_Mesh *meshP = FEM_Mesh_lookup(mesh, "driver"); nodesInChunk = FEM_Mesh_get_length(mesh,FEM_NODE); boundVals = new int[nodesInChunk]; nGn = FEM_Mesh_get_length(mesh, FEM_GHOST + FEM_NODE); coords = new vector3d[nodesInChunk+nGn]; FEM_Mesh_data(mesh, FEM_NODE, FEM_BOUNDARY, (int*) boundVals, 0, nodesInChunk, FEM_INT, 1); FEM_Mesh_data(mesh, FEM_NODE, attrNo, (double*)coords, 0, nodesInChunk, FEM_DOUBLE, 2); for (int i=0; i<(nodesInChunk); i++) { //CkPrintf(" coords[%d]: (%f, %f)\n", i, coords[i].x, coords[i].y); } IDXL_Layout_t coord_layout = IDXL_Layout_create(IDXL_DOUBLE, 2); FEM_Update_ghost_field(coord_layout,-1, coords); ghostCoords = &(coords[nodesInChunk]); /* for (int i=0; i<nGn;i++) { if (FEM_is_valid(mesh, FEM_GHOST+FEM_NODE, i)) { CkPrintf("ghost %d is valid \n", i); // vGcoords[j]=ghostCoords[i]; //j++; } else CkPrintf("ghost %d is invalid \n", i); } */ for (int i=0; i<(nodesInChunk+nGn); i++) { //CkPrintf(" coords[%d]: (%f, %f)\n", i, coords[i].x, coords[i].y); } // FEM_Mesh_data(FEM_Mesh_default_write(), FEM_GHOST+FEM_NODE, attrNo, (double*)ghostCoords, 0, nGn, FEM_DOUBLE, 2); for (int i=0; i<nNodes; i++) { newPos.x=0; newPos.y=0; CkAssert(nodes[i]<nodesInChunk); if (FEM_is_valid(mesh, FEM_NODE, i) && boundVals[i]>-1) //node must be internal { meshP->n2e_getAll(i, &adjelems, &nEle); centroids = new vector3d[nEle]; for (int j=0; j<nEle; j++) { //for all adjacent elements, find centroids meshP->e2n_getAll(adjelems[j], neighbors); for (int k=0; k<3; k++) { if (neighbors[k]<-1) { gIdxN = FEM_From_ghost_index(neighbors[k]); x[k] = ghostCoords[gIdxN].x; y[k] = ghostCoords[gIdxN].y; } else { x[k] = coords[neighbors[k]].x; y[k] = coords[neighbors[k]].y; } } centroids[j].x=(x[0]+x[1]+x[2])/3.0; centroids[j].y=(y[0]+y[1]+y[2])/3.0; newPos.x += centroids[j].x; newPos.y += centroids[j].y; } newPos.x/=nEle; newPos.y/=nEle; FEM_set_entity_coord2(mesh, FEM_NODE, nodes[i], newPos.x, newPos.y); delete [] centroids; delete [] adjelems; } } delete [] coords; delete [] boundVals; }