package BoxTools; // Note that if ghostsize=0, then no exchange. /** A BoxLayoutData object contains a set of distributed box-oriented objects. For most * of cases, it can be considered as a wrapper of the Ti array: * T [1d] local single [1d] [SPACE_DIM d] local, * or * T [1d] local [1d] local [SPACE_DIM d] local. * In this implementation, a wrapper such as BoxedArray is used to further wrap * the box-oriented Ti array, for example: * double [SPACE_DIM d] local. * Hereafter, T represents a general box-oriented data type. * Here, TA is a two dimensional array of some box-oriented data type, where * TA[procID][localBoxID] gives the localBoxID+1 th box-oriented object * on processor/processes procID<\code>. A BoxLayoutData object is defined on a * BoxLayout object along with the sizes of ghostcells in each direction. A * BoxLayoutData object can be null constructed first and defined later. Since Titanium * currently does not support inheritance from a template class, it is impossible to implement the * hierarchy of * @see LayoutData, * @see BoxLayoutData, and * @see LevelData as defined in * @see Chombo. So currently, we have to * combine these three classes into one class. Note that the methods exchange and * copy can be used only when the underlying boxes are disjointed. *

Usage: a BoxLayoutData object must be declared local. * @see BoxLayout,BoxedArray, DataIterator, LayoutIterator, LayoutIndex, DataIndex * @see Chombo Specification * @version 2.0 * Modified on May 24, 2004. Ghost regions for exchange are cached. * on Jun 21, 2004. the restriction of global pointers are cached (See BoxedArray). * on Jul 09, 2004. change of syntax of foreach, see foreachLoopTest.ti. * on Aug 09, 2004. add m_layoutItr. * on Aug 26, 2004. the operator <<=constant covers ghost cells so as to save exchange. * @author Tong Wen, LBNL * @since 1.0 */ template public class BoxLayoutData{ private final static int SPACE_DIM=Util.SPACE_DIM; private final static int SORT_DIM=Util.SORT_DIM; private BoxLayout local single m_layout; private int single m_numOfProcs=Ti.numProcs(); private int m_procID=Ti.thisProc(); /**The box oriented data of type T in TA<\code> can reside on any processor/process. */ protected T [1d] local [1d] local TA; /**The array stores local Ts. Each BoxLayoutData is only responsible * for constructing local Ts. Then the pointers to local data are exchanged. */ //private T local [1d] local m_data; private boolean single m_constructed=false; private int m_numOfBoxes; private boolean single m_disjointed=false; private boolean single m_sorted=false; private int single m_ghostSize; private LayoutIterator local m_layoutItr; protected int [] local [] local m_neighbors; //protected RectDomain [] local [] local m_ExchangeGhostRegion;// Jun 21, 2004 Exchange Version 2. boolean m_regionUsed=false; PrivateRegion local m_region; Timer TM=new Timer(); Timer TMCopy=new Timer(); Timer TMCopyL=new Timer(); public inline BoxLayoutData(){ TA=new T [0:m_numOfProcs-1] [1d] local; } /**Jun 21, 2004 Exchange Version 2. private final local void fillExchangeGhostRegion(){ if (m_ghostSize>1) m_neighbors=m_layout.findNeighbors(m_ghostSize); else{ if (!m_layout.m_neighborsFound) m_layout.findNeighbors(); m_neighbors=m_layout.m_neighbors; } m_ExchangeGhostRegion=new RectDomain [m_numOfBoxes] local [] local; int i,j,size,gIdx; RectDomain box; for (i=0;i [size] local; box=TA[m_procID][i].domain(); for (j=0;j1) m_neighbors=m_layout.findNeighbors(m_ghostSize); else{ if (!m_layout.m_neighborsFound) m_layout.findNeighbors(); m_neighbors=m_layout.m_neighbors; } int i,j,size,gIdxA, gIdxB, lIdxB, procIDB; RectDomain boxA, boxB; T local boxedDataA; boolean [] local procsInUse=new boolean [m_numOfProcs]; int l,m, procs; for (i=0;iprocs) procs=m; } //Util.printMsg("Exchange: max num of procs for exchange "+Reduce.max(procs)); return; } public final local single void define( BoxLayout local single a_layout, int single a_ghostSize){ if (m_constructed) { Util.printErrMsg("BoxLayoutData::define( ): this BoxLayoutData has already been defined!"); return; } else{ m_ghostSize=(int single)Math.abs(a_ghostSize); int i; m_layout=a_layout; m_numOfBoxes=m_layout.numBoxesAt(m_procID); for (i=0;i box; Point stride; if (!lit.isEnded()) stride=lit.access().stride(); lit.reset(); //Timer TM=new Timer();TM.start(); if (m_ghostSize==0) while (!lit.isEnded()){ box=lit.access(); if (m_regionUsed) TA[m_procID][i] = new T(box,m_region); else TA[m_procID][i] = new T(box); lit.advance();i++; } else{ while (!lit.isEnded()){ box=lit.access(); if (m_regionUsed) TA[m_procID][i] = new T(box.accrete(m_ghostSize,stride), m_region); else TA[m_procID][i] = new T(box.accrete(m_ghostSize,stride)); lit.advance();i++; } // fillExchangeGhostRegion();// June 21, 2004 Exchange Version 2. } //Ti.barrier(); redundant? //TM.stop(); System.out.println("Time to construct local data with "+ghostSize+" ghost size: "+TM.millis()); //TA.exchange(m_data); int single j,k; for (k=0;k0) { cacheExchangeInfo();// Exchange Version 3 } m_constructed=true; m_disjointed=a_layout.isDisjointed(); m_sorted=a_layout.isSorted(); return; } } public BoxLayoutData(BoxLayout local single a_layout,int single a_ghostSize, boolean single a_useRegion){ this(); m_regionUsed=a_useRegion; if (m_regionUsed) m_region=new PrivateRegion(); //TA=new(m_region) T [0:m_numOfProcs-1] [1d] local; define(a_layout,a_ghostSize); } public BoxLayoutData(BoxLayout local single a_layout,int single a_ghostSize){ this(); define(a_layout,a_ghostSize); } public final inline local BoxLayout local single boxLayout(){ if (m_constructed) return m_layout; else return null; } public final inline local LayoutIterator local layoutIterator(){ m_layoutItr.reset();m_layoutItr.Reset();return m_layoutItr; } public final inline local boolean single isDisjointed(){return m_disjointed;} public final inline local boolean single isConstructed(){return m_constructed;} public final inline local RectDomain getBox(DataIndex local a_DI){ if (m_constructed) return m_layout.getBox(a_DI); else return Util.NULL_BOX; } public final inline local T local op[](DataIndex local a_DI){ if (m_constructed) if ((m_procID==a_DI.m_procID) && (m_layout.getRoot()==a_DI.m_root)) return (T local)TA[m_procID][a_DI.m_dataIndex]; else{ Util.printErrMsg("BoxLayoutData::op[]: invalid DataIndex!"); return null; } else return null; } /**operations on BoxLayoutData are local and only applied on valid data (no data on ghost region). * Therefore, we do not put "single" here. For each operation defined here, it is required that there is a * corresponding one of class T. */ public final local template BoxLayoutData local single op+=(template BoxLayoutData local single a_BLD){ if (m_constructed && a_BLD.isConstructed()) if (m_layout==a_BLD.boxLayout()){ T local BoxedData1, BoxedData2; for (int i=0;i local single op-=(template BoxLayoutData local single a_BLD){ if (m_constructed && a_BLD.isConstructed()) if (m_layout==a_BLD.boxLayout()){ T local BoxedData1, BoxedData2; for (int i=0;i local single op*=(double single a_db){ if (m_constructed){ T local BoxedData; for (int i=0;i local single op<<=(double single a_db){ if (m_constructed){ T local BoxedData; for (int i=0;i local single op<<=(template BoxLayoutData local single a_BLD){ if (m_constructed && a_BLD.isConstructed()) if (m_layout==a_BLD.boxLayout()){ T local BoxedData1, BoxedData2; for (int i=0;i local single a_BLD1, template BoxLayoutData local single a_BLD2){ if (m_constructed && a_BLD1.isConstructed() && a_BLD2.isConstructed()) if ((m_layout==a_BLD1.boxLayout()) && (m_layout==a_BLD2.boxLayout())){ T local BoxedData1, BoxedData2, BoxedData3; for (int i=0;i local single a_BLD1, template BoxLayoutData local single a_BLD2){ if (m_constructed && a_BLD1.isConstructed() && a_BLD2.isConstructed()) if ((m_layout==a_BLD1.boxLayout()) && (m_layout==a_BLD2.boxLayout())){ T local BoxedData1, BoxedData2, BoxedData3; for (int i=0;iLevelData*/ /* public final local single void exchange(){ if (m_constructed) if (m_disjointed){ LayoutIterator local LIT=new LayoutIterator(m_layout); LayoutIterator local LIT=m_layoutItr;//Aug 09, 2004 RectDomain boxA,boxB; T local boxedDataA; T boxedDataB; DataIndex local DI; LIT.reset(); for (int i=0;i boxA,boxB; RectDomain [] local neighbors; T local boxedDataA; T boxedDataB; DataIndex local DI; DataIndex local [] local neighborIdxes; int i,j; LIT.reset(); for (i=0;i [] local neighbors; T local boxedDataA; T boxedDataB;T local boxedDataB_l; DataIndex local DI; DataIndex local [] local neighborIdxes; int i,j; LIT.reset(); for (i=0;iLevelData*/ // To add another case when the two have the same layout. /* version 1 (before Nov 01, 2004) public final local single void copy(template BoxLayoutData local single a_BLDsrc, boolean single a_ghostIncluded){ Ti.barrier(); if (m_constructed && a_BLDsrc.isConstructed()) if (a_BLDsrc.isDisjointed()){ PrivateRegion local region=new PrivateRegion(); //LayoutIterator local LITA=new LayoutIterator(m_layout); LayoutIterator local LITA=m_layoutItr;//Aug 09, 2004 //LayoutIterator local LITB=new(region) LayoutIterator(a_BLDsrc.m_layout); LayoutIterator local LITB=a_BLDsrc.LayoutIterator();//Aug 09, 2004 RectDomain boxA,boxB; T local boxedDataA; T boxedDataB; T local boxedDataB_l; DataIndex local DI; LITA.reset(); if (m_layout==a_BLDsrc.m_layout){ for (int i=0;i local single a_BLDsrc, boolean single a_ghostIncluded){ Ti.barrier(); if (m_constructed && a_BLDsrc.isConstructed()) if (a_BLDsrc.isDisjointed()){ BoxLayout local BLB=a_BLDsrc.m_layout; LayoutIterator local LITA=m_layoutItr;//Aug 09, 2004 LayoutIterator local LITB=a_BLDsrc.m_layoutItr;//Nov 01, 2004 RectDomain boxA,boxB; T local boxedDataA; T boxedDataB; T local boxedDataB_l; //DataIndex local DI; int i,j,gIdxB,lIdxB,procIDB; LITA.reset(); if (m_layout==BLB){ for (i=0;i box; //Double.setPrecision(3); for (int i=0;i size=box.max()-box.min()+Point.all(1); int counter=0; System.out.println("Domain is "+box.toString()); foreach (point in box){ System.out.print(" "+BD[point]); counter++; if (counter==size[2]){ System.out.print("\n");System.out.flush(); counter=0; } } } } //Double.setPrecision(0); } }