| 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 |
|
| 16 |
#include "PanzerCore_config.hpp" |
| 17 |
|
| 18 |
#include "Panzer_WorksetDescriptor.hpp" |
| 19 |
|
| 20 |
#include "Panzer_LocalMeshInfo.hpp" |
| 21 |
#include "Panzer_LocalPartitioningUtilities.hpp" |
| 22 |
|
| 23 |
#include "Panzer_UnitTest_LocalMeshUtilities.hpp" |
| 24 |
|
| 25 |
#include <vector> |
| 26 |
#include <string> |
| 27 |
#include <iostream> |
| 28 |
|
| 29 |
namespace panzer { |
| 30 |
|
| 31 |
TEUCHOS_UNIT_TEST(localMeshPartitioningUtilities, basic) |
| 32 |
{ |
| 33 |
|
| 34 |
// Test empty mesh |
| 35 |
{ |
| 36 |
panzer::LocalMeshInfo empty_mesh; |
| 37 |
|
| 38 |
panzer::WorksetDescriptor description("block",panzer::WorksetSizeType::ALL_ELEMENTS,true); |
| 39 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 40 |
|
| 41 |
// It should not return any partitions |
| 42 |
generateLocalMeshPartitions(empty_mesh, description, partitions); |
| 43 |
|
| 44 |
// Nothing should have been found |
| 45 |
TEST_EQUALITY(partitions.size(), 0); |
| 46 |
} |
| 47 |
|
| 48 |
// Generate a local mesh info object |
| 49 |
Teuchos::RCP<panzer::LocalMeshInfo> mesh_info = generateLocalMeshInfo(); |
| 50 |
|
| 51 |
// Test bad descriptors |
| 52 |
{ |
| 53 |
panzer::WorksetDescriptor description("block0",panzer::WorksetSizeType::CLASSIC_MODE,true); |
| 54 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 55 |
|
| 56 |
// It should throw an error |
| 57 |
TEST_THROW(generateLocalMeshPartitions(*mesh_info, description, partitions), std::logic_error); |
| 58 |
} |
| 59 |
{ |
| 60 |
panzer::WorksetDescriptor description("block0",panzer::WorksetSizeType::NO_ELEMENTS,true); |
| 61 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 62 |
|
| 63 |
// It should throw an error |
| 64 |
TEST_THROW(generateLocalMeshPartitions(*mesh_info, description, partitions), std::logic_error); |
| 65 |
} |
| 66 |
{ |
| 67 |
panzer::WorksetDescriptor description("block0",panzer::WorksetSizeType::ALL_ELEMENTS,false); |
| 68 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 69 |
|
| 70 |
// It should throw an error |
| 71 |
TEST_THROW(generateLocalMeshPartitions(*mesh_info, description, partitions), std::logic_error); |
| 72 |
} |
| 73 |
|
| 74 |
// Test the partitions |
| 75 |
|
| 76 |
// Non-existant block partition |
| 77 |
{ |
| 78 |
panzer::WorksetDescriptor description("block32",panzer::WorksetSizeType::ALL_ELEMENTS,true); |
| 79 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 80 |
|
| 81 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 82 |
|
| 83 |
// Nothing should have been found |
| 84 |
TEST_EQUALITY(partitions.size(), 0); |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
// Non-existant sideset partition |
| 89 |
{ |
| 90 |
panzer::WorksetDescriptor description("block32","sideset0",panzer::WorksetSizeType::ALL_ELEMENTS,true); |
| 91 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 92 |
|
| 93 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 94 |
|
| 95 |
// Nothing should have been found |
| 96 |
TEST_EQUALITY(partitions.size(), 0); |
| 97 |
|
| 98 |
} |
| 99 |
{ |
| 100 |
panzer::WorksetDescriptor description("block0","sideset32",panzer::WorksetSizeType::ALL_ELEMENTS,true); |
| 101 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 102 |
|
| 103 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 104 |
|
| 105 |
// Nothing should have been found |
| 106 |
TEST_EQUALITY(partitions.size(), 0); |
| 107 |
|
| 108 |
} |
| 109 |
{ |
| 110 |
panzer::WorksetDescriptor description("block0","sideset1",panzer::WorksetSizeType::ALL_ELEMENTS,true); |
| 111 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 112 |
|
| 113 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 114 |
|
| 115 |
// Nothing should have been found |
| 116 |
TEST_EQUALITY(partitions.size(), 0); |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
// Existing block partition |
| 121 |
{ |
| 122 |
panzer::WorksetDescriptor description("block0",panzer::WorksetSizeType::ALL_ELEMENTS,true); |
| 123 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 124 |
|
| 125 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 126 |
|
| 127 |
// Only one partition since we requested a full partition |
| 128 |
TEST_EQUALITY(partitions.size(), 1); |
| 129 |
|
| 130 |
const auto & partition = partitions[0]; |
| 131 |
TEST_EQUALITY(partition.num_owned_cells,2); |
| 132 |
TEST_EQUALITY(partition.num_ghstd_cells,1); |
| 133 |
TEST_EQUALITY(partition.num_virtual_cells,1); |
| 134 |
} |
| 135 |
|
| 136 |
// Existing sideset partition |
| 137 |
{ |
| 138 |
panzer::WorksetDescriptor description("block0","sideset0",panzer::WorksetSizeType::ALL_ELEMENTS,true); |
| 139 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 140 |
|
| 141 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 142 |
|
| 143 |
// Only one partition since we requested a full partition |
| 144 |
TEST_EQUALITY(partitions.size(), 1); |
| 145 |
|
| 146 |
const auto & partition = partitions[0]; |
| 147 |
TEST_EQUALITY(partition.num_owned_cells,1); |
| 148 |
TEST_EQUALITY(partition.num_ghstd_cells,0); |
| 149 |
TEST_EQUALITY(partition.num_virtual_cells,1); |
| 150 |
} |
| 151 |
{ |
| 152 |
panzer::WorksetDescriptor description("block1","sideset2",panzer::WorksetSizeType::ALL_ELEMENTS,true); |
| 153 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 154 |
|
| 155 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 156 |
|
| 157 |
// Only one partition since we requested a full partition |
| 158 |
TEST_EQUALITY(partitions.size(), 1); |
| 159 |
|
| 160 |
const auto & partition = partitions[0]; |
| 161 |
TEST_EQUALITY(partition.num_owned_cells,1); |
| 162 |
TEST_EQUALITY(partition.num_ghstd_cells,1); |
| 163 |
TEST_EQUALITY(partition.num_virtual_cells,0); |
| 164 |
} |
| 165 |
|
| 166 |
// Existing block double partition |
| 167 |
{ |
| 168 |
// We want two partitions, each with a size of 1 cell |
| 169 |
panzer::WorksetDescriptor description("block1",1,true); |
| 170 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 171 |
|
| 172 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 173 |
|
| 174 |
// Two partitions |
| 175 |
TEST_EQUALITY(partitions.size(), 2); |
| 176 |
|
| 177 |
{ |
| 178 |
const auto & partition = partitions[0]; |
| 179 |
TEST_EQUALITY(partition.num_owned_cells,1); |
| 180 |
|
| 181 |
// Either both extra cells are ghosts, or one is virtual and one is ghost |
| 182 |
TEST_EQUALITY(partition.num_ghstd_cells+partition.num_virtual_cells,2); |
| 183 |
} |
| 184 |
|
| 185 |
{ |
| 186 |
const auto & partition = partitions[1]; |
| 187 |
TEST_EQUALITY(partition.num_owned_cells,1); |
| 188 |
|
| 189 |
// Either both extra cells are ghosts, or one is virtual and one is ghost |
| 190 |
TEST_EQUALITY(partition.num_ghstd_cells+partition.num_virtual_cells,2); |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
// Existing sideset double partition, but only one partition is available |
| 195 |
{ |
| 196 |
// We want two partitions, each with a size of 1 cell |
| 197 |
panzer::WorksetDescriptor description("block1","sideset1",1,true); |
| 198 |
std::vector<panzer::LocalMeshPartition> partitions; |
| 199 |
|
| 200 |
generateLocalMeshPartitions(*mesh_info, description, partitions); |
| 201 |
|
| 202 |
// Only one partition should have been built |
| 203 |
TEST_EQUALITY(partitions.size(), 1); |
| 204 |
|
| 205 |
{ |
| 206 |
const auto & partition = partitions[0]; |
| 207 |
TEST_EQUALITY(partition.num_owned_cells,1); |
| 208 |
TEST_EQUALITY(partition.num_ghstd_cells,0); |
| 209 |
TEST_EQUALITY(partition.num_virtual_cells,1); |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
} |
| 214 |
|
| 215 |
} // end namespace panzer |