// 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: GenerateRules.c */ /* */ /* Purpose: generate the rules for ug3d */ /* */ /* Author: Henrik Reichert */ /* Institut fuer Angewandte Mathematik */ /* Universitaet Heidelberg */ /* Im Neuenheimer Feld 294 */ /* 6900 Heidelberg */ /* */ /* History: 10.9.1993 begin */ /* */ /****************************************************************************/ #include #include #include #include #include #include "GenerateRules.h" #include "gm.h" #include "simplex.h" #include "ugrefine3d.h" #include /* only compile for 3D version */ #ifdef UG_DIM_3 /****************************************************************************/ /* */ /* defines and macros */ /* */ /****************************************************************************/ #define PATTERNFILTER 0x3F /* mask for the first 6 digits of pattern: 00111111 */ #define NOFATHERSIDE 5 /* has to be just greater than MAX_SIDES_OF_ELEM */ #define NRULES 242 #define MAXCORNERS 11 /* max no. of new corners (incl. center) */ #define NOTDONE -1 /* SHORT has to be signed! */ #define DONE 0 #define TOUCHED 1 /* has been visited by FindPathForNeighbours*/ /****************************************************************************/ /* */ /* data structures used in this source file (exported data structures are */ /* in the corresponding include file!) */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* global variables */ /* */ /****************************************************************************/ static EDGEDATA EdgeData[MAXCORNERS][MAXCORNERS] = { {{0,0,0,0},{0,0,1,0},{0,0,2,0},{0,0,3,0},{0,0,4,0},{2,0,5,0},{0,0,6,0},{0,0,7,0},{2,0,8,3},{2,0,9,2},{1,0,10,0}}, {{0,0,1,0},{0,1,1,0},{0,1,2,0},{0,1,3,0},{0,1,4,0},{0,1,5,0},{2,1,6,0},{2,1,7,3},{0,1,8,0},{2,1,9,1},{1,1,10,0}}, {{0,0,2,0},{0,1,2,0},{0,2,2,0},{0,2,3,0},{2,2,4,0},{0,2,5,0},{0,2,6,0},{2,2,7,2},{2,2,8,1},{0,2,9,0},{1,2,10,0}}, {{0,0,3,0},{0,1,3,0},{0,2,3,0},{0,3,3,0},{2,3,4,3},{2,3,5,1},{2,3,6,2},{0,3,7,0},{0,3,8,0},{0,3,9,0},{1,3,10,0}}, {{0,0,4,0},{0,1,4,0},{2,2,4,0},{2,3,4,3},{0,4,4,0},{2,4,5,0},{2,4,6,0},{2,4,7,3},{2,4,8,3},{1,4,9,0},{1,4,10,0}}, {{2,0,5,0},{0,1,5,0},{0,2,5,0},{2,3,5,1},{2,4,5,0},{0,5,5,0},{2,5,6,0},{1,5,7,0},{2,5,8,1},{2,5,9,1},{1,5,10,0}}, {{0,0,6,0},{2,1,6,0},{0,2,6,0},{2,3,6,2},{2,4,6,0},{2,5,6,0},{0,6,6,0},{2,6,7,2},{1,6,8,0},{2,6,9,2},{1,6,10,0}}, {{0,0,7,0},{2,1,7,3},{2,2,7,2},{0,3,7,0},{2,4,7,3},{1,5,7,0},{2,6,7,2},{0,7,7,0},{2,7,8,3},{2,7,9,2},{1,7,10,0}}, {{2,0,8,3},{0,1,8,0},{2,2,8,1},{0,3,8,0},{2,4,8,3},{2,5,8,1},{1,6,8,0},{2,7,8,3},{0,8,8,0},{2,8,9,1},{1,8,10,0}}, {{2,0,9,2},{2,1,9,1},{0,2,9,0},{0,3,9,0},{1,4,9,0},{2,5,9,1},{2,6,9,2},{2,7,9,2},{2,8,9,1},{0,9,9,0},{1,9,10,0}}, {{1,0,10,0},{1,1,10,0},{1,2,10,0},{1,3,10,0},{1,4,10,0},{1,5,10,0},{1,6,10,0},{1,7,10,0},{1,8,10,0},{1,9,10,0},{0,10,10,0}} }; static SHORT CornerOfSonSide[MAX_SIDES_OF_ELEM][3] = {{0,1,2},{1,2,3},{0,2,3},{0,1,3}}; static SHORT IsOnSide[MAX_SIDES_OF_ELEM][MAXCORNERS] = {{1,1,1,0,1,1,1,0,0,0,0}, {0,1,1,1,0,1,0,0,1,1,0}, {1,0,1,1,0,0,1,1,0,1,0}, {1,1,0,1,1,0,0,1,1,0,0}}; static int nRulesTh; /* total number of theoretical refinement rules */ static int nRules; /* total number of generated refinement rules */ static int FirstRuleWithEdgePattern; /* Rule no. of first of several SidePatterns */ static REFRULE *RuleList; /* list is allocated in main program */ static SHORT *PatternToRefrule; /* vector is allocated in main program */ static bool Output; /* if true output of generated rules */ /* prototype for new rules without any data */ static REFRULE EmptyRule = {0,{0,0,0,0,0,0},0,{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}, {{{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}}}; /****************************************************************************/ /* */ /* functions */ /* */ /****************************************************************************/ static SHORT SideWithCorners (SHORT C0,SHORT C1,SHORT C2) { SHORT Side; for (Side=0; Sidensons; i++) for (theSon = theRule->sons+i, j=0; jcorners[j] = ReplaceBy[theSon->corners[j]]; return (0); } static int PrintRule (REFRULE *theRule, SHORT nEdges) { SHORT i,j; printf("nsons %d; pattern %d%d%d%d%d%d; ",(int)theRule->nsons, (int)theRule->pattern[5], (int)theRule->pattern[4], (int)theRule->pattern[3], (int)theRule->pattern[2], (int)theRule->pattern[1], (int)theRule->pattern[0]); printf("pat %#04x; (nedges %d)\n",(int)theRule->pat,(int)nEdges); printf("edges: "); for (i=0; i<8; i++) printf("{%d,%d,%d,%d}",(int)theRule->edges[i].type,(int)theRule->edges[i].from, (int)theRule->edges[i].to,(int)theRule->edges[i].side); printf("\n\t"); for (; iedges[i].type,(int)theRule->edges[i].from, (int)theRule->edges[i].to,(int)theRule->edges[i].side); printf("\nsons: "); for (i=0; i<6; i++) printf("{{%d,%d,%d,%d}{%d,%d,%d,%d}}",(int)theRule->sons[i].corners[0],(int)theRule->sons[i].corners[1], (int)theRule->sons[i].corners[2],(int)theRule->sons[i].corners[3], (int)theRule->sons[i].nb[0],(int)theRule->sons[i].nb[1], (int)theRule->sons[i].nb[2],(int)theRule->sons[i].nb[3]); printf("\n\t"); for (; isons[i].corners[0],(int)theRule->sons[i].corners[1], (int)theRule->sons[i].corners[2],(int)theRule->sons[i].corners[3], (int)theRule->sons[i].nb[0],(int)theRule->sons[i].nb[1], (int)theRule->sons[i].nb[2],(int)theRule->sons[i].nb[3]); for (i=1; insons; i++) { printf("\npath to %d: son0",i); for (j=0; jsons[i].path); j++) printf("-->nb%d",(int) NEXTSIDE(theRule->sons[i].path,j)); printf(" (%d steps)",(int) PATHDEPTH(theRule->sons[i].path)); } printf("\nsonandnode:"); for (i=0; i(%d,%d)",(int)(i+CORNERS_OF_ELEM),(int)theRule->sonandnode[i][0],(int)theRule->sonandnode[i][1]); printf("\n"); return (0); } static int CopySonsIntoRule (REFRULE *theRule,SONDATA sons[SONS]) { SHORT i; for (i=0; isons[i] = sons[i]; return (0); } static int CompareEdgesForSides (const void *Edge1, const void *Edge2) { EDGEDATA *theEdge1,*theEdge2; theEdge1 = (EDGEDATA *) Edge1; theEdge2 = (EDGEDATA *) Edge2; /* leave type==0 at end of the list */ if ((theEdge1->type)==0) return (1); if ((theEdge2->type)==0) return (-1); if ((theEdge1->side)==(theEdge2->side)) return (0); else if ((theEdge1->side)>(theEdge2->side)) return (1); else return (-1); } static int CompareEdges (const void *theEdge1, const void *theEdge2) { if (((EDGEDATA *)theEdge1)->from==((EDGEDATA *)theEdge2)->from) { if (((EDGEDATA *)theEdge1)->to>((EDGEDATA *)theEdge2)->to) return (1); else if (((EDGEDATA *)theEdge1)->to<((EDGEDATA *)theEdge2)->to) return (-1); else return (0); } else if (((EDGEDATA *)theEdge1)->from>((EDGEDATA *)theEdge2)->from) return (1); else return (-1); } static int CompareCorners (const void *theCorner1, const void *theCorner2) { SHORT C1,C2; C1 = * ((SHORT *) theCorner1); C2 = * ((SHORT *) theCorner2); assert(C1!=C2); if (C1>C2) return (1); else return (-1); } static int NewEdgesAreEqual (EDGEDATA *NewEdges0, EDGEDATA *NewEdges1) { SHORT i; for (i=0; isons[myID].nb[i])sons[nbID].path); /* copy myPath to nbPath */ *nbPath = theRule->sons[myID].path; /* complete nbPath */ nbPATHDEPTH = PATHDEPTH(*nbPath); SETNEXTSIDE(*nbPath,nbPATHDEPTH,i); SETPATHDEPTH(*nbPath,++nbPATHDEPTH); Status[nbID] = TOUCHED; } /* recursive call for TOUCHED sons */ for (nbID=1; nbIDnsons; nbID++) if (Status[nbID]==TOUCHED) { Status[nbID] = DONE; FindPathForNeighbours (theRule,nbID,Status); } return (0); } /****************************************************************************/ /* */ /* AddRuleIfNew */ /* called by most of the main functions */ /* */ /* the additional data fields of the refrule are filled and the */ /* rule is stored if not already there */ /* */ /****************************************************************************/ static int AddRuleIfNew (REFRULE *theRule) { EDGEDATA theEdgeData,*InnerEdge[2]; SONDATA *SONi,*SONj,*theSon; SHORT i,j,nEdges,theEdge,FatherSide,newcorner,corner,son,edge,found,SidePattern; SHORT SIDEi,SIDEj,side,SideBit,Status[SONS]; assert(nRules 3) and fill edges field */ nEdges = 0; for (son=0; sonnsons; son++) for (i=0; isons[son].corners[i]] [theRule->sons[son].corners[j]]).type) { /* (From,To) is a new edge: already stored? */ for (theEdge=0; theEdgeedges[theEdge].from==theEdgeData.from)&&(theRule->edges[theEdge].to==theEdgeData.to)) break; if (theEdge>=nEdges) theRule->edges[nEdges++] = theEdgeData; } /* sort edges for corner IDs (necessary for fast comparison of SidePatterns) */ qsort((void *)theRule->edges,nEdges,sizeof(EDGEDATA),CompareEdges); /* if this SidePattern is not already in RuleList: store it */ for (i=FirstRuleWithEdgePattern; iedges,RuleList[i].edges)) break; if (insons; i++) qsort((void *)theRule->sons[i].corners,4,sizeof(SHORT),CompareCorners); /* fill entries of nb field in the SONDATA */ for (i=0; insons; i++) for (SONi=theRule->sons+i, SIDEi=0; SIDEinb[SIDEi] == NOTDONE) { /* outer face? */ if ((FatherSide=SideWithCorners(SONi->corners[CornerOfSonSide[SIDEi][0]], SONi->corners[CornerOfSonSide[SIDEi][1]], SONi->corners[CornerOfSonSide[SIDEi][2]]))!=NOFATHERSIDE) { SONi->nb[SIDEi] = FatherSide; continue; } for (j=i+1; jnsons; j++) for (SONj=theRule->sons+j, SIDEj=0; SIDEjcorners[CornerOfSonSide[SIDEi][0]]==SONj->corners[CornerOfSonSide[SIDEj][0]]) && (SONi->corners[CornerOfSonSide[SIDEi][1]]==SONj->corners[CornerOfSonSide[SIDEj][1]]) && (SONi->corners[CornerOfSonSide[SIDEi][2]]==SONj->corners[CornerOfSonSide[SIDEj][2]])) { /* neighbour found */ SONi->nb[SIDEi] = j; SONj->nb[SIDEj] = i; j=SONS; break; } } /* clear the remaining NOTDONEs */ for (i=theRule->nsons; isons+i, SIDEi=0; SIDEinb[SIDEi] = 0; /* fill the sonandnode field */ for (newcorner=0; newcornersonandnode[newcorner][0] = NOTUSED; for (newcorner=CORNERS_OF_ELEM; newcorner<(NEWCORNERS+CORNERS_OF_ELEM); newcorner++) for (son=0; sonsons+son, corner=0; cornercorners[corner]==newcorner) { theRule->sonandnode[newcorner-CORNERS_OF_ELEM][0] = son; theRule->sonandnode[newcorner-CORNERS_OF_ELEM][1] = corner; son = SONS; break; } /* make a consistence check: newcorners in sondata indicate the refined edges */ for (newcorner=0; newcornersonandnode[newcorner][0]==NOTUSED) { assert(theRule->pattern[newcorner]==0); assert((theRule->pat & (1<pattern[newcorner]==1); assert((theRule->pat & (1<0); } /* find the SidePattern of theRule */ SidePattern = 0; for (side=0; sidepat & CondensedEdgeOfSide[side]][0] >= 0) { /* here we have a side with a trisection edge */ for (found=0, edge=0; edgeedges[edge].type==2) && (theRule->edges[edge].side==side)) { /* we have an inner edge of side (which has a trisection node) */ InnerEdge[found++] = theRule->edges+edge; } assert(found==2); if (InnerEdge[0]->from==InnerEdge[1]->from) theEdge = InnerEdge[0]->from - CORNERS_OF_ELEM; else if (InnerEdge[0]->from==InnerEdge[1]->to) theEdge = InnerEdge[0]->from - CORNERS_OF_ELEM; else if (InnerEdge[0]->to==InnerEdge[1]->from) theEdge = InnerEdge[0]->to - CORNERS_OF_ELEM; else if (InnerEdge[0]->to==InnerEdge[1]->to) theEdge = InnerEdge[0]->to - CORNERS_OF_ELEM; else assert(0); if (TriSectionEdge[theRule->pat & CondensedEdgeOfSide[side]][0] == theEdge) SideBit = 0; else if (TriSectionEdge[theRule->pat & CondensedEdgeOfSide[side]][1] == theEdge) SideBit = 1; else assert(0); if (SideBit) SidePattern |= (1<nsons; i++) Status[i] = NOTDONE; FindPathForNeighbours (theRule,0,Status); /* put the new rule into the RuleList */ PatternToRefrule[theRule->pat | (SidePattern<=0; found--) BisectSon(SonID[found],CornerID0[found],CornerID1[found],theEdge,theNewRule.sons,theNewRule.nsons++); /* recursively refine the remaining edges: */ EdgePattern[theEdge] = 0; BisectEdge(EdgePattern,theNewRule); EdgePattern[theEdge] = 1; } if (nEdges==0) AddRuleIfNew(&theRule); return (0); } /****************************************************************************/ /****************************************************************************/ /* */ /* main functions: */ /* MakeRule... */ /* */ /* the Rules refining n edges are generated */ /* */ /****************************************************************************/ /****************************************************************************/ /****************************************************************************/ /* */ /* MakeRuleByBisection */ /* generates rules by recursive bisection of the father */ /* */ /****************************************************************************/ static int MakeRuleByBisection (SHORT pattern) { REFRULE NewRule; SONDATA father = {{0,1,2,3},{NOTDONE,NOTDONE,NOTDONE,NOTDONE}}; SHORT EdgePattern[EDGES],RefEdgesPerSide[MAX_SIDES_OF_ELEM]; SHORT i,nTrapezoid; NewRule = EmptyRule; NewRule.nsons = 1; NewRule.sons[0] = father; NewRule.pat = pattern; /* make extended pattern */ for (i=0; i0); /* find the number of trapezoids for check purposes */ for (i=0; i %d SidePatterns\n",(int)nTrapezoid,(int)(1<0); if (AddRuleIfNew(&theRule)==1) printf("MakeRule3: already there\n"); } return (1); } else { printf(" rule 3: 3 on one side: 1 Rule\n"); nRulesTh += 1; theRule = EmptyRule; theRule.nsons = 4; CopySonsIntoRule(&theRule,SidePrototype); if (Rot!=IDENTITY) RotateCorners(&theRule,Rot); theRule.pat = pattern; /* fill extended pattern */ for (j=0; j0); if (AddRuleIfNew(&theRule)==1) printf("MakeRule3: already there\n"); return (0); } } #define RULE4CORNER 1 #define RULE4CORNER_PROTO 4 #define RULE4PLANE 2 #define RULE4PLANE_PROTO 2 static int MakeRule4 (SHORT pattern) { SONDATA CornerPrototype[RULE4CORNER_PROTO][SONS] = { {{{0,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{5,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,4,7,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,4,1,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,3,7,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,3,2,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}}, {{{0,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{5,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,4,7,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,4,1,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,7,3,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,7,6,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}}, {{{0,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{5,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,7,4,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,7,3,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,7,3,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,7,6,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}}, {{{0,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{5,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,7,4,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,7,3,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,3,7,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,3,2,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}} }; SONDATA PlanePrototype[RULE4PLANE_PROTO][SONS] = { {{{1,8,5,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,8,7,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,6,5,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,6,7,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,1,5,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,1,7,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,5,6,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,5,8,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,7,6,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,7,8,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,2,8,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,2,6,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}}, {{{1,5,6,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,5,8,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,7,6,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,7,8,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,1,6,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,1,8,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,6,5,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,6,7,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,8,5,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{3,8,7,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,3,5,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,3,7,10},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}} }; SHORT *Rot0,*Rot1; REFRULE theRule; SHORT i,j,theRule4; if ((pattern&0x0D)==0x0D) switch (pattern&~0x0D) /* corner 0 */ { case (1<<1) : Rot0 = IDENTITY; Rot1 = IDENTITY; theRule4 = RULE4CORNER; break; case (1<<4) : Rot0 = IDENTITY; Rot1 = Ax0Left; theRule4 = RULE4CORNER; break; case (1<<5) : Rot0 = IDENTITY; Rot1 = Ax0Right; theRule4 = RULE4CORNER; break; } else if ((pattern&0x13)==0x13) switch (pattern&~0x13) /* corner 1 */ { case (1<<2) : Rot0 = Ax3Left; Rot1 = IDENTITY; theRule4 = RULE4CORNER; break; case (1<<3) : Rot0 = Ax3Left; Rot1 = Ax1Right; theRule4 = RULE4CORNER; break; case (1<<5) : Rot0 = Ax3Left; Rot1 = Ax1Left; theRule4 = RULE4CORNER; break; } else if ((pattern&0x26)==0x26) switch (pattern&~0x26) /* corner 2 */ { case (1<<0) : Rot0 = Ax3Right; Rot1 = IDENTITY; theRule4 = RULE4CORNER; break; case (1<<3) : Rot0 = Ax3Right; Rot1 = Ax2Left; theRule4 = RULE4CORNER; break; case (1<<4) : Rot0 = Ax3Right; Rot1 = Ax2Right; theRule4 = RULE4CORNER; break; } else if ((pattern&0x38)==0x38) switch (pattern&~0x38) /* corner 3 */ { case (1<<0) : Rot0 = Ax1Right; Rot1 = IDENTITY; theRule4 = RULE4CORNER; break; case (1<<1) : Rot0 = Ax1Right; Rot1 = Ax3Left; theRule4 = RULE4CORNER; break; case (1<<2) : Rot0 = Ax1Right; Rot1 = Ax3Right; theRule4 = RULE4CORNER; break; } else if (pattern==0x1E) /* plane 5,6,7,8 (011110) */ { Rot0 = IDENTITY; theRule4 = RULE4PLANE; } else if (pattern==0x35) /* plane 4,6,8,9 (110101) */ { Rot0 = Ax3Left; theRule4 = RULE4PLANE; } else if (pattern==0x2B) /* plane 4,5,7,9 (101011) */ { Rot0 = Ax3Right; theRule4 = RULE4PLANE; } else assert(0); /* should not happen */ /* rotate the Prototype son patterns into the pattern position and copy them into the rule */ if (theRule4==RULE4CORNER) { printf(" rule 4: 3 next to one node: 4 Rules\n"); nRulesTh += 4; for (i=0; i0); if (AddRuleIfNew(&theRule)==1) printf("MakeRule4: already there\n"); } return (0); } else { printf(" rule 4: 4 on a plane: 2 Rules\n"); /* nRulesTh += 2; will be counted by MakeRuleByBisection */ for (i=0; i0); if (AddRuleIfNew(&theRule)==1) printf("MakeRule4: already there\n"); } return (1); } } #define RULE5_PROTO 4 static int MakeRule5 (SHORT pattern) { SONDATA CornerPrototype[RULE5_PROTO][SONS] = { {{{3,7,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,9,6,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,7,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{5,6,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,6,7,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,6,5,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,1,5,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}}, {{{3,7,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,9,6,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,7,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{5,6,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,6,8,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,6,8,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,1,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}}, {{{3,7,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,9,6,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,7,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{5,6,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,6,8,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,1,6,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,7,6,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}}, {{{3,7,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{2,9,6,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{9,7,5,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{9,7,5,6},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,7,6,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,1,7,5},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{1,7,5,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}} }; SHORT *Rot0,*Rot1; REFRULE theRule; SHORT i,j; printf(" rule 5: 4 Rules\n"); nRulesTh += 4; switch (~pattern&PATTERNFILTER) { case (1<<0) : Rot0 = IDENTITY; Rot1 = IDENTITY; break; /* all but edge 0 (111110) */ case (1<<1) : Rot0 = Ax3Left; Rot1 = IDENTITY; break; /* all but edge 1 (111101) */ case (1<<2) : Rot0 = Ax3Right; Rot1 = IDENTITY; break; /* all but edge 2 (111011) */ case (1<<3) : Rot0 = Ax2Left; Rot1 = IDENTITY; break; /* all but edge 3 (110111) */ case (1<<4) : Rot0 = Ax2Right; Rot1 = IDENTITY; break; /* all but edge 4 (101111) */ case (1<<5) : Rot0 = Ax2Left; Rot1 = Ax1Right; break; /* all but edge 5 (011111) */ default : assert (0); /* should not happen */ } /* rotate the Prototype son patterns into the pattern position and copy them into the rule */ for (i=0; i0); if (AddRuleIfNew(&theRule)==1) printf("MakeRule5: already there\n"); } return (0); } static int MakeRule6 (SHORT pattern) { SONDATA FullRefPrototype[SONS] = {{{0,4,6,7},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{4,1,5,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,5,2,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{7,8,9,3},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{4,6,7,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{4,6,5,8},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,5,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{6,7,8,9},{NOTDONE,NOTDONE,NOTDONE,NOTDONE},0}, {{0,0,0,0},{0,0,0,0},0}, {{0,0,0,0},{0,0,0,0},0}, {{0,0,0,0},{0,0,0,0},0}, {{0,0,0,0},{0,0,0,0},0}}; REFRULE theRule; SHORT j; printf(" rule 6: 3 Rules\n"); nRulesTh += 3; /* inner edge 6-8 */ theRule = EmptyRule; theRule.nsons = 8; theRule.pat = pattern; for (j=0; j0); CopySonsIntoRule(&theRule,FullRefPrototype); AddRuleIfNew(&theRule); /* inner edge 4-9 */ theRule = EmptyRule; theRule.nsons = 8; theRule.pat = pattern; for (j=0; j0); CopySonsIntoRule(&theRule,FullRefPrototype); RotateCorners(&theRule,Ax1Left); FirstRuleWithEdgePattern = nRules; AddRuleIfNew(&theRule); /* inner edge 5-7 */ theRule = EmptyRule; theRule.nsons = 8; theRule.pat = pattern; for (j=0; j0); CopySonsIntoRule(&theRule,FullRefPrototype); RotateCorners(&theRule,Ax1Right); FirstRuleWithEdgePattern = nRules; AddRuleIfNew(&theRule); /* reset PatternToRefrule[111111] to the first of the FullRefRules */ PatternToRefrule[pattern] = nRules-3; return (0); } int main ([[maybe_unused]] int argc, [[maybe_unused]] char **argv) { FILE *stream; SHORT pattern,nRefEdge,nRE,i; int MINnRefEdge,MAXnRefEdge,j,err,SaveList; MINnRefEdge = 0; MAXnRefEdge = EDGES; Output = false; SaveList = 1; #ifdef TEST_GR if (argc<3) { printf("usage: GenerateRules [-o] [-s]\n"); return (1); } /* scan args for options */ if (sscanf(argv[1],"%d",&MINnRefEdge)!=1) return (1); if (sscanf(argv[2],"%d",&MAXnRefEdge)!=1) return (1); for (i=3; iEDGES)) { printf("ERROR: min # of refined edges out of range\n"); return (1); } if ((MAXnRefEdge<0) || (MAXnRefEdge>EDGES)) { printf("ERROR: min # of refined edges out of range\n"); return (1); } if (MAXnRefEdge max\n"); return (1); } /* get storage for RuleList */ RuleList = (REFRULE *) malloc(NRULES*sizeof(REFRULE)); if (RuleList==NULL) { printf("ERROR: no storage for RuleList\n"); return (1); } /* get storage for PatternToRefrule */ PatternToRefrule = (SHORT *) malloc((1<<(EDGES+MAX_SIDES_OF_ELEM))*sizeof(SHORT)); if (PatternToRefrule==NULL) { printf("ERROR: no storage for PatternToRefrule\n"); return (1); } for (j=0; j<(1<<(EDGES+MAX_SIDES_OF_ELEM)); j++) PatternToRefrule[j] = NOTUSED; nRules = nRulesTh = 0; for (nRefEdge=MINnRefEdge; nRefEdge<=MAXnRefEdge; nRefEdge++) { printf("\n### %d refined edges ###\n",(int)nRefEdge); for (pattern=0; pattern < (1<0; /* take only pattern with nRE==nRefEdge */ if (nRE!=nRefEdge) continue; /* set begin of possibly identical SidePatterns for AddRuleIfNew () */ FirstRuleWithEdgePattern = nRules; for (i=0; i0)); switch (nRefEdge) { case 0 : MakeRule0(pattern); break; case 1 : MakeRuleByBisection(pattern); break; case 2 : MakeRuleByBisection(pattern); break; case 3 : if (MakeRule3(pattern)) MakeRuleByBisection(pattern); break; case 4 : if (MakeRule4(pattern)) MakeRuleByBisection(pattern); break; case 5 : MakeRule5(pattern); break; case 6 : MakeRule6(pattern); break; } } } /* sort edges for sides (necessary for ugrefine) */ for (i=2; i RefRules */ if (err!=1) goto exit; fclose(stream); printf("\nRuleList saved to 'RefRules.data'\n"); } printf("\n######## DONE #########\n"); return (0); exit: fclose(stream); return (1); } #endif