Skip to content

Commit

Permalink
test/PABLO: add a test for checking AMR with periodic boundary condit…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
andrea-iob committed Nov 5, 2020
1 parent 5ae2249 commit 7bae643
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/PABLO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ if (ENABLE_MPI)
list(APPEND TESTS "test_PABLO_parallel_00002")
list(APPEND TESTS "test_PABLO_parallel_00003")
list(APPEND TESTS "test_PABLO_parallel_00004")
list(APPEND TESTS "test_PABLO_parallel_00005:4")
endif()

# Test extra libraries
Expand Down
139 changes: 139 additions & 0 deletions test/PABLO/test_PABLO_parallel_00005.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
*
* bitpit
*
* Copyright (C) 2015-2020 OPTIMAD engineering Srl
*
* -------------------------------------------------------------------------
* License
* This file is part of bitpit.
*
* bitpit is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License v3 (LGPL)
* as published by the Free Software Foundation.
*
* bitpit is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with bitpit. If not, see <http://www.gnu.org/licenses/>.
*
\*---------------------------------------------------------------------------*/

#include <mpi.h>

#include "bitpit_PABLO.hpp"

using namespace bitpit;

/*!
* Subtest 001
*
* Testing adaptive mesh refinement (AMR) with periodic boundary conditions.
*/
int subtest_001()
{
/**<Instantation of a 3D pablo uniform object.*/
PabloUniform pablo11(3);

/** Set Periodic boundary conditions */
pablo11.setPeriodic(0);
pablo11.setPeriodic(2);
pablo11.setPeriodic(4);

/**<Refine globally one level and write the octree.*/
pablo11.adaptGlobalRefine();

/**<Refine globally one level and write the octree.*/
pablo11.adaptGlobalRefine();

/**<Partition the tree.*/
pablo11.loadBalance();

/**<Write the tree.*/
pablo11.updateConnectivity();
pablo11.write("pablo_parallel_00005");

/**<Extract and print face neighbors.*/
uint32_t nOct = pablo11.getNumOctants();
std::cout << "Number of Octants : " << nOct << std::endl;
std::cout << "Extracting the four face neighbours of each Octant " << std::endl;
for (uint32_t iOct = 0; iOct < nOct; ++iOct) {
std::vector<uint32_t> neigh;
std::vector<bool> isGhost;
std::cout << ". Octant index : " << iOct << std::endl;
for (uint8_t iFace=0; iFace<pablo11.getNfaces(); ++iFace) {
pablo11.findNeighbours(iOct, iFace, 1, neigh, isGhost);
std::cout << " - For face " << (int)iFace << "; " << neigh.size() << " neighbours: [ ";
for (auto iNeigh : neigh) {
std::cout << iNeigh << " " << (isGhost[0] ? "(ghost)" : "");
}
std::cout << "]" << std::endl;
}
}

/**<Extract and print vertex neighbors .*/
std::cout << "Extracting the four vertex neighbours of each Octant " << std::endl;
for (uint32_t iOct = 0; iOct < nOct; ++iOct) {
std::vector<uint32_t> neigh;
std::vector<bool> isGhost;
std::cout << ". Octant index : " << iOct << std::endl;
for (uint8_t iVertex=0; iVertex<pablo11.getNnodes(); ++iVertex) {
pablo11.findNeighbours(iOct, iVertex, 3, neigh, isGhost);
std::cout << " - For vertex " << (int)iVertex << "; " << neigh.size() << " neighbours: [ ";
for (auto iNeigh: neigh) {
std::cout << iNeigh << " " << (isGhost[0] ? "(ghost)" : "");
}
std::cout << "]" << std::endl;
}
}

/**<Extract and print edge neighbors .*/
std::cout << "Extracting the four edge neighbours of each Octant " << std::endl;
for (uint32_t iOct=0; iOct < nOct; ++iOct) {
std::vector<uint32_t> neigh;
std::vector<bool> isGhost;
std::cout << ". Octant index : " << iOct << std::endl;
for (uint8_t iEdge = 0; iEdge<pablo11.getNedges(); ++iEdge) {
pablo11.findNeighbours(iOct, iEdge, 2, neigh, isGhost);
std::cout << " - For edge " << (int)iEdge << "; " << neigh.size() << " neighbours: [ ";
for (auto iNeigh: neigh) {
std::cout << iNeigh << " " << (isGhost[0] ? "(ghost)" : "");
}
std::cout << "]" << std::endl;
}
}

return 0;
}

/*!
* Main program.
*/
int main(int argc, char *argv[])
{
MPI_Init(&argc,&argv);

int nProcs;
int rank;
MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

// Run the subtests
log::cout() << "Testing parallel AMR with periodic boundary conditions." << std::endl;

int status;
try {
status = subtest_001();
if (status != 0) {
return status;
}
} catch (const std::exception &exception) {
log::cout() << exception.what();
exit(1);
}

MPI_Finalize();
}

0 comments on commit 7bae643

Please sign in to comment.