-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sensei2 ghost libsim #3
base: master
Are you sure you want to change the base?
Changes from 4 commits
68ae584
a133e65
d26e55f
69dc6fb
ae5e05f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
#include <vtkInformation.h> | ||
#include <vtkObjectFactory.h> | ||
#include <vtkPointData.h> | ||
#include <vtkFloatArray.h> | ||
#include <vtkRectilinearGrid.h> | ||
#include <vtkUnsignedCharArray.h> | ||
|
||
#include <Error.h> | ||
#if defined(SENSEI_2) | ||
|
@@ -23,6 +26,7 @@ senseiNewMacro(JacobiDataAdaptor); | |
//----------------------------------------------------------------------------- | ||
JacobiDataAdaptor::JacobiDataAdaptor() | ||
{ | ||
this->sim = NULL; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
|
@@ -31,24 +35,19 @@ JacobiDataAdaptor::~JacobiDataAdaptor() | |
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void JacobiDataAdaptor::Initialize(int m, int rankx, int ranky, int bx, int by, int ng) | ||
void JacobiDataAdaptor::Initialize(simulation_data *s) | ||
{ | ||
(void)m; // m could be used for whole extents [0 m+2 0 m+2 0 0] | ||
|
||
this->Origin[0] = -double(ng); | ||
this->Origin[1] = -double(ng); | ||
this->Origin[2] = 0.0; | ||
|
||
this->Spacing[0] = 1.0; | ||
this->Spacing[1] = 1.0; | ||
this->Spacing[2] = 1.0; | ||
|
||
this->Extent[0] = rankx*(bx - 1); | ||
this->Extent[1] = this->Extent[0] + bx + 2*ng - 1; | ||
this->Extent[2] = ranky*by; | ||
this->Extent[3] = this->Extent[2] + by + 2*ng - 1; | ||
this->Extent[4] = 0; | ||
this->Extent[5] = 0; | ||
this->sim = s; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void JacobiDataAdaptor::Update(simulation_data *s) | ||
{ | ||
this->sim = s; | ||
|
||
this->SetDataTime(sim->iter*1.); | ||
this->SetDataTimeStep(sim->iter); | ||
this->AddArray("temperature", sim->Temp); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
|
@@ -111,14 +110,30 @@ int JacobiDataAdaptor::GetMesh(const std::string &meshName, bool structureOnly, | |
int n_ranks = 1; | ||
MPI_Comm_size(MPI_COMM_WORLD, &n_ranks); | ||
|
||
vtkImageData *block = vtkImageData::New(); | ||
block->SetExtent(this->Extent); | ||
block->SetOrigin(this->Origin); | ||
block->SetSpacing(this->Spacing); | ||
|
||
vtkRectilinearGrid *block = vtkRectilinearGrid::New(); | ||
int dims[3]; | ||
dims[0] = this->sim->bx+2; | ||
dims[1] = this->sim->by+2; | ||
dims[2] = 1; | ||
block->SetDimensions(dims); | ||
|
||
vtkFloatArray *x = vtkFloatArray::New(); | ||
vtkFloatArray *y = vtkFloatArray::New(); | ||
vtkFloatArray *z = vtkFloatArray::New(); | ||
int dontDelete = 1; | ||
x->SetArray(this->sim->cx, this->sim->bx+2, dontDelete); | ||
y->SetArray(this->sim->cy, this->sim->by+2, dontDelete); | ||
z->SetNumberOfTuples(1); | ||
z->SetTuple1(0,0.); | ||
block->SetXCoordinates(x); | ||
block->SetYCoordinates(y); | ||
block->SetZCoordinates(z); | ||
x->Delete(); | ||
y->Delete(); | ||
z->Delete(); | ||
this->Mesh = vtkSmartPointer<vtkMultiBlockDataSet>::New(); | ||
this->Mesh->SetNumberOfBlocks(n_ranks); | ||
this->Mesh->SetBlock(rank, block); | ||
this->Mesh->SetNumberOfBlocks(1); | ||
this->Mesh->SetBlock(0, block); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be SetBlock(rank, block) |
||
|
||
block->Delete(); | ||
} | ||
|
@@ -135,14 +150,14 @@ int JacobiDataAdaptor::AddArray(vtkDataObject* mesh, const std::string &meshName | |
vtkMultiBlockDataSet *mb = dynamic_cast<vtkMultiBlockDataSet*>(mesh); | ||
if (!mb) | ||
{ | ||
SENSEI_ERROR("Invlaid mesh type " << mesh->GetClassName()) | ||
SENSEI_ERROR("Invalid mesh type " << mesh->GetClassName()) | ||
return -1; | ||
} | ||
|
||
int rank = 0; | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
|
||
vtkImageData *block = dynamic_cast<vtkImageData*>(mb->GetBlock(rank)); | ||
vtkRectilinearGrid *block = dynamic_cast<vtkRectilinearGrid*>(mb->GetBlock(0)); | ||
if (!block) | ||
return 0; | ||
|
||
|
@@ -172,10 +187,7 @@ int JacobiDataAdaptor::AddArray(vtkDataObject* mesh, const std::string &meshName | |
vtkSmartPointer<vtkDoubleArray>& vtkarray = this->Arrays[iterV->first]; | ||
vtkarray = vtkSmartPointer<vtkDoubleArray>::New(); | ||
vtkarray->SetName(arrayName.c_str()); | ||
|
||
vtkIdType size = (this->Extent[1] - this->Extent[0] + 1) * | ||
(this->Extent[3] - this->Extent[2] + 1) * (this->Extent[5] - this->Extent[4] + 1); | ||
|
||
vtkIdType size = (this->sim->bx+2) * (this->sim->by+2); | ||
vtkarray->SetArray(iterV->second, size, 1); | ||
|
||
block->GetPointData()->SetScalars(vtkarray); | ||
|
@@ -232,6 +244,83 @@ int JacobiDataAdaptor::GetArrayName(const std::string &meshName, int association | |
return 0; | ||
} | ||
|
||
int JacobiDataAdaptor::GetMeshHasGhostNodes(const std::string &meshName, | ||
bool &hasGhostNodes, int &nLayers) | ||
{ | ||
if (meshName != "mesh") | ||
{ | ||
hasGhostNodes = false; | ||
nLayers = 0; | ||
SENSEI_ERROR("No mesh named " << meshName) | ||
return -1; | ||
} | ||
|
||
hasGhostNodes = true; | ||
nLayers = 1; | ||
return 0; | ||
} | ||
|
||
int JacobiDataAdaptor::AddGhostNodesArray(vtkDataObject* mesh, const std::string &meshName) | ||
{ | ||
if (meshName != "mesh") | ||
{ | ||
SENSEI_ERROR("No mesh named " << meshName) | ||
return -1; | ||
} | ||
|
||
vtkMultiBlockDataSet *mb = dynamic_cast<vtkMultiBlockDataSet*>(mesh); | ||
if (!mb) | ||
{ | ||
SENSEI_ERROR("Invalid mesh type " << mesh->GetClassName()) | ||
return -1; | ||
} | ||
|
||
vtkRectilinearGrid *block = dynamic_cast<vtkRectilinearGrid*>(mb->GetBlock(0)); | ||
if (!block) | ||
return -1; | ||
|
||
int nx = this->sim->bx+2; | ||
int ny = this->sim->by+2; | ||
vtkUnsignedCharArray *gn = vtkUnsignedCharArray::New(); | ||
gn->SetNumberOfTuples(nx*ny); | ||
gn->SetName(GHOST_NODE_ARRAY_NAME().c_str()); | ||
unsigned char *gptr = (unsigned char *)gn->GetVoidPointer(0); | ||
memset(gn->GetVoidPointer(0), 0, nx*nx*sizeof(unsigned char)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be nx*ny |
||
unsigned char ghost = 1; | ||
// Left column | ||
if(this->sim->rankx > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all the patches have full set of ghost nodes, so I think these tests on rank is not needed |
||
{ | ||
int i = 0, j = 0; | ||
for( ; j < ny; ++j) | ||
gptr[j*nx+i] = ghost; | ||
} | ||
// Right column | ||
if(this->sim->rankx < this->sim->cart_dims[0]-1) | ||
{ | ||
int i = nx-1, j = 0; | ||
for( ; j < ny; ++j) | ||
gptr[j*nx+i] = ghost; | ||
} | ||
// Bottom row | ||
if(this->sim->ranky > 0) | ||
{ | ||
int i = 0, j = 0; | ||
for( ; i < nx; ++i) | ||
gptr[j*nx+i] = ghost; | ||
} | ||
// Top row | ||
if(this->sim->ranky < this->sim->cart_dims[1]-1) | ||
{ | ||
int i = 0, j = ny-1; | ||
for( ; i < nx; ++i) | ||
gptr[j*nx+i] = ghost; | ||
} | ||
block->GetPointData()->SetScalars(gn); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use AddArray here, SetScalars should be used for the array you want to visualize |
||
gn->Delete(); | ||
|
||
return 0; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
int JacobiDataAdaptor::ReleaseData() | ||
{ | ||
|
@@ -252,17 +341,34 @@ vtkDataObject* JacobiDataAdaptor::GetMesh(bool vtkNotUsed(structure_only)) | |
int n_ranks = 1; | ||
MPI_Comm_size(MPI_COMM_WORLD, &n_ranks); | ||
|
||
vtkImageData *block = vtkImageData::New(); | ||
block->SetExtent(this->Extent); | ||
block->SetOrigin(this->Origin); | ||
block->SetSpacing(this->Spacing); | ||
|
||
vtkRectilinearGrid *block = vtkRectilinearGrid::New(); | ||
int dims[3]; | ||
dims[0] = this->sim->bx+2; | ||
dims[1] = this->sim->by+2; | ||
dims[2] = 1; | ||
block->SetDimensions(dims); | ||
|
||
vtkFloatArray *x = vtkFloatArray::New(); | ||
vtkFloatArray *y = vtkFloatArray::New(); | ||
vtkFloatArray *z = vtkFloatArray::New(); | ||
int dontDelete = 1; | ||
x->SetArray(this->sim->cx, this->sim->bx+2, dontDelete); | ||
y->SetArray(this->sim->cy, this->sim->by+2, dontDelete); | ||
z->SetNumberOfTuples(1); | ||
z->SetTuple1(0,0.); | ||
block->SetXCoordinates(x); | ||
block->SetYCoordinates(y); | ||
block->SetZCoordinates(z); | ||
x->Delete(); | ||
y->Delete(); | ||
z->Delete(); | ||
this->Mesh = vtkSmartPointer<vtkMultiBlockDataSet>::New(); | ||
this->Mesh->SetNumberOfBlocks(n_ranks); | ||
this->Mesh->SetBlock(rank, block); | ||
this->Mesh->SetNumberOfBlocks(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
this->Mesh->SetBlock(0, block); | ||
|
||
block->Delete(); | ||
} | ||
|
||
return this->Mesh; | ||
} | ||
|
||
|
@@ -283,7 +389,7 @@ bool JacobiDataAdaptor::AddArray(vtkDataObject* mesh, int association, const std | |
int rank = 0; | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
vtkMultiBlockDataSet *mb = dynamic_cast<vtkMultiBlockDataSet*>(mesh); | ||
vtkImageData *block = mb ? dynamic_cast<vtkImageData*>(mb->GetBlock(rank)) : nullptr; | ||
vtkRectilinearGrid *block = mb ? dynamic_cast<vtkRectilinearGrid*>(mb->GetBlock(0)) : nullptr; | ||
if (!block) | ||
return false; | ||
|
||
|
@@ -293,8 +399,7 @@ bool JacobiDataAdaptor::AddArray(vtkDataObject* mesh, int association, const std | |
vtkSmartPointer<vtkDoubleArray>& vtkarray = this->Arrays[iterV->first]; | ||
vtkarray = vtkSmartPointer<vtkDoubleArray>::New(); | ||
vtkarray->SetName(name.c_str()); | ||
vtkIdType size = (this->Extent[1] - this->Extent[0] + 1) * | ||
(this->Extent[3] - this->Extent[2] + 1) * (this->Extent[5] - this->Extent[4] + 1); | ||
vtkIdType size = (this->sim->bx+2) * (this->sim->by+2); | ||
vtkarray->SetArray(iterV->second, size, 1); | ||
block->GetPointData()->SetScalars(vtkarray); | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be n_ranks, because the way pjacobi decomposes the domain each rank has 1 block