Skip to content

Commit

Permalink
helper to flush halo regions
Browse files Browse the repository at this point in the history
  • Loading branch information
natj committed Oct 27, 2020
1 parent ca7358d commit 38fa76f
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions tools/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ class Mesh
std::fill(mat.begin(), mat.end(), T() ); // fill with zeros
}

/// fill halos with zeros
void clear_halos() {

for(int k=-H; k<this->Nz+H; k++) {
for(int j=-H; j<this->Ny+H; j++) {
for(int i=-H; i<this->Nx+H; i++) {

if(
(i >= 0 && i < this->Nx) &&
(j >= 0 && j < this->Ny) &&
(k >= 0 && k < this->Nz)
) { continue; }

mat[ indx(i,j,k) ] = 0.0;
}}}

}


/// serialize 3D data cube into 1D vector
std::vector<T> serialize() const {
Expand Down Expand Up @@ -456,10 +474,9 @@ inline void Mesh<T,H>::copy_vert(Mesh<T,H2>& rhs, int lhsI, int rhsI) {
if(this->Ny != rhs.Ny) throw std::range_error ("y dimensions do not match");

for(int k=0; k<(int)this->Nz; k++) {
for(int j=0; j<(int)this->Ny; j++) {
this->operator()(lhsI, j, k) = rhs(rhsI, j, k);
}
}
for(int j=0; j<(int)this->Ny; j++) {
this->operator()(lhsI, j, k) = rhs(rhsI, j, k);
}}
}

/// Add vertical slice
Expand All @@ -470,10 +487,9 @@ inline void Mesh<T,H>::add_vert(Mesh<T,H2>& rhs, int lhsI, int rhsI) {
if(this->Ny != rhs.Ny) throw std::range_error ("y dimensions do not match");

for(int k=0; k<(int)this->Nz; k++) {
for(int j=0; j<(int)this->Ny; j++) {
this->operator()(lhsI, j, k) += rhs(rhsI, j, k);
}
}
for(int j=0; j<(int)this->Ny; j++) {
this->operator()(lhsI, j, k) += rhs(rhsI, j, k);
}}
}


Expand All @@ -485,10 +501,9 @@ inline void Mesh<T,H>::copy_horz(Mesh<T,H2>& rhs, int lhsJ, int rhsJ) {
if(this->Nx != rhs.Nx) throw std::range_error ("x dimensions do not match");

for(int k=0; k<(int)this->Nz; k++) {
for(int i=0; i<(int)this->Nx; i++) {
this->operator()(i, lhsJ, k) = rhs(i, rhsJ, k);
}
}
for(int i=0; i<(int)this->Nx; i++) {
this->operator()(i, lhsJ, k) = rhs(i, rhsJ, k);
}}
}

/// Add horizontal slice
Expand All @@ -499,10 +514,9 @@ inline void Mesh<T,H>::add_horz(Mesh<T,H2>& rhs, int lhsJ, int rhsJ) {
if(this->Nx != rhs.Nx) throw std::range_error ("x dimensions do not match");

for(int k=0; k<(int)this->Nz; k++) {
for(int i=0; i<(int)this->Nx; i++) {
this->operator()(i, lhsJ, k) += rhs(i, rhsJ, k);
}
}
for(int i=0; i<(int)this->Nx; i++) {
this->operator()(i, lhsJ, k) += rhs(i, rhsJ, k);
}}
}


Expand All @@ -514,10 +528,9 @@ inline void Mesh<T,H>::copy_face(Mesh<T,H2>& rhs, int lhsK, int rhsK) {
if(this->Ny != rhs.Ny) throw std::range_error ("y dimensions do not match");

for(int j=0; j<(int)this->Ny; j++) {
for(int i=0; i<(int)this->Nx; i++) {
this->operator()(i, j, lhsK) = rhs(i, j, rhsK);
}
}
for(int i=0; i<(int)this->Nx; i++) {
this->operator()(i, j, lhsK) = rhs(i, j, rhsK);
}}
}

/// Add face slice
Expand All @@ -528,10 +541,9 @@ inline void Mesh<T,H>::add_face(Mesh<T,H2>& rhs, int lhsK, int rhsK) {
if(this->Ny != rhs.Ny) throw std::range_error ("y dimensions do not match");

for(int j=0; j<(int)this->Ny; j++) {
for(int i=0; i<(int)this->Nx; i++) {
this->operator()(i, j, lhsK) += rhs(i, j, rhsK);
}
}
for(int i=0; i<(int)this->Nx; i++) {
this->operator()(i, j, lhsK) += rhs(i, j, rhsK);
}}
}

//--------------------------------------------------
Expand Down

0 comments on commit 38fa76f

Please sign in to comment.