static int build_cube (ModeInfo *mi) { int polys = 0; glPushMatrix(); polys += build_face (mi); glRotatef (90, 0, 1, 0); polys += build_face (mi); glRotatef (90, 0, 1, 0); polys += build_face (mi); glRotatef (90, 0, 1, 0); polys += build_face (mi); glRotatef (90, 1, 0, 0); polys += build_face (mi); glRotatef (180,1, 0, 0); polys += build_face (mi); glPopMatrix(); return polys; }
// Build other connectivity arrays void BuildConnectivity(MacroMesh* m) { printf("Build connectivity...\n"); real *bounds = malloc(6 * sizeof(real)); macromesh_bounds(m, bounds); printf("bounds: %f, %f, %f, %f, %f, %f\n", bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); printf("bounds: %f, %f, %f, %f, %f, %f\n", m->xmin[0],m->xmax[0], m->xmin[1],m->xmax[1], m->xmin[2],m->xmax[2] ); // Build a list of faces each face is made of four corners of the // hexaedron mesh Face4Sort *face = malloc(6 * sizeof(Face4Sort) * m->nbelems); build_face(m, face); build_elem2elem(m, face); free(face); build_node2elem(m); // check /* for(int ie = 0;ie<m->nbelems;ie++) { */ /* for(int ifa = 0;ifa<6;ifa++) { */ /* printf("elem=%d face=%d, voisin=%d\n", */ /* ie,ifa,m->elem2elem[ifa+6*ie]); */ /* } */ /* } */ if(m->is2d) suppress_zfaces(m); if(m->is1d) { suppress_zfaces(m); suppress_yfaces(m); } // update connectivity if the mesh is periodic // in some directions real diag[3][3]={1,0,0, 0,1,0, 0,0,1}; for (int ie = 0; ie < m->nbelems; ie++) { real physnode[20][3]; for(int inoloc = 0; inoloc < 20; inoloc++) { int ino = m->elem2node[20 * ie + inoloc]; physnode[inoloc][0] = m->node[3 * ino + 0]; physnode[inoloc][1] = m->node[3 * ino + 1]; physnode[inoloc][2] = m->node[3 * ino + 2]; } for(int ifa = 0; ifa < 6; ifa++) { if (m->elem2elem[6 * ie + ifa] < 0){ real xpgref[3],xpgref_in[3]; int ipgf=0; int param2[7]={0,0,0,1,1,1,0}; ref_pg_face(param2, ifa, ipgf, xpgref, NULL, xpgref_in); real dtau[3][3],xpg_in[3]; real codtau[3][3],vnds[3]={0,0,0}; Ref2Phy(physnode, xpgref_in, NULL, ifa, // dpsiref,ifa xpg_in, dtau, codtau, NULL, vnds); // codtau,dpsi,vnds Normalize(vnds); vnds[0]=fabs(vnds[0]); vnds[1]=fabs(vnds[1]); vnds[2]=fabs(vnds[2]); int dim=0; while(Dist(vnds,diag[dim]) > 1e-2 && dim<3) dim++; //assert(dim < 3); //printf("xpg_in_before=%f\n",xpg_in[dim]); if (dim < 3 && m->period[dim] > 0){ //if (xpg_in[dim] > m->period[dim]){ if (xpg_in[dim] > m->xmax[dim]){ xpg_in[dim] -= m->period[dim]; //printf("xpg_in_after=%f\n",xpg_in[dim]); } //else if (xpg_in[dim] < 0){ else if (xpg_in[dim] < m->xmin[dim]){ xpg_in[dim] += m->period[dim]; //printf("xpg_in_after=%f\n",xpg_in[dim]); } else { //printf("xpg_in=%f\n",xpg_in[dim]); assert(1==2); } m->elem2elem[6 * ie + ifa] = NumElemFromPoint(m,xpg_in,NULL); /* printf("ie=%d ifa=%d numelem=%d vnds=%f %f %f xpg_in=%f %f %f \n", */ /* ie,ifa,NumElemFromPoint(m,xpg_in,NULL), */ /* vnds[0],vnds[1],vnds[2], */ /* xpg_in[0],xpg_in[1],xpg_in[2]); */ } } } } // now, update the face2elem connectivity (because elem2elem has changed) for(int ifa = 0; ifa < m->nbfaces; ifa++) { int ieL = m->face2elem[4 * ifa + 0]; int locfaL = m->face2elem[4 * ifa + 1]; int ieR = m->face2elem[4 * ifa + 2]; int locfaR = m->face2elem[4 * ifa + 3]; int ieR2=m->elem2elem[6 * ieL + locfaL]; if (ieR != ieR2){ assert(ieR == -1); int opp[6]={2,3,0,1,5,4}; if (locfaL == 0 || locfaL == 1 || locfaL == 4) { m->face2elem[4 * ifa + 2] = ieR2; m->face2elem[4 * ifa + 3] = opp[locfaL]; } else { // mark the face for suppression m->face2elem[4 * ifa + 0] = -1; } } } suppress_double_faces(m); //assert(1==5); free(bounds); m->connec_ok = true; /* #ifdef _PERIOD */ /* assert(m->is1d); // TODO : generalize to 2D */ /* assert(m->nbelems==1); */ /* // faces 1 and 3 point to the same unique macrocell */ /* m->elem2elem[1+6*0]=0; */ /* m->elem2elem[3+6*0]=0; */ /* #endif */ }