Commit e8eabc5e authored by George Zagaris's avatar George Zagaris
Browse files

ENH: Integer-Space AMR blanking

Improved blanking algorithms & data-structures
to better support integer based blanking.
parent 6eaad215
......@@ -26,6 +26,7 @@
#include "vtkImageToStructuredGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredGridWriter.h"
#include "vtkUnsignedIntArray.h"
#include <string>
#include <sstream>
......@@ -73,6 +74,12 @@ void vtkAMRDataTransferFilter::Transfer( )
// STEP 1: Donor-Receiver search
this->DonorSearch();
// STEP 3: DataTransfer
this->DataTransfer( );
// STEP 4: Synch processes
this->Controller->Barrier( );
}
//------------------------------------------------------------------------------
......@@ -96,7 +103,8 @@ void vtkAMRDataTransferFilter::ExtrudeGhostLayers( )
vtkUniformGrid *myGrid =
this->AMRDataSet->GetDataSet(currentLevel,dataIdx,myBox);
myBox.ExtrudeGhostCells( this->NumberOfGhostLayers );
myBox.Grow( this->NumberOfGhostLayers );
// myBox.ExtrudeGhostCells( this->NumberOfGhostLayers );
myGrid = (myGrid != NULL)? this->GetExtrudedGrid(myBox,myGrid) : NULL;
if( myGrid != NULL )
......@@ -120,8 +128,19 @@ void vtkAMRDataTransferFilter::ExtrudeGhostLayers( )
void vtkAMRDataTransferFilter::DonorSearch()
{
vtkAssertUtils::assertNotNull(this->ExtrudedData,__FILE__,__LINE__);
vtkAssertUtils::assertNotNull(this->RemoteConnectivity,__FILE__,__LINE__);
vtkAssertUtils::assertNotNull(this->LocalConnectivity,__FILE__,__LINE__);
vtkUnsignedIntArray *rmtGridKeys =
this->RemoteConnectivity->GetEncodedGridKeys();
for( int i=0; i < rmtGridKeys->GetNumberOfTuples(); ++i )
{
}
vtkUnsignedIntArray *localGridKeys =
this->LocalConnectivity->GetEncodedGridKeys();
// TODO: implement this
}
//------------------------------------------------------------------------------
......@@ -202,9 +221,6 @@ void vtkAMRDataTransferFilter::WriteGrid( vtkUniformGrid* grid,
vtkStructuredGridWriter *myWriter = vtkStructuredGridWriter::New();
vtkAssertUtils::assertNotNull( myWriter,__FILE__,__LINE__);
std::cout << "Writing grid @" << fileName << std::endl;
std::cout.flush();
myWriter->SetInput(0,myGrid);
myWriter->SetFileName( fileName.c_str( ) );
myWriter->Update();
......
......@@ -81,11 +81,12 @@ class VTK_AMR_EXPORT vtkAMRDataTransferFilter:
void WriteGrid( vtkUniformGrid* grid, std::string prefix );
// Description:
//
// Process the remote connectivity and local connectivity lists and
// finds a donor for each
void DonorSearch();
// Description:
//
// Transfers
void DataTransfer();
int NumberOfGhostLayers;
......
......@@ -30,13 +30,15 @@ int main( int arc, char **argv )
std::cout << "\n======================================================\n";
std::cout.flush( );
myTestBox.ExtrudeGhostCells( 1 );
myTestBox.Grow( 1 );
// myTestBox.ExtrudeGhostCells( 1 );
myTestBox.WriteToVtkFile( "initial1.vtk" );
myTestBox.Print( std::cout );
std::cout << "\n======================================================\n";
std::cout.flush( );
myTestBox.ExtrudeGhostCells( 2 );
myTestBox.Grow( 2 );
// myTestBox.ExtrudeGhostCells( 2 );
myTestBox.WriteToVtkFile( "initial2.vtk" );
myTestBox.Print( std::cout );
std::cout << "\n======================================================\n";
......
......@@ -235,8 +235,10 @@ vtkAMRBox::vtkAMRBox(
{
this->X0[i] = dataSetOrigin[i];
this->DX[i] = h[i];
this->LoCorner[i] = floor( (boxOrigin[i]-dataSetOrigin[i])/h[i] );
this->LoCorner[i] = round( (boxOrigin[i]-dataSetOrigin[i])/h[i] );
this->HiCorner[i] = this->LoCorner[i] + ( ndim[i]-1 );
vtkAssertUtils::assertTrue( (this->LoCorner[i]>=0),__FILE__,__LINE__);
vtkAssertUtils::assertTrue( (this->HiCorner[i]>=0),__FILE__,__LINE__);
}
this->BlockId = blockIdx;
......@@ -262,9 +264,9 @@ int vtkAMRBox::GetNodeLinearIndex( const int i,const int j,const int k )
vtkAssertUtils::assertInRange(
i,this->LoCorner[0],this->HiCorner[0],__FILE__, __LINE__ );
vtkAssertUtils::assertInRange(
j,this->LoCorner[0],this->HiCorner[1],__FILE__, __LINE__ );
j,this->LoCorner[1],this->HiCorner[1],__FILE__, __LINE__ );
vtkAssertUtils::assertInRange(
k,this->LoCorner[0],this->HiCorner[2],__FILE__, __LINE__ );
k,this->LoCorner[2],this->HiCorner[2],__FILE__, __LINE__ );
int ndim[3];
int ijk[3];
......@@ -298,7 +300,7 @@ void vtkAMRBox::WriteToVtkFile( const char *file )
{
// Sanity Checks
vtkAssertUtils::assertNotNull( file, __FILE__, __LINE__ );
vtkAssertUtils::assertTrue( std::strlen( file )>0, __FILE__, __LINE__ );
// vtkAssertUtils::assertTrue( std::strlen( file )>0, __FILE__, __LINE__ );
std::ofstream ofs;
ofs.open( file );
......@@ -322,11 +324,11 @@ void vtkAMRBox::WriteToVtkFile( const char *file )
int ijk[3];
double pnt[3];
pnt[0] = pnt[1] = pnt[2] = 0;
for( int k=0; k < nodeExtent[2]; ++k )
for( int k=this->LoCorner[2]; k <= this->HiCorner[2]; ++k )
{
for( int j=0; j < nodeExtent[1]; ++j )
for( int j=this->LoCorner[1]; j <= this->HiCorner[1]; ++j )
{
for( int i=0; i < nodeExtent[0]; ++i )
for( int i=this->LoCorner[0]; i <= this->HiCorner[0]; ++i )
{
ijk[0] = i;
......@@ -931,52 +933,51 @@ double vtkAMRBox::GetMaxZ() const
}
//-----------------------------------------------------------------------------
bool vtkAMRBox::HasPoint( const double x, const double y, const double z )
void vtkAMRBox::GetMinBounds( double min[3] ) const
{
double xMax = 0.0;
double yMax = 0.0;
double zMax = 0.0;
min[0] = min[1] = min[2] = 0.0;
for( int i=0; i < this->Dimension; ++i )
min[ i ] = this->X0[i]+this->LoCorner[i]*this->DX[i];
}
int ndim[3];
this->GetNumberOfNodes( ndim );
switch( this->Dimension )
{
case 1:
xMax = this->X0[0]+(this->DX[0]*ndim[0]);
if( x >= this->X0[0] && x <= xMax )
return true;
break;
case 2:
xMax = this->X0[0]+(this->DX[0]*ndim[0]);
yMax = this->X0[1]+(this->DX[1]*ndim[1]);
//-----------------------------------------------------------------------------
void vtkAMRBox::GetMaxBounds( double max[3] ) const
{
max[0] = max[1] = max[2] = 0.0;
for( int i=0; i < this->Dimension; ++i )
max[ i ] =this->X0[i]+this->HiCorner[i]*this->DX[i];
}
// this->WriteBox(
// this->X0[0], this->X0[1], 0,
// xMax, yMax, 0 );
//-----------------------------------------------------------------------------
bool vtkAMRBox::HasPoint( const double x, const double y, const double z )
{
double min[3];
double max[3];
this->GetMinBounds( min );
this->GetMaxBounds( max );
if( x >= this->X0[0] && x <= xMax &&
y >= this->X0[1] && y <= yMax )
return true;
break;
case 3:
xMax = this->X0[0]+(this->DX[0]*ndim[0]);
yMax = this->X0[1]+(this->DX[1]*ndim[1]);
zMax = this->X0[2]+(this->DX[2]*ndim[2]);
// this->WriteBox(
// this->X0[0], this->X0[1], this->X0[2],
// xMax, yMax, zMax );
if( x >= this->X0[0] && x <= xMax &&
y >= this->X0[1] && y <= yMax &&
z >= this->X0[2] && z <= zMax )
return true;
break;
default:
// Code should not reach here!
// TODO: add better error handling here!
return false;
switch( this->Dimension )
{
case 1:
if( x >= min[0] && x <= max[0] )
return true;
break;
case 2:
if( x >= min[0] && x <= max[0] &&
y >= min[1] && y <= max[1] )
return true;
break;
case 3:
if( x >= min[0] && x <= max[0] &&
y >= min[1] && y <= max[1] &&
z >= min[2] && z <= max[2] )
return true;
break;
default:
// Code should not reach here!
// TODO: add better error handling here!
return false;
}
return false;
......@@ -1225,52 +1226,6 @@ ostream &vtkAMRBox::Print(ostream &os) const
return os;
}
//-----------------------------------------------------------------------------
void vtkAMRBox::ExtrudeGhostCells( int nlayers )
{
vtkAssertUtils::assertTrue( (nlayers>=1), __FILE__, __LINE__ );
for( int layer=0; layer < nlayers; ++layer )
{
// STEP 0: Shift origin and increase the dimension
for( int i=0; i < this->Dimension; ++i )
{
vtkAssertUtils::assertEquals(this->LoCorner[i],0,__FILE__,__LINE__);
this->X0[i] -= this->DX[i];
this->HiCorner[i] += 2;
this->NG[i]++;
}
}
// Update the RealExtent
switch( this->Dimension )
{
case 1:
this->RealExtent[0] = this->LoCorner[0]+nlayers; // real-imin
this->RealExtent[1] = this->HiCorner[0]-nlayers; // real-imax
break;
case 2:
this->RealExtent[0] = this->LoCorner[0]+nlayers; // real-imin
this->RealExtent[1] = this->HiCorner[0]-nlayers; // real-imax
this->RealExtent[2] = this->LoCorner[1]+nlayers; // real-jmin
this->RealExtent[3] = this->HiCorner[1]-nlayers; // real-jmax
break;
case 3:
this->RealExtent[0] = this->LoCorner[0]+nlayers; // real-imin
this->RealExtent[1] = this->HiCorner[0]-nlayers; // real-imax
this->RealExtent[2] = this->LoCorner[1]+nlayers; // real-jmin
this->RealExtent[3] = this->HiCorner[1]-nlayers; // real-jmax
this->RealExtent[4] = this->LoCorner[2]+nlayers; // real-kmin
this->RealExtent[5] = this->HiCorner[2]-nlayers; // real-kmax
break;
default:
// Code should not reach here!
// TODO: Better error handling of this case!
this->Invalidate();
}
}
//-----------------------------------------------------------------------------
void vtkAMRBox::GetRealExtent( int realext[6] ) const
{
......@@ -1294,10 +1249,14 @@ void vtkAMRBox::SetRealExtent( int realExtent[6] )
realExtent[2],this->LoCorner[1],this->HiCorner[1],__FILE__,__LINE__);
vtkAssertUtils::assertInRange(
realExtent[3],this->LoCorner[1],this->HiCorner[1],__FILE__,__LINE__);
vtkAssertUtils::assertInRange(
realExtent[4],this->LoCorner[2],this->HiCorner[2],__FILE__,__LINE__);
vtkAssertUtils::assertInRange(
realExtent[5],this->LoCorner[2],this->HiCorner[2],__FILE__,__LINE__);
if( this->Dimension == 3 )
{
vtkAssertUtils::assertInRange(
realExtent[4],this->LoCorner[2],this->HiCorner[2],__FILE__,__LINE__);
vtkAssertUtils::assertInRange(
realExtent[5],this->LoCorner[2],this->HiCorner[2],__FILE__,__LINE__);
}
this->RealExtent[0] = realExtent[0]; // imin
this->RealExtent[1] = realExtent[1]; // imax
......@@ -1344,7 +1303,7 @@ bool vtkAMRBox::IsGhostNode( const int i, const int j, const int k )
switch( this->Dimension )
{
case 1:
if( (i < this->RealExtent[0]) || (i > this->RealExtent[1]) )
if( (i < this->RealExtent[0]) || (i > this->RealExtent[1]) )
status = true;
break;
case 2:
......@@ -1355,7 +1314,7 @@ bool vtkAMRBox::IsGhostNode( const int i, const int j, const int k )
case 3:
if( (i < this->RealExtent[0]) || (i > this->RealExtent[1]) ||
(j < this->RealExtent[2]) || (j > this->RealExtent[3]) ||
(k < this->RealExtent[4]) || (k > this->RealExtent[5] ) )
(k < this->RealExtent[4]) || (k > this->RealExtent[5]) )
status = true;
break;
default:
......@@ -1370,6 +1329,7 @@ bool vtkAMRBox::IsGhostNode( const int i, const int j, const int k )
void vtkAMRBox::GetPoint( const int ijk[3], double pnt[3] ) const
{
// Compiler should unroll this small loop!
pnt[0] = 0.0; pnt[1] = 0.0; pnt[2] = 0.0;
for( int i=0; i < this->Dimension; ++i )
{
// Sanity Check!
......@@ -1488,22 +1448,6 @@ void vtkAMRBox::Deserialize( unsigned char* buffer, const size_t &bytesize )
ptr += 3*sizeof( int );
}
//-----------------------------------------------------------------------------
void vtkAMRBox::GetMinBounds( double min[3] ) const
{
min[0] = this->GetMinX();
min[1] = this->GetMinY();
min[2] = this->GetMinZ();
}
//-----------------------------------------------------------------------------
void vtkAMRBox::GetMaxBounds( double max[3] ) const
{
max[0] = this->GetMaxX();
max[1] = this->GetMaxY();
max[2] = this->GetMaxZ();
}
//-----------------------------------------------------------------------------
bool vtkAMRBox::Collides( const vtkAMRBox &b1, const vtkAMRBox &b2)
{
......
......@@ -321,11 +321,6 @@ public:
// i-j-k coordinates is a ghost node.
bool IsGhostNode( const int i, const int j, const int k );
// Description:
// Extrudes a provided number of (virtual) ghost cells
// nlayers -- the number of layers of ghost cells to extrude. Default is 1.
void ExtrudeGhostCells( int nlayers=1 );
// Description:
// Writes this instance of AMR box as a uniform grid in a VTK file
// that can be visualized with ParaView.
......
......@@ -32,6 +32,7 @@
#include "vtkAssertUtils.hpp"
#include <vtkstd/vector>
#include <sstream>
#include <cassert>
vtkStandardNewMacro(vtkHierarchicalBoxDataSet);
......@@ -369,12 +370,13 @@ void vtkHierarchicalBoxDataSet::GenerateCellVisibility(
//----------------------------------------------------------------------------
void vtkHierarchicalBoxDataSet::GeneratePointVisibility(
const unsigned int level, vtkUniformGrid *coarseGrid )
const unsigned int level, vtkUniformGrid *coarseGrid, vtkAMRBox* coarseBox )
{
// Sanity Check!
vtkAssertUtils::assertTrue(
level<=this->GetNumberOfLevels(), __FILE__, __LINE__);
vtkAssertUtils::assertNotNull(coarseGrid,__FILE__,__LINE__);
vtkAssertUtils::assertNotNull(coarseBox,__FILE__,__LINE__ );
unsigned int nextLevel = level+1;
unsigned int dataIdx = 0;
......@@ -382,23 +384,42 @@ void vtkHierarchicalBoxDataSet::GeneratePointVisibility(
for( ; dataIdx < numDataSets; ++dataIdx )
{
vtkAMRBox fineBox;
vtkUniformGrid *fineGrid = this->GetDataSet(
nextLevel, dataIdx, fineBox );
vtkAssertUtils::assertEquals(
fineBox.GetLevel(), nextLevel,__FILE__,__LINE__);
vtkAMRBox fineBox;
vtkUniformGrid *fineGrid = this->GetDataSet(
nextLevel, dataIdx, fineBox );
vtkAssertUtils::assertEquals(
fineBox.GetLevel(), nextLevel,__FILE__,__LINE__);
fineBox.Coarsen( this->GetRefinementRatio( level ) );
const int *hi = coarseBox->GetHiCorner();
const int *lo = coarseBox->GetLoCorner();
for( int i=lo[0]; i <= hi[0]; ++i )
{
for( int j=lo[1]; j <= hi[1]; ++j )
{
for( int k=lo[2]; k <= hi[2]; ++k )
{
if( fineBox.Contains( i,j,k ) )
{
int li,lj,lk; // local ijk indices
li = i-lo[0];
lj = j-lo[1];
lk = k-lo[2];
coarseGrid->BlankPoint(li,lj,lk);
}
} // END for k
} // END for j
} // END for i
unsigned int pnt = 0;
for( ; pnt < coarseGrid->GetNumberOfPoints(); ++pnt )
{
double X[3];
coarseGrid->GetPoint( pnt, X );
if( fineBox.HasPoint( X[0],X[1],X[2] ) )
coarseGrid->BlankPoint( pnt );
}
} // END for all data at next level
coarseGrid->AttachPointVisibilityToPointData();
}
//----------------------------------------------------------------------------
......@@ -425,7 +446,7 @@ void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays( )
coarseGrid->GetNumberOfPoints(),coarseBox.GetNumberOfNodes(),
__FILE__,__LINE__ );
this->GeneratePointVisibility( level, coarseGrid );
this->GeneratePointVisibility( level, coarseGrid, &coarseBox );
this->GenerateCellVisibility( coarseGrid );
}
// Else the grid does not belong to this process
......@@ -462,6 +483,7 @@ void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays( )
}
//----------------------------------------------------------------------------
//void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays()
//{
......@@ -514,28 +536,26 @@ void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays( )
// if (grid && !box.Empty())
// {
//
// std::cout << "Grid Number of Cells=" << grid->GetNumberOfCells( );
// std::cout << std::endl;
// std::cout << "Box Number of Cells=" << box.GetNumberOfCells( );
// std::cout << std::endl;
//
// assert( grid->GetNumberOfCells()==box.GetNumberOfCells() );
//// std::cout << "Got Here!" << std::endl;
//// std::cout.flush( );
// assert( grid->GetNumberOfPoints()==box.GetNumberOfNodes() );
//
//// int cellDims[3];
//// box.GetNumberOfCells(cellDims);
//// vtkUnsignedCharArray* vis = vtkUnsignedCharArray::New();
//// int N = box.GetNumberOfCells();
//
// int cellDims[3];
// box.GetNumberOfCells(cellDims);
// box.GetNumberOfNodes(cellDims);
// vtkUnsignedCharArray* vis = vtkUnsignedCharArray::New();
// vtkIdType numCells = box.GetNumberOfCells();
// vis->SetNumberOfTuples(numCells);
// int N = box.GetNumberOfNodes();
//
// vis->SetNumberOfTuples( N );
// vis->FillComponent(0,static_cast<char>(1));
// vtkIdType numBlankedPts = 0;
//
// if (!boxes.empty())
// {
//
//// std::cout << "Got Here2!" << std::endl;
//// std::cout.flush( );
//
// const int *loCorner=box.GetLoCorner();
// const int *hiCorner=box.GetHiCorner();
// for (int iz=loCorner[2]; iz<=hiCorner[2]; iz++)
......@@ -544,27 +564,39 @@ void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays( )
// {
// for (int ix=loCorner[0]; ix<=hiCorner[0]; ix++)
// {
//
// // Blank if cell is covered by a box of higher level
// if (vtkHierarchicalBoxDataSetIsInBoxes(boxes, ix, iy, iz))
// {
// vtkIdType id =
// (iz-loCorner[2])*cellDims[0]*cellDims[1] +
// (iy-loCorner[1])*cellDims[0] +
// (ix-loCorner[0]);
// vis->SetValue(id, 0);
//// std::cout << "blanking cell:" << id << std::endl;
//// std::cout.flush( );
// numBlankedPts++;
// int ndim[3];
// box.GetNumberOfNodes( ndim );
//
// int ijk[3] = { ix, iy, iz };
//
//// vtkIdType id = vtkStructuredData::ComputeCellId(ndim,ijk);
// vtkIdType id =
// (iz-loCorner[2])*cellDims[0]*cellDims[1] +
// (iy-loCorner[1])*cellDims[0] +
// (ix-loCorner[0]);
// vtkAssertUtils::assertInRange(
// id, 0, vis->GetNumberOfTuples()-1,__FILE__,__LINE__);
// vis->SetValue(id, 0);
// numBlankedPts++;
// }
// }
// }
// }
//
// } // END for x
// } // END for y
// } // END for z
//
// }
//
// grid->SetCellVisibilityArray(vis);
// grid->AttachCellVisibilityToCellData();
//// grid->AttachPointVisibilityToPointData();
// vis->Delete();
// grid->SetPointVisibilityArray( vis );
// grid->AttachPointVisibilityToPointData();
//
//// grid->SetCellVisibilityArray(vis);
//// grid->AttachCellVisibilityToCellData();
//
//
// if (this->HasMetaData(levelIdx, dataSetIdx))
// {
// vtkInformation* infotmp =
......
......@@ -216,7 +216,7 @@ protected:
// Description:
// Computes the point visibility array of the given grid @the provided level.
virtual void GeneratePointVisibility( const unsigned int level,
vtkUniformGrid *gridPtr );
vtkUniformGrid *gridPtr, vtkAMRBox* coarseBox );
// Description:
// Computes the cell visibility array of the given grid based on the pre-
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment