package BoxTools; public class Util{ public final static int SPACE_DIM=3; public final static int SORT_DIM=1; //public final static int SORT_DIM=SPACE_DIM;//for using LineTools public final static int HIGH_SIDE=1; public final static int LOW_SIDE=0; public final static RectDomain NULL_BOX=[Point.all(1):Point.all(0)]; public final static int NUMVCYCLE=1; public final static int NUMBVCYCLE=2; public final static int NUMAMRVCYCLE=20; //20 public static double countCopy=0; public static double countLocalCopy=0; public static double countTiCopy=0; public static double countExchange=0; public static double countSize=0; public static double countNum=0; public static double countRestrict=0; public static double countPointer=0; private Util(){} public final static inline void addCountCopy(double a_db){ countCopy+=a_db; } public final static inline void printErrMsg(String single a_string){ if (Ti.thisProc()==0) System.err.println(a_string); } public final static inline void printMsg(String single a_string){ if (Ti.thisProc()==0) System.out.println(a_string); } public final inline static boolean checkDir(int a_dir, int a_side){ if (a_dir<1 || a_dir>SPACE_DIM || a_side <0 || a_side>1) return false; else return true; } public final inline static boolean isBlackPoint(Point point){ int result=0; for (int i=1;i<=SPACE_DIM;i++) result+=point[i]; if (result%2==0) return true; else return false; } public final inline static int Black(Point point){ int result=0; for (int i=1;i<=SPACE_DIM;i++) result+=point[i]; return (result%2); } /* public final static RectDomain [] BlackBoxes(RectDomain a_box){ RectDomain [] result; switch (SPACE_DIM){ case 3: result=new RectDomain [4]; Point [] lwb=new Point [4]; lwb[0]=a_box.min();lwb[1]=lwb[0]+[0,1,1];lwb[2]=lwb[0]+[1,0,1];lwb[3]=lwb[0]+[1,1,0]; Point max=a_box.max();Point stride=a_box.stride()*2; for (int i=0;i<4;i++){ result[i]=[lwb[i]:(lwb[i]+(max-lwb[i])/2*2):stride]; } } return result; } public final static RectDomain [] RedBoxes(RectDomain a_box){ RectDomain [] result; switch (SPACE_DIM){ case 3: result=new RectDomain [4]; Point [] lwb=new Point [4]; Point min=a_box.min(); lwb[0]=min+[1,1,1];lwb[1]=min+[1,0,0];min=min+[0,1,0];lwb[3]=min+[0,0,1]; Point max=a_box.max();Point stride=a_box.stride()*2; for (int i=0;i<4;i++){ result[i]=[lwb[i]:(lwb[i]+(max-lwb[i])/2*2):stride]; } } return result; } */ public final inline static int Red(Point point){ int result=1; for (int i=1;i<=SPACE_DIM;i++) result+=point[i]; return (result%2); } public final inline static RectDomain coarsen(RectDomain a_rectDomain, int a_factor){ Point lwb,upb,stride; lwb=a_rectDomain.min();upb=a_rectDomain.max();stride=a_rectDomain.stride()*a_factor; lwb=lwb/stride; upb=upb/stride; return [lwb:upb:a_rectDomain.stride()]; } public final inline static RectDomain refine(RectDomain a_rectDomain, int a_factor){ Point lwb,upb,stride; final Point STRIDE; lwb=a_rectDomain.min();upb=a_rectDomain.max(); STRIDE=a_rectDomain.stride();stride=STRIDE*a_factor; lwb=lwb*stride; upb=(upb+STRIDE)*stride-STRIDE; return [lwb:upb:STRIDE]; } public final inline static boolean single isJointed(RectDomain a_box1, RectDomain a_box2){ boolean single jointed=true; RectDomain single box1=(RectDomain single) a_box1; RectDomain single box2=(RectDomain single) a_box2; Point single lwb1,upb1,lwb2,upb2; lwb1=box1.min();upb1=box1.max(); lwb2=box2.min();upb2=box2.max(); int single x1,x2; for (int single d=1;d a_box){ Point p=(a_box.max()-a_box.min()); int i=0; for (int d=1;d=SPACE_DIM-1) return true; else return false; } /** Find if a_box1 is a neighbor of a_box2. Corners and edges are ignored*/ public final inline static boolean single isMyNeighbor(RectDomain a_box1, RectDomain a_box2){ boolean single result=true; RectDomain single box1=(RectDomain single) a_box1; RectDomain single box2=(RectDomain single) a_box2; Point single lwb1,upb1,lwb2,upb2; lwb1=box1.min();upb1=box1.max(); lwb2=box2.min();upb2=box2.max(); int single x1,x2,i,d; search: for (d=1;d1) for (i=1;iO(n^2) sorting algorithm. */ public final static boolean single sort(RectDomain single [] single a_Boxes, int single [] single a_procIDs, int single a_dim){ if (a_Boxes.length != a_procIDs.length){ Util.printErrMsg("BoxLayout::sort( , ): the sizes of the two input arrarys must be equal!"); return false; } else{ RectDomain single tempBox; int single tempProcID; int single tempIndex; int single n=a_Boxes.length; int single i,j; for (i=0; i single [] single a_Boxes, int single a_dim){ RectDomain single tempBox; int single tempIndex; int single n=a_Boxes.length; int single i,j; for (i=0; i