| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Panzer: A partial differential equation assembly |
| 4 |
// engine for strongly coupled complex multiphysics systems |
| 5 |
// |
| 6 |
// Copyright 2011 NTESS and the Panzer contributors. |
| 7 |
// SPDX-License-Identifier: BSD-3-Clause |
| 8 |
// ***************************************************************************** |
| 9 |
// @HEADER |
| 10 |
|
| 11 |
#include <Teuchos_ConfigDefs.hpp> |
| 12 |
#include <Teuchos_UnitTestHarness.hpp> |
| 13 |
#include <Teuchos_RCP.hpp> |
| 14 |
#include <Teuchos_TimeMonitor.hpp> |
| 15 |
#include "Teuchos_ParameterList.hpp" |
| 16 |
#include "Teuchos_DefaultComm.hpp" |
| 17 |
#include "Tpetra_Core.hpp" |
| 18 |
|
| 19 |
#include "Teuchos_GlobalMPISession.hpp" |
| 20 |
|
| 21 |
#include "Panzer_STK_Interface.hpp" |
| 22 |
#include "Panzer_STK_LocalMeshUtilities.hpp" |
| 23 |
#include "Panzer_NodalFieldPattern.hpp" |
| 24 |
#include "Panzer_EdgeFieldPattern.hpp" |
| 25 |
#include "Panzer_FaceFieldPattern.hpp" |
| 26 |
#include "Panzer_ElemFieldPattern.hpp" |
| 27 |
|
| 28 |
#include "Panzer_LocalMeshInfo.hpp" |
| 29 |
#include "Panzer_STKConnManager.hpp" |
| 30 |
#include "PanzerSTK_UnitTest_BuildMesh.hpp" |
| 31 |
|
| 32 |
#include <string> |
| 33 |
|
| 34 |
namespace panzer_stk { |
| 35 |
|
| 36 |
namespace { |
| 37 |
|
| 38 |
Teuchos::RCP<const panzer::LocalMeshInfo> |
| 39 |
buildParallelLocalMeshInfo(const std::vector<int> & N, // Cells per dimension |
| 40 |
const std::vector<int> & B, // Blocks per dimension |
| 41 |
const std::vector<int> & P, // Processors per dimension |
| 42 |
const std::vector<double> &L, // Domain length per block |
| 43 |
const std::vector<int> periodic_dims) // Periodic dimensions |
| 44 |
{ |
| 45 |
Teuchos::RCP<panzer_stk::STK_Interface> mesh = buildParallelMesh(N,B,P,L,periodic_dims); |
| 46 |
return generateLocalMeshInfo(*mesh); |
| 47 |
} |
| 48 |
|
| 49 |
void |
| 50 |
runConnectivityTest(const std::vector<int> & N, // Cells per dimension |
| 51 |
const std::vector<int> & B, // Blocks per dimension |
| 52 |
const std::vector<int> & P, // Processors per dimension |
| 53 |
const std::vector<double> &L, // Domain length per block |
| 54 |
const std::vector<int> periodic_dims, // Periodic dimensions |
| 55 |
Teuchos::FancyOStream &out, |
| 56 |
bool &success) |
| 57 |
{ |
| 58 |
|
| 59 |
// The point of this test is to make sure that the LocalMeshInfo object connectivity |
| 60 |
// agrees with the ConnManager. |
| 61 |
// Note the ConnManager does not contain all of the connectivity found in the LocalMeshInfo (associated with periodic boundary conditions) |
| 62 |
|
| 63 |
Teuchos::RCP<panzer_stk::STK_Interface> mesh = buildParallelMesh(N, B, P, L, periodic_dims); |
| 64 |
auto mesh_info = generateLocalMeshInfo(*mesh); |
| 65 |
|
| 66 |
auto conn = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 67 |
|
| 68 |
std::vector<shards::CellTopology> topologies; |
| 69 |
conn->getElementBlockTopologies(topologies); |
| 70 |
const auto topology = topologies[0]; |
| 71 |
|
| 72 |
Teuchos::RCP<panzer::FieldPattern> cell_pattern; |
| 73 |
if(topology.getDimension() == 1){ |
| 74 |
cell_pattern = Teuchos::rcp(new panzer::EdgeFieldPattern(topology)); |
| 75 |
} else if(topology.getDimension() == 2){ |
| 76 |
cell_pattern = Teuchos::rcp(new panzer::FaceFieldPattern(topology)); |
| 77 |
} else if(topology.getDimension() == 3){ |
| 78 |
cell_pattern = Teuchos::rcp(new panzer::ElemFieldPattern(topology)); |
| 79 |
} |
| 80 |
conn->buildConnectivity(*cell_pattern); |
| 81 |
|
| 82 |
std::vector<std::string> element_blocks; |
| 83 |
conn->getElementBlockIds(element_blocks); |
| 84 |
|
| 85 |
// TODO: "cell_sets" is an advanced feature that is not yet setup |
| 86 |
|
| 87 |
// // Owned cells |
| 88 |
// for(const auto & element_block : element_blocks){ |
| 89 |
// const auto block_id = mesh_info->cell_sets->getSetIndex(element_block); |
| 90 |
// for(const auto & local_cell_id : conn->getElementBlock(element_block)){ |
| 91 |
// const auto global_cell_id = conn->getConnectivity(local_cell_id)[0]; |
| 92 |
// |
| 93 |
// // Make sure the local mesh info thinks the same thing |
| 94 |
// TEST_EQUALITY(mesh_info->global_cells(local_cell_id), global_cell_id); |
| 95 |
// } |
| 96 |
// } |
| 97 |
// |
| 98 |
// // Whatever ghost cells are in the ConnManager |
| 99 |
// for(const auto & element_block : element_blocks){ |
| 100 |
// const auto block_id = mesh_info->cell_sets->getSetIndex(element_block); |
| 101 |
// for(const auto & local_cell_id : conn->getNeighborElementBlock(element_block)){ |
| 102 |
// const auto global_cell_id = conn->getConnectivity(local_cell_id)[0]; |
| 103 |
// |
| 104 |
// // Make sure the local mesh info thinks the same thing |
| 105 |
// TEST_EQUALITY(mesh_info->global_cells(local_cell_id), global_cell_id); |
| 106 |
// } |
| 107 |
// } |
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 1D_mesh) |
| 113 |
{ |
| 114 |
|
| 115 |
int myRank=0; |
| 116 |
MPI_Comm_rank(MPI_COMM_WORLD, &myRank); |
| 117 |
|
| 118 |
auto mesh_info = buildParallelLocalMeshInfo({3},{2},{2},{2.},{0}); |
| 119 |
|
| 120 |
// Make sure there are two blocks (eblock-0, and eblock-1) |
| 121 |
TEST_EQUALITY(mesh_info->element_blocks.size(), 2); |
| 122 |
TEST_EQUALITY(mesh_info->sidesets.size(), 2); |
| 123 |
|
| 124 |
TEST_ASSERT(mesh_info->has_connectivity); |
| 125 |
// TEST_ASSERT(! mesh_info->cell_sets.is_null()); |
| 126 |
|
| 127 |
if(myRank == 0){ |
| 128 |
|
| 129 |
{ |
| 130 |
const auto & block = mesh_info->element_blocks.at("eblock-0"); |
| 131 |
auto global_cells_h = Kokkos::create_mirror_view(block.global_cells); |
| 132 |
Kokkos::deep_copy(global_cells_h, block.global_cells); |
| 133 |
|
| 134 |
out << "Element Block eblock-0" << std::endl; |
| 135 |
|
| 136 |
TEST_ASSERT(block.num_virtual_cells == 0); |
| 137 |
// TEST_ASSERT(not block.cell_sets.is_null()); |
| 138 |
// TEST_EQUALITY(block.cell_sets->getNumElements(), block.num_owned_cells+block.num_ghstd_cells+block.num_virtual_cells); |
| 139 |
// for(int i=0; i<block.num_owned_cells; ++i){ |
| 140 |
// TEST_EQUALITY(block.cell_sets->getElementSet(i), std::string("eblock-0")); |
| 141 |
// } |
| 142 |
// int num_block_0 = 0, num_block_1 = 0; |
| 143 |
// for(int i=block.num_owned_cells; i<block.num_owned_cells+block.num_ghstd_cells; ++i){ |
| 144 |
// if(block.cell_sets->getElementSet(i) == std::string("eblock-0")) |
| 145 |
// ++num_block_0; |
| 146 |
// else if(block.cell_sets->getElementSet(i) == std::string("eblock-1")) |
| 147 |
// ++num_block_1; |
| 148 |
// } |
| 149 |
// TEST_EQUALITY(num_block_0, 1); |
| 150 |
// TEST_EQUALITY(num_block_1, 1); |
| 151 |
|
| 152 |
// Block should have some basic stuff working |
| 153 |
TEST_EQUALITY(block.num_owned_cells, 2); |
| 154 |
TEST_EQUALITY(block.num_ghstd_cells, 2); |
| 155 |
TEST_EQUALITY(block.num_virtual_cells, 0); |
| 156 |
TEST_EQUALITY((int) global_cells_h(0), 0); |
| 157 |
TEST_EQUALITY((int) global_cells_h(1), 1); |
| 158 |
TEST_EQUALITY((int) global_cells_h(2), 2); |
| 159 |
TEST_EQUALITY((int) global_cells_h(3), 5); |
| 160 |
TEST_ASSERT(block.has_connectivity); |
| 161 |
} |
| 162 |
|
| 163 |
{ |
| 164 |
const auto & block = mesh_info->element_blocks.at("eblock-1"); |
| 165 |
auto global_cells_h = Kokkos::create_mirror_view(block.global_cells); |
| 166 |
Kokkos::deep_copy(global_cells_h, block.global_cells); |
| 167 |
|
| 168 |
out << "Element Block eblock-1" << std::endl; |
| 169 |
|
| 170 |
TEST_ASSERT(block.num_virtual_cells == 0); |
| 171 |
// TEST_ASSERT(not block.cell_sets.is_null()); |
| 172 |
// TEST_EQUALITY(block.cell_sets->getNumElements(), block.num_owned_cells+block.num_ghstd_cells+block.num_virtual_cells); |
| 173 |
// for(int i=0; i<block.num_owned_cells; ++i){ |
| 174 |
// TEST_EQUALITY(block.cell_sets->getElementSet(i), std::string("eblock-1")); |
| 175 |
// } |
| 176 |
// int num_block_0 = 0, num_block_1 = 0; |
| 177 |
// for(int i=block.num_owned_cells; i<block.num_owned_cells+block.num_ghstd_cells; ++i){ |
| 178 |
// if(block.cell_sets->getElementSet(i) == std::string("eblock-0")) |
| 179 |
// ++num_block_0; |
| 180 |
// else if(block.cell_sets->getElementSet(i) == std::string("eblock-1")) |
| 181 |
// ++num_block_1; |
| 182 |
// } |
| 183 |
// TEST_EQUALITY(num_block_0, 1); |
| 184 |
// TEST_EQUALITY(num_block_1, 1); |
| 185 |
|
| 186 |
// Block should be empty |
| 187 |
TEST_EQUALITY(block.num_owned_cells, 2); |
| 188 |
TEST_EQUALITY(block.num_ghstd_cells, 2); |
| 189 |
TEST_EQUALITY(block.num_virtual_cells, 0); |
| 190 |
TEST_EQUALITY((int) global_cells_h(0), 3); |
| 191 |
TEST_EQUALITY((int) global_cells_h(1), 4); |
| 192 |
TEST_EQUALITY((int) global_cells_h(2), 5); |
| 193 |
TEST_EQUALITY((int) global_cells_h(3), 2); |
| 194 |
TEST_ASSERT(block.has_connectivity); |
| 195 |
} |
| 196 |
|
| 197 |
{ |
| 198 |
const auto & block = mesh_info->sidesets.at("eblock-0").at("left"); |
| 199 |
auto global_cells_h = Kokkos::create_mirror_view(block.global_cells); |
| 200 |
Kokkos::deep_copy(global_cells_h, block.global_cells); |
| 201 |
|
| 202 |
out << "Sideset eblock-0 left" << std::endl; |
| 203 |
|
| 204 |
TEST_ASSERT(block.num_virtual_cells == 0); |
| 205 |
// TEST_ASSERT(not block.cell_sets.is_null()); |
| 206 |
// TEST_EQUALITY(block.cell_sets->getNumElements(), block.num_owned_cells+block.num_ghstd_cells+block.num_virtual_cells); |
| 207 |
// TEST_EQUALITY(block.cell_sets->getElementSet(0), std::string("eblock-0")); |
| 208 |
// TEST_EQUALITY(block.cell_sets->getElementSet(1), std::string("eblock-1")); |
| 209 |
|
| 210 |
// Block should have some basic stuff working |
| 211 |
TEST_EQUALITY(block.num_owned_cells, 1); |
| 212 |
TEST_EQUALITY(block.num_ghstd_cells, 1); |
| 213 |
TEST_EQUALITY(block.num_virtual_cells, 0); |
| 214 |
TEST_EQUALITY((int) global_cells_h(0), 0); |
| 215 |
TEST_EQUALITY((int) global_cells_h(1), 5); |
| 216 |
TEST_ASSERT(block.has_connectivity); |
| 217 |
} |
| 218 |
|
| 219 |
// TEUCHOS_ASSERT(mesh_info->sidesets.find("eblock-1") == mesh_info->sidesets.end()); |
| 220 |
|
| 221 |
} else { |
| 222 |
{ |
| 223 |
const auto & block = mesh_info->element_blocks.at("eblock-0"); |
| 224 |
auto global_cells_h = Kokkos::create_mirror_view(block.global_cells); |
| 225 |
Kokkos::deep_copy(global_cells_h, block.global_cells); |
| 226 |
|
| 227 |
out << "Element Block eblock-0" << std::endl; |
| 228 |
|
| 229 |
TEST_ASSERT(block.num_virtual_cells == 0); |
| 230 |
// TEST_ASSERT(not block.cell_sets.is_null()); |
| 231 |
// TEST_EQUALITY(block.cell_sets->getNumElements(), block.num_owned_cells+block.num_ghstd_cells+block.num_virtual_cells); |
| 232 |
// for(int i=0; i<block.num_owned_cells; ++i){ |
| 233 |
// TEST_EQUALITY(block.cell_sets->getElementSet(i), std::string("eblock-0")); |
| 234 |
// } |
| 235 |
// int num_block_0 = 0, num_block_1 = 0; |
| 236 |
// for(int i=block.num_owned_cells; i<block.num_owned_cells+block.num_ghstd_cells; ++i){ |
| 237 |
// if(block.cell_sets->getElementSet(i) == std::string("eblock-0")) |
| 238 |
// ++num_block_0; |
| 239 |
// else if(block.cell_sets->getElementSet(i) == std::string("eblock-1")) |
| 240 |
// ++num_block_1; |
| 241 |
// } |
| 242 |
// TEST_EQUALITY(num_block_0, 1); |
| 243 |
// TEST_EQUALITY(num_block_1, 1); |
| 244 |
|
| 245 |
// Block should have some basic stuff working |
| 246 |
TEST_EQUALITY(block.num_owned_cells, 1); |
| 247 |
TEST_EQUALITY(block.num_ghstd_cells, 2); |
| 248 |
TEST_EQUALITY(block.num_virtual_cells, 0); |
| 249 |
TEST_EQUALITY((int) global_cells_h(0), 2); |
| 250 |
TEST_EQUALITY((int) global_cells_h(1), 3); |
| 251 |
TEST_EQUALITY((int) global_cells_h(2), 1); |
| 252 |
TEST_ASSERT(block.has_connectivity); |
| 253 |
} |
| 254 |
|
| 255 |
{ |
| 256 |
const auto & block = mesh_info->element_blocks.at("eblock-1"); |
| 257 |
auto global_cells_h = Kokkos::create_mirror_view(block.global_cells); |
| 258 |
Kokkos::deep_copy(global_cells_h, block.global_cells); |
| 259 |
|
| 260 |
out << "Element Block eblock-1" << std::endl; |
| 261 |
|
| 262 |
TEST_ASSERT(block.num_virtual_cells == 0); |
| 263 |
// TEST_ASSERT(not block.cell_sets.is_null()); |
| 264 |
// TEST_EQUALITY(block.cell_sets->getNumElements(), block.num_owned_cells+block.num_ghstd_cells+block.num_virtual_cells); |
| 265 |
// for(int i=0; i<block.num_owned_cells; ++i){ |
| 266 |
// TEST_EQUALITY(block.cell_sets->getElementSet(i), std::string("eblock-1")); |
| 267 |
// } |
| 268 |
// int num_block_0 = 0, num_block_1 = 0; |
| 269 |
// for(int i=block.num_owned_cells; i<block.num_owned_cells+block.num_ghstd_cells; ++i){ |
| 270 |
// if(block.cell_sets->getElementSet(i) == std::string("eblock-0")) |
| 271 |
// ++num_block_0; |
| 272 |
// else if(block.cell_sets->getElementSet(i) == std::string("eblock-1")) |
| 273 |
// ++num_block_1; |
| 274 |
// } |
| 275 |
// TEST_EQUALITY(num_block_0, 1); |
| 276 |
// TEST_EQUALITY(num_block_1, 1); |
| 277 |
|
| 278 |
// Block should be empty |
| 279 |
TEST_EQUALITY(block.num_owned_cells, 1); |
| 280 |
TEST_EQUALITY(block.num_ghstd_cells, 2); |
| 281 |
TEST_EQUALITY(block.num_virtual_cells, 0); |
| 282 |
TEST_EQUALITY((int) global_cells_h(0), 5); |
| 283 |
TEST_EQUALITY((int) global_cells_h(1), 0); |
| 284 |
TEST_EQUALITY((int) global_cells_h(2), 4); |
| 285 |
TEST_ASSERT(block.has_connectivity); |
| 286 |
} |
| 287 |
|
| 288 |
// TEUCHOS_ASSERT(mesh_info->sidesets.find("eblock-0") == mesh_info->sidesets.end()); |
| 289 |
|
| 290 |
{ |
| 291 |
const auto & block = mesh_info->sidesets.at("eblock-1").at("right"); |
| 292 |
auto global_cells_h = Kokkos::create_mirror_view(block.global_cells); |
| 293 |
Kokkos::deep_copy(global_cells_h, block.global_cells); |
| 294 |
|
| 295 |
out << "Sideset eblock-1 right" << std::endl; |
| 296 |
|
| 297 |
TEST_ASSERT(block.num_virtual_cells == 0); |
| 298 |
// TEST_ASSERT(not block.cell_sets.is_null()); |
| 299 |
// TEST_EQUALITY(block.cell_sets->getNumElements(), block.num_owned_cells+block.num_ghstd_cells+block.num_virtual_cells); |
| 300 |
// TEST_EQUALITY(block.cell_sets->getElementSet(0), std::string("eblock-1")); |
| 301 |
// TEST_EQUALITY(block.cell_sets->getElementSet(1), std::string("eblock-0")); |
| 302 |
|
| 303 |
// Block should have some basic stuff working |
| 304 |
TEST_EQUALITY(block.num_owned_cells, 1); |
| 305 |
TEST_EQUALITY(block.num_ghstd_cells, 1); |
| 306 |
TEST_EQUALITY(block.num_virtual_cells, 0); |
| 307 |
TEST_EQUALITY((int) global_cells_h(0), 5); |
| 308 |
TEST_EQUALITY((int) global_cells_h(1), 0); |
| 309 |
TEST_ASSERT(block.has_connectivity); |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
} |
| 314 |
|
| 315 |
// 1D |
| 316 |
|
| 317 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 1D_connectivity_bc) |
| 318 |
{ |
| 319 |
runConnectivityTest({3},{2},{2},{1.},{},out,success); |
| 320 |
} |
| 321 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 1D_connectivity_bc0) |
| 322 |
{ |
| 323 |
runConnectivityTest({3},{2},{2},{1.},{0},out,success); |
| 324 |
} |
| 325 |
|
| 326 |
// 2D |
| 327 |
|
| 328 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 2D_connectivity_bc) |
| 329 |
{ |
| 330 |
runConnectivityTest({3,3},{2,1},{2,1},{1.,1.},{},out,success); |
| 331 |
} |
| 332 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 2D_connectivity_bc0) |
| 333 |
{ |
| 334 |
runConnectivityTest({3,3},{2,1},{2,1},{1.,1.},{0},out,success); |
| 335 |
} |
| 336 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 2D_connectivity_bc1) |
| 337 |
{ |
| 338 |
runConnectivityTest({3,3},{2,1},{2,1},{1.,1.},{1},out,success); |
| 339 |
} |
| 340 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 2D_connectivity_bc01) |
| 341 |
{ |
| 342 |
runConnectivityTest({3,3},{2,1},{2,1},{1.,1.},{0,1},out,success); |
| 343 |
} |
| 344 |
|
| 345 |
// 3D - not all combinations are tested |
| 346 |
|
| 347 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 3D_connectivity_bc) |
| 348 |
{ |
| 349 |
runConnectivityTest({3,3,2},{2,1,1},{2,1,1},{1.,1.,1.},{},out,success); |
| 350 |
} |
| 351 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 3D_connectivity_bc0) |
| 352 |
{ |
| 353 |
runConnectivityTest({3,3,2},{2,1,1},{2,1,1},{1.,1.,1.},{0},out,success); |
| 354 |
} |
| 355 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 3D_connectivity_bc1) |
| 356 |
{ |
| 357 |
runConnectivityTest({3,3,2},{2,1,1},{2,1,1},{1.,1.,1.},{1},out,success); |
| 358 |
} |
| 359 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 3D_connectivity_bc2) |
| 360 |
{ |
| 361 |
runConnectivityTest({3,3,2},{2,1,1},{2,1,1},{1.,1.,1.},{2},out,success); |
| 362 |
} |
| 363 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 3D_connectivity_bc01) |
| 364 |
{ |
| 365 |
runConnectivityTest({3,3,2},{2,1,1},{2,1,1},{1.,1.,1.},{0,1},out,success); |
| 366 |
} |
| 367 |
TEUCHOS_UNIT_TEST(parallelPeriodicLocalMeshUtilities, 3D_connectivity_bc012) |
| 368 |
{ |
| 369 |
runConnectivityTest({3,3,2},{2,1,1},{2,1,1},{1.,1.,1.},{0,1,2},out,success); |
| 370 |
} |
| 371 |
|
| 372 |
} |