ConstantFineInterp
is defined on two levels of BoxLayout<\code>, the fine and the
* coarse. A ConstantFineInterp
object is used to interp a BoxLayoutData<\code>
* defined at the coarse level to one defined at the fine level. This algorithm only works on
* BoxLayoutData<\code>s with BoxedArray
components.
* Given a BoxLayoutData<\code> at the coarse level, this algorithm first does an constant
* interpretation of it to its refined version defined at the fine level, then copies the refined
* version to any BoxLayoutData<\code> defined at same level. A copier should be used to cache
* the copy relation between the two levels (which has not beenimplemented yet).
* Please refer to the Chombo design document for the details of this algorithm.
* Usage: a ConstantFineInterp
object must be declared local.
* @see BoxTools.BoxLayout, BoxTools.BoxLayoutData, BoxTools.LayoutIterator, BoxTools.BoxedArray
* and BoxTools.DataIndex.
* @see Chombo Specification
* @version 1.1
* Modified on Jul 09, 2004. change of syntax of foreach, see BoxTools/foreachLoopTest.ti.
* @author Tong Wen, LBNL
* @since 1.0
*/
template public class ConstantFineInterp{
private int single m_refRatio=1;
//private int single m_nComp;
private static final int SPACE_DIM=BoxTools.Util.SPACE_DIM;
private template BoxLayoutData > local single m_coarseData_f;
private BoxLayout single local m_coarseLayout_f;
private LayoutIterator local m_coarseLayoutItr;
private RectDomain m_localRegion;
/*
private RectDomain m_localRegion, m_localRegion_2;
private final RectDomain m_subLocalRegion=[Point.all(0):Point.all(1)];
private RectDomain [] local m_subLocalRegions;
private int m_numSubRegion;
*/
private BoxLayout single local m_coarseLayout;
private template Copier > local single m_copier;
private boolean single m_copierConstructed=false;
Timer tmr=new Timer();
public ConstantFineInterp(){}
public ConstantFineInterp(BoxLayout single local a_coarseLayout, int single a_refRatio){
define(a_coarseLayout, a_refRatio);
}
public final local void define(BoxLayout single local a_coarseLayout, int single a_refRatio){
m_refRatio=a_refRatio;
m_coarseLayout=a_coarseLayout;
m_coarseLayout_f=a_coarseLayout.refine(a_refRatio);
m_coarseLayoutItr=new LayoutIterator(a_coarseLayout);
m_coarseData_f=new template BoxLayoutData >(m_coarseLayout_f,0);
/* //assume unit stride
if (m_coarseLayoutItr.IsEnded())
m_localRegion=[Point.all(0):Point.all(m_refRatio-1)];
else
//m_localRegion=[Point.all(0):Point.all(m_refRatio-1):m_coarseLayoutItr.Access().stride()];
m_localRegion=[Point.all(0):m_coarseLayoutItr.Access().stride()*(m_refRatio-1):m_coarseLayoutItr.Access().stride()];
*/
m_localRegion=[Point.all(0):Point.all(m_refRatio-1)];
/*
m_localRegion_2=[Point.all(0):Point.all(m_refRatio-1):Point.all(2)];
m_numSubRegion=m_localRegion_2.size();
m_subLocalRegions=new RectDomain [m_numSubRegion];
int i=0;
foreach(point in m_localRegion_2){
m_subLocalRegions[i]=m_subLocalRegion+point;
i++;
}*/
m_coarseLayoutItr.Reset();
}
/*
final local void interpToFine(template BoxLayoutData > local single a_coarseData){
PrivateRegion local region=new PrivateRegion();
DataIndex local DI;
T [SPACE_DIM d] local TiArray_c, TiArray_f,buffer;
Point point_f;
T interp;
RectDomain box_c, box_f;
m_coarseLayoutItr.reset();
int i=0;
while (!m_coarseLayoutItr.isEnded()){
box_c=m_coarseLayoutItr.access();
DI=m_coarseLayoutItr.getDataIndex();
TiArray_f=m_coarseData_f[DI].getLocalArray();
TiArray_c=a_coarseData[DI].getLocalArray();
tmr.start();
foreach (point_c in box_c){
interp=TiArray_c[point_c];
point_f=point_c*m_refRatio;
box_f=m_localRegion+point_f;
buffer=new(region) T [box_f];
foreach (point in box_f) buffer[point]=interp;
TiArray_f.copy(buffer);
}
tmr.stop();
m_coarseLayoutItr.advance();i++;
}
Util.countRestrict+=tmr.millis();tmr.reset();
Util.countPointer+=i;
try {
region.delete();
}
catch (RegionInUse e){
Util.printErrMsg("ConstantFineInterp::interpToFine(): failed to delete PrivateRegion region");
}
}*/
/*
final local void interpToFine(template BoxLayoutData > local single a_coarseData){
PrivateRegion local region=new PrivateRegion();
DataIndex local DI;
T [SPACE_DIM d] local TiArray_c, TiArray_f,buffer, buffer_t;
buffer=new(region) T [m_localRegion];
Point point_f;
T interp;
RectDomain box;
m_coarseLayoutItr.reset();
int i=0;
while (!m_coarseLayoutItr.isEnded()){
box=m_coarseLayoutItr.access();
DI=m_coarseLayoutItr.getDataIndex();
TiArray_f=m_coarseData_f[DI].getLocalArray();
TiArray_c=a_coarseData[DI].getLocalArray();
tmr.start();
if (m_refRatio>2){
foreach (point_c in box){
interp=TiArray_c[point_c];
point_f=point_c*m_refRatio;
foreach (point in m_localRegion) buffer[point]=interp;
buffer_t=buffer.translate(point_f);
TiArray_f.copy(buffer_t);
}
}
else{
foreach (point_c in box){
point_f=point_c*m_refRatio;
interp=TiArray_c[point_c];
foreach (point in m_localRegion) TiArray_f[point_f+point]=interp;
}
}
tmr.stop();
m_coarseLayoutItr.advance();i++;
}
Util.countRestrict+=tmr.millis();tmr.reset();
Util.countPointer+=i;
try {
region.delete();
}
catch (RegionInUse e){
Util.printErrMsg("ConstantFineInterp::interpToFine(): failed to delete PrivateRegion region");
}
}*/
/*
final local void interpToFine(template BoxLayoutData > local single a_coarseData){
DataIndex local DI;
T [SPACE_DIM d] local TiArray_c, TiArray_f;
//Point point, point_c, point_f; // for change in the syntax of foreach
Point point_f;
T interp;
RectDomain box,box_f;
m_coarseLayoutItr.reset();
int j;
int i=0;
while (!m_coarseLayoutItr.isEnded()){
box=m_coarseLayoutItr.access();
DI=m_coarseLayoutItr.getDataIndex();
TiArray_f=m_coarseData_f[DI].getLocalArray();
TiArray_c=a_coarseData[DI].getLocalArray();
tmr.start();
if (m_refRatio>2)
// foreach(point_2 in m_localRegion_2)
// foreach (point_c in box){
//point_f=point_c*m_refRatio+point_2;
//interp=TiArray_c[point_c];
//foreach (point in m_subLocalRegion) TiArray_f[point_f+point]=interp; //July 13, 2004
//}
for(j=0;j > local single a_coarseData){
DataIndex local DI;
T [SPACE_DIM d] local TiArray_c, TiArray_f;
//Point point, point_c, point_f; // for change in the syntax of foreach
Point point_f;
T interp;
RectDomain box,box_f;
m_coarseLayoutItr.reset();
int i=0;
while (!m_coarseLayoutItr.isEnded()){
box=m_coarseLayoutItr.access();
DI=m_coarseLayoutItr.getDataIndex();
TiArray_f=m_coarseData_f[DI].getLocalArray();
TiArray_c=a_coarseData[DI].getLocalArray();
tmr.start();
if (m_refRatio>2){
foreach (point_c in box){
point_f=point_c*m_refRatio;
interp=TiArray_c[point_c];
box_f=m_localRegion+point_f;
foreach (point in box_f) TiArray_f[point]=interp;
//foreach (point in m_localRegion) TiArray_f[point_f+point]=interp; //July 13, 2004
}
//i+=box.size();
}
else
foreach (point_c in box){
point_f=point_c*m_refRatio;
interp=TiArray_c[point_c];
foreach (point in m_localRegion) TiArray_f[point_f+point]=interp; //July 13, 2004
}
tmr.stop();
m_coarseLayoutItr.advance();//i++;
}
Util.countRestrict+=tmr.millis();tmr.reset();
//Util.countPointer+=i;
}
/*
final local void interpToFine(template BoxLayoutData > local single a_coarseData){
DataIndex local DI;
T [SPACE_DIM d] local TiArray_c, TiArray_f;
Point point_c, point_cc;
T interp;
RectDomain box;
m_coarseLayoutItr.reset();
while (!m_coarseLayoutItr.isEnded()){
DI=m_coarseLayoutItr.getDataIndex();
box=m_coarseLayout_f[DI];
TiArray_f=m_coarseData_f[DI].getLocalArray();
TiArray_c=a_coarseData[DI].getLocalArray();
tmr.start();
//foreach (point_f in box)
// TiArray_f[point_f]=TiArray_c[point_f/m_refRatio];
point_cc=Point.all(-1000000000);
foreach (point_f in box){
point_c=point_f/m_refRatio;
if (point_c!=point_cc){
interp=TiArray_c[point_c];
point_cc=point_c;
}
TiArray_f[point_f]=interp;
}
tmr.stop();
m_coarseLayoutItr.advance();
}
Util.countPointer+=tmr.millis();tmr.reset();
}
*/
public final local void interpToFine(template BoxLayoutData > local single a_fineData, template BoxLayoutData > local single a_coarseData){
interpToFine(a_fineData, a_coarseData, true);
}
public final local void interpToFine(template BoxLayoutData > local single a_fineData, template BoxLayoutData > local single a_coarseData, boolean single a_copierON){
if (m_coarseLayout==(BoxLayout single)a_coarseData.boxLayout()) {
interpToFine(a_coarseData);
if (a_copierON){
if (!m_copierConstructed){
m_copier=new template Copier > (a_fineData.boxLayout(),m_coarseLayout_f);
m_copierConstructed=true;
}
m_copier.copy(a_fineData, m_coarseData_f);
}
else
a_fineData.copy(m_coarseData_f, false);
}
else{
Util.printErrMsg("ConstantFineInterp::interpToFine(): the layout of the coarse data is wrong!");
}
}
/*public final local template BoxLayoutData > local single interpToLocalFine(
template BoxLayoutData > local single a_coarseData){
if (m_coarseLayout==(BoxLayout single)a_coarseData.boxLayout()) {
interpToFine(a_coarseData);
fineData=new template BoxLayoutData >(m_coarseLayout_f,0);
fineData<<=m_coarseData_f;
return fineData
}
else{
Util.printErrMsg("ConstantFineInterp::interpToLocalFine(): the layout of the coarse data is wrong!");
return null;
}
}*/
}