Skip to content

Commit

Permalink
test/surfunstructured: add a test that adjusts the orientation of a o…
Browse files Browse the repository at this point in the history
…ne-dimensional surface
  • Loading branch information
andrea-iob committed Jan 7, 2021
1 parent e0b2deb commit 2f67e5f
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/surfunstructured/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ if (ENABLE_MPI)
TARGET "test_surfunstructured_parallel_00003" PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/data/buddha.stl" "${CMAKE_CURRENT_BINARY_DIR}/data/buddha.stl"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/data/disc.stl" "${CMAKE_CURRENT_BINARY_DIR}/data/disc.stl"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/data/circle.dgf" "${CMAKE_CURRENT_BINARY_DIR}/data/circle.dgf"
)

add_custom_command(
Expand Down
70 changes: 70 additions & 0 deletions test/surfunstructured/data/circle.dgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
VERTEX
1 0 0
0.980785 0.19509 0
0.92388 0.382683 0
0.83147 0.55557 0
0.707107 0.707107 0
0.55557 0.83147 0
0.382683 0.92388 0
0.19509 0.980785 0
6.12323e-17 1 0
-0.19509 0.980785 0
-0.382683 0.92388 0
-0.55557 0.83147 0
-0.707107 0.707107 0
-0.83147 0.55557 0
-0.92388 0.382683 0
-0.980785 0.19509 0
-1 1.22465e-16 0
-0.980785 -0.19509 0
-0.92388 -0.382683 0
-0.83147 -0.55557 0
-0.707107 -0.707107 0
-0.55557 -0.83147 0
-0.382683 -0.92388 0
-0.19509 -0.980785 0
-1.83697e-16 -1 0
0.19509 -0.980785 0
0.382683 -0.92388 0
0.55557 -0.83147 0
0.707107 -0.707107 0
0.83147 -0.55557 0
0.92388 -0.382683 0
0.980785 -0.19509 0
#

SIMPLEX
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 0
#

203 changes: 203 additions & 0 deletions test/surfunstructured/test_surfunstructured_parallel_00003.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,204 @@ return 0;

}

// ========================================================================== //
// SUBTEST #003 Test surface orientation //
// ========================================================================== //
int subtest_003(
void
) {

// ========================================================================== //
// int subtest_003( //
// void) //
// //
// Test mesh orientation //
// ========================================================================== //
// INPUT //
// ========================================================================== //
// - none //
// ========================================================================== //
// OUTPUT //
// ========================================================================== //
// - err : int, error flag: //
// err = 0 --> no error(s) //
// err = 1 --> error at step #1 (import STL) //
// err = 2 --> error at step #2 (mesh partition) //
// err = 3 --> error at step #3 (mesh orientation) //
// ========================================================================== //

// ========================================================================== //
// VARIABLES DECLARATION //
// ========================================================================== //

// Local variables
string in_name_bin = "./data/circle.dgf";
SurfUnstructured mesh(1, 2);

// Counters
// none

// ========================================================================== //
// INITIALIZE MESH PARAMETERS //
// ========================================================================== //
{
// Scope variables ------------------------------------------------------ //
// none

// Set name ------- ----------------------------------------------------- //
mesh.getVTK().setName("test_surfunstructured_parallel_00003_subtest_003");

// Set communicator ----------------------------------------------------- //
mesh.setCommunicator(MPI_COMM_WORLD);
}

// ========================================================================== //
// OUTPUT MESSAGE //
// ========================================================================== //
{
// Scope variables
// none

// Output message
log::cout() << "** ================================================================= **" << endl;
log::cout() << "** Sub-test #003 - Orientation surface **" << endl;
log::cout() << "** ================================================================= **" << endl;
log::cout() << endl;
}

// ========================================================================== //
// STEP #1 (IMPORT MESH FROM BINARY STL AND FLIP EVERY 4TH TRIANGLE) //
// ========================================================================== //
int myRank = mesh.getRank();
if (myRank == 0) {
// Scope variables ------------------------------------------------------ //
// None

// Import mesh from stl format ------------------------------------------ //
log::cout() << "** Importing mesh from (ASCII): \"" << in_name_bin << "\"" << endl;
if (mesh.importDGF(in_name_bin) != 0) return 1;
mesh.collapseCoincidentVertices();
}

{
// Scope variables ------------------------------------------------------ //
// None

// Build adjacencies --------------------------------------------------- //
mesh.initializeAdjacencies();
}

if (myRank == 0) {
// Scope variables ------------------------------------------------------ //
// None

// Mess-up the orientation ---------------------------------------------- //
for (const auto &cell : mesh.getCells()) {
if (!cell.isInterior()) {
continue;
}

long cellId = cell.getId();
if (cellId % 4 == 0) {
mesh.flipCellOrientation(cellId);
}
}
}

// ========================================================================== //
// STEP #2 (PARTITION THE MESH) //
// ========================================================================== //
{
// Scope variables ------------------------------------------------------ //
long nCells = mesh.getCellCount();

int nProcs;
MPI_Comm_size(MPI_COMM_WORLD, &nProcs);

// Evaluation of baricenter ----------------------------------------------//
std::array<double, 3> baricenter = {{0, 0, 0}};
for (const auto &cell : mesh.getCells()) {
baricenter += mesh.evalCellCentroid(cell.getId());
}
baricenter = baricenter / ((double) nCells);

// Partitioning ----------------------------------------------------------//
log::cout() << "** Mesh partitioning" << endl;

std::unordered_map<long, int> cellRanks;
if (myRank == 0) {
for (const auto &cell : mesh.getCells()) {
int side_x = (mesh.evalCellCentroid(cell.getId())[0] > baricenter[0]) ? 0 : 1;
int side_y = (mesh.evalCellCentroid(cell.getId())[1] > baricenter[1]) ? 0 : 1;
int side_z = (mesh.evalCellCentroid(cell.getId())[2] > baricenter[2]) ? 0 : 1;

int rank = -1;
if (side_z == 0 && side_y == 0 && side_x == 0) {
rank = 0;
} else if (side_z == 0 && side_y == 0 && side_x == 1) {
rank = 1;
} else if (side_z == 0 && side_y == 1 && side_x == 0) {
rank = 2;
} else if (side_z == 0 && side_y == 1 && side_x == 1) {
rank = 3;
} else if (side_z == 1 && side_y == 0 && side_x == 0) {
rank = 4;
} else if (side_z == 1 && side_y == 0 && side_x == 1) {
rank = 5;
} else if (side_z == 1 && side_y == 1 && side_x == 0) {
rank = 6;
} else if (side_z == 1 && side_y == 1 && side_x == 1) {
rank = 7;
}
rank = rank % nProcs;

cellRanks[cell.getId()] = rank;
}
}

mesh.partition(cellRanks, false);

}

// ========================================================================== //
// STEP #3 (ADJUST ORIENTATION) //
// ========================================================================== //
{
// Adjust orientation --------------------------------------------------- //
log::cout() << "** Mesh adjust orientation" << endl;
bool orientable = mesh.adjustCellOrientation();
if (orientable) {
log::cout() << " Mesh successfully oriented" << endl;
} else {
log::cout() << " Error during surface orientation" << endl;
}

// Write mesh ----------------------------------------------------------- //
log::cout() << "** Writing mesh" << endl;
mesh.write();

// Output message ------------------------------------------------------- //
log::cout() << "** Mesh partitioning" << endl;
}

// ========================================================================== //
// OUTPUT MESSAGE //
// ========================================================================== //
{
// Scope variables
// none

// Output message
log::cout() << "** ================================================================= **" << endl;
log::cout() << "** Sub-test #003 - completed! **" << endl;
log::cout() << "** ================================================================= **" << endl;
log::cout() << endl;
}

return 0;

}

// ========================================================================== //
// MAIN //
// ========================================================================== //
Expand Down Expand Up @@ -480,6 +678,11 @@ int main(int argc, char *argv[])
if (status != 0) {
return (20 + status);
}

status = subtest_003();
if (status != 0) {
return (30 + status);
}
} catch (const std::exception &exception) {
log::cout() << exception.what();
exit(1);
Expand Down

0 comments on commit 2f67e5f

Please sign in to comment.