| 1 |
#include "gtest/gtest.h" // for AssertHelper, EXPECT_EQ, etc |
| 2 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 3 |
#include <stk_mesh/base/DestroyRelations.hpp> |
| 4 |
#include <stk_mesh/base/GetEntities.hpp> // for count_selected_entities |
| 5 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 6 |
#include <stk_unit_test_utils/getOption.h> |
| 7 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 8 |
#include <stk_unit_test_utils/PerformanceTester.hpp> |
| 9 |
#include <stk_unit_test_utils/ioUtils.hpp> |
| 10 |
#include <stk_util/environment/memory_util.hpp> |
| 11 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp> |
| 12 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraphUpdater.hpp> |
| 13 |
#include <tokenize.h> // for tokenize |
| 14 |
#include <cmath> // for atan2, cos, sin |
| 15 |
#include <cstdlib> // for strtod, nullptr, strtol, exit, etc |
| 16 |
#include <cstring> // for memcpy |
| 17 |
#include <iomanip> // for operator<<, setw |
| 18 |
#include <iostream> // for operator<<, basic_ostream, etc |
| 19 |
#include <string> // for string, operator==, etc |
| 20 |
#include <vector> |
| 21 |
#include <Ioss_EntityType.h> // for EntityType, etc |
| 22 |
#include <stk_mesh/base/Field.hpp> // for Field |
| 23 |
#include <stddef.h> // for size_t |
| 24 |
#include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker |
| 25 |
|
| 26 |
namespace |
| 27 |
{ |
| 28 |
|
| 29 |
std::string get_file_name(const std::string ¶meters) |
| 30 |
{ |
| 31 |
std::string filename = parameters; |
| 32 |
size_t colon = filename.find(':'); |
| 33 |
if (colon != std::string::npos && colon > 0) { |
| 34 |
filename = filename.substr(colon+1); |
| 35 |
} |
| 36 |
|
| 37 |
return filename; |
| 38 |
} |
| 39 |
|
| 40 |
void get_mesh_dimensions(const std::string ¶meters, int &numX, int &numY, int &numZ) |
| 41 |
{ |
| 42 |
std::string filename = get_file_name(parameters); |
| 43 |
|
| 44 |
auto params = Ioss::tokenize(filename, "/"); |
| 45 |
auto groups = Ioss::tokenize(params[params.size()-1], "|+"); |
| 46 |
|
| 47 |
// First 'group' is the interval specification -- IxJxK |
| 48 |
auto tokens = Ioss::tokenize(groups[0], "x"); |
| 49 |
assert(tokens.size() == 3); |
| 50 |
|
| 51 |
numX = std::strtol(tokens[0].c_str(), nullptr, 10); |
| 52 |
numY = std::strtol(tokens[1].c_str(), nullptr, 10); |
| 53 |
numZ = std::strtol(tokens[2].c_str(), nullptr, 10); |
| 54 |
} |
| 55 |
|
| 56 |
struct DeletedMeshInfo |
| 57 |
{ |
| 58 |
std::vector<stk::mesh::EntityId> elemIds; |
| 59 |
std::vector< std::vector<stk::mesh::Entity> > elemNodes; |
| 60 |
}; |
| 61 |
|
| 62 |
struct NodeConnectivityInfo |
| 63 |
{ |
| 64 |
std::map<stk::mesh::Entity, int> nodeConnMap; |
| 65 |
std::vector<int> nodeConn; |
| 66 |
}; |
| 67 |
|
| 68 |
typedef stk::mesh::Field<int> ScalarIntField; |
| 69 |
|
| 70 |
class AnimateMeshDeletion |
| 71 |
{ |
| 72 |
public: |
| 73 |
AnimateMeshDeletion(stk::mesh::BulkData &bulk, ScalarIntField &statusField, const std::string &animationFileName) : |
| 74 |
m_bulkData(bulk), |
| 75 |
m_stkIo(bulk.parallel()), |
| 76 |
m_fileHandler(0), |
| 77 |
m_statusField(statusField), |
| 78 |
m_animationFileName(animationFileName) |
| 79 |
{ |
| 80 |
initialize_status_field(); |
| 81 |
create_output_mesh(); |
| 82 |
} |
| 83 |
|
| 84 |
~AnimateMeshDeletion() {} |
| 85 |
|
| 86 |
void initialize_status_field() |
| 87 |
{ |
| 88 |
stk::mesh::put_field_on_mesh(m_statusField, m_bulkData.mesh_meta_data().universal_part(), nullptr); |
| 89 |
} |
| 90 |
|
| 91 |
void create_output_mesh() |
| 92 |
{ |
| 93 |
m_stkIo.set_bulk_data(m_bulkData); |
| 94 |
m_fileHandler = m_stkIo.create_output_mesh(m_animationFileName, stk::io::WRITE_RESULTS); |
| 95 |
m_stkIo.add_field(m_fileHandler, m_statusField); |
| 96 |
m_stkIo.write_output_mesh(m_fileHandler); |
| 97 |
} |
| 98 |
|
| 99 |
void deactivate_element(stk::mesh::EntityId elemId) |
| 100 |
{ |
| 101 |
stk::mesh::Entity elem = m_bulkData.get_entity(stk::topology::ELEM_RANK, elemId); |
| 102 |
*stk::mesh::field_data(m_statusField, elem) = 1; |
| 103 |
} |
| 104 |
|
| 105 |
void animate(const std::vector<stk::mesh::EntityId> elemIds, int numSteps) |
| 106 |
{ |
| 107 |
initialize_status_field(); |
| 108 |
|
| 109 |
int numElem = elemIds.size(); |
| 110 |
|
| 111 |
for (int m_time = 0; m_time <= numSteps; m_time++) |
| 112 |
{ |
| 113 |
if((0 != m_time) && (m_time <= numElem)) |
| 114 |
{ |
| 115 |
stk::mesh::EntityId elemId = elemIds[m_time-1]; |
| 116 |
deactivate_element(elemId); |
| 117 |
} |
| 118 |
|
| 119 |
m_stkIo.begin_output_step(m_fileHandler, m_time); |
| 120 |
m_stkIo.write_defined_output_fields(m_fileHandler); |
| 121 |
m_stkIo.end_output_step(m_fileHandler); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
private: |
| 126 |
stk::mesh::BulkData &m_bulkData; |
| 127 |
stk::io::StkMeshIoBroker m_stkIo; |
| 128 |
size_t m_fileHandler; |
| 129 |
ScalarIntField &m_statusField; |
| 130 |
std::string m_animationFileName; |
| 131 |
}; |
| 132 |
|
| 133 |
void declare_animation_field(stk::mesh::MetaData &metaData, std::string &animationFile) |
| 134 |
{ |
| 135 |
animationFile = stk::unit_test_util::get_option("-animationFile", ""); |
| 136 |
|
| 137 |
if("" != animationFile) |
| 138 |
{ |
| 139 |
ScalarIntField &deathField = metaData.declare_field<int>(stk::topology::ELEMENT_RANK, "death"); |
| 140 |
stk::mesh::put_field_on_mesh(deathField, metaData.universal_part(), nullptr); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
void animate_death(stk::mesh::BulkData &bulkData, const std::vector<stk::mesh::EntityId> elemIds, const std::string &animationFile = "") |
| 145 |
{ |
| 146 |
if("" != animationFile) |
| 147 |
{ |
| 148 |
int numSteps, numElem = elemIds.size(); |
| 149 |
|
| 150 |
stk::all_reduce_max(bulkData.parallel(), &numElem, &numSteps, 1); |
| 151 |
|
| 152 |
ScalarIntField &deathField = static_cast<ScalarIntField &> (*bulkData.mesh_meta_data().get_field(stk::topology::ELEM_RANK, "death")); |
| 153 |
AnimateMeshDeletion deathAnimation(bulkData, deathField, animationFile); |
| 154 |
|
| 155 |
deathAnimation.animate(elemIds, numSteps); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
void print_delete_info(const stk::mesh::BulkData &bulkData, DeletedMeshInfo &meshInfo) |
| 160 |
{ |
| 161 |
int data[2]; |
| 162 |
int data_sum[2], data_min, data_max; |
| 163 |
|
| 164 |
data[0] = meshInfo.elemIds.size(); |
| 165 |
data[1] = stk::mesh::count_selected_entities(bulkData.mesh_meta_data().locally_owned_part(), bulkData.buckets(stk::topology::ELEM_RANK)); // localElems.size(); |
| 166 |
|
| 167 |
stk::all_reduce_sum(bulkData.parallel(), data, data_sum, 2); |
| 168 |
stk::all_reduce_min(bulkData.parallel(), data, &data_min, 1); |
| 169 |
stk::all_reduce_max(bulkData.parallel(), data, &data_max, 1); |
| 170 |
|
| 171 |
if(0 == bulkData.parallel_rank()) |
| 172 |
{ |
| 173 |
double del_sum = (100.0*data_sum[0])/data_sum[1]; |
| 174 |
std::cout << "[Delete Elements] " << data_sum[0] << " elements (" << del_sum << " % of mesh) Min : " << data_min << " Max: " << data_max << std::endl; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
void print_skin_info(const stk::mesh::BulkData &bulkData, const stk::mesh::Part& surface) |
| 179 |
{ |
| 180 |
stk::mesh::Selector selector(surface & bulkData.mesh_meta_data().locally_owned_part()); |
| 181 |
std::vector<size_t> skin_count; |
| 182 |
stk::mesh::count_entities(selector, bulkData, skin_count); |
| 183 |
int minFaces, maxFaces, sumFaces, localFaces = skin_count[2]; |
| 184 |
stk::all_reduce_min(bulkData.parallel(), &localFaces, &minFaces, 1); |
| 185 |
stk::all_reduce_max(bulkData.parallel(), &localFaces, &maxFaces, 1); |
| 186 |
stk::all_reduce_sum(bulkData.parallel(), &localFaces, &sumFaces, 1); |
| 187 |
|
| 188 |
if(bulkData.parallel_rank() == 0) |
| 189 |
{ |
| 190 |
std::cout << "[Skinning] Min faces: " << minFaces << " Max faces: " << maxFaces << " Total faces: " << sumFaces << std::endl; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
void print_memory(stk::ParallelMachine communicator, const std::string &preamble) |
| 195 |
{ |
| 196 |
double maxHwmInMB = stk::get_max_hwm_across_procs(communicator) / (1024.0 * 1024.0); |
| 197 |
|
| 198 |
size_t curr_max, curr_min, curr_avg; |
| 199 |
stk::get_current_memory_usage_across_processors(communicator, curr_max, curr_min, curr_avg); |
| 200 |
double max = curr_max / (1024.0 * 1024.0); |
| 201 |
curr_min /= (1024.0 * 1024.0); |
| 202 |
curr_avg /= (1024.0 * 1024.0); |
| 203 |
|
| 204 |
if(stk::parallel_machine_rank(communicator) == 0) |
| 205 |
{ |
| 206 |
std::ostringstream os; |
| 207 |
os << preamble << " high water mark = " << maxHwmInMB << " Mb, current max = " << max << " Mb" << std::endl; |
| 208 |
std::cerr << os.str(); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
void get_ids_along_boundary(const stk::mesh::BulkData &bulkData, const std::string &meshSpec, DeletedMeshInfo &meshInfo) |
| 214 |
{ |
| 215 |
int nx, ny, nz; |
| 216 |
|
| 217 |
get_mesh_dimensions(meshSpec, nx, ny, nz); |
| 218 |
|
| 219 |
meshInfo.elemIds.resize(ny*nz); |
| 220 |
|
| 221 |
int count = 0; |
| 222 |
|
| 223 |
for(int z = 0; z < nz; ++z) |
| 224 |
{ |
| 225 |
for(int y = 0; y < ny; ++y) |
| 226 |
{ |
| 227 |
if((y%2 == 0) || ((ny-1) == y)) continue; |
| 228 |
|
| 229 |
int id = 1 + nx*(y + ny*z); |
| 230 |
|
| 231 |
stk::mesh::EntityId elemId = static_cast<stk::mesh::EntityId> (id); |
| 232 |
stk::mesh::Entity elem = bulkData.get_entity(stk::topology::ELEM_RANK, elemId); |
| 233 |
|
| 234 |
if(bulkData.is_valid(elem) && bulkData.bucket(elem).owned()) |
| 235 |
{ |
| 236 |
meshInfo.elemIds[count] = static_cast<stk::mesh::EntityId> (id); |
| 237 |
++count; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
meshInfo.elemIds.resize(count); |
| 243 |
|
| 244 |
print_delete_info(bulkData, meshInfo); |
| 245 |
} |
| 246 |
|
| 247 |
bool is_element_on_processor_boundary(const stk::mesh::ElemElemGraph& eeGraph, stk::mesh::Entity localElement) |
| 248 |
{ |
| 249 |
size_t numConn = eeGraph.get_num_connected_elems(localElement); |
| 250 |
|
| 251 |
bool onProcBoundary = false; |
| 252 |
for(size_t i=0; i<numConn; ++i) |
| 253 |
{ |
| 254 |
if(!eeGraph.is_connected_elem_locally_owned(localElement, i)) |
| 255 |
onProcBoundary = true; |
| 256 |
} |
| 257 |
return onProcBoundary; |
| 258 |
} |
| 259 |
|
| 260 |
bool will_deleting_element_create_orphaned_nodes(const stk::mesh::BulkData &bulkData, |
| 261 |
stk::mesh::Entity localElement, |
| 262 |
const NodeConnectivityInfo &nodeConnInfo) |
| 263 |
{ |
| 264 |
const stk::mesh::ConnectedEntities nodes = bulkData.get_connected_entities(localElement, stk::topology::NODE_RANK); |
| 265 |
const unsigned numNodes = nodes.size(); |
| 266 |
|
| 267 |
for(unsigned i=0; i<numNodes; ++i) |
| 268 |
{ |
| 269 |
stk::mesh::Entity node = nodes[i]; |
| 270 |
int index = -1; |
| 271 |
std::map<stk::mesh::Entity, int>::const_iterator it = nodeConnInfo.nodeConnMap.find(node); |
| 272 |
|
| 273 |
if(nodeConnInfo.nodeConnMap.end() != it) |
| 274 |
index = it->second; |
| 275 |
|
| 276 |
if((-1 != index) && (nodeConnInfo.nodeConn[index] <= 1)) |
| 277 |
return true; |
| 278 |
} |
| 279 |
|
| 280 |
return false; |
| 281 |
} |
| 282 |
|
| 283 |
void decrement_node_connectivity(const stk::mesh::BulkData &bulkData, |
| 284 |
stk::mesh::Entity localElement, |
| 285 |
NodeConnectivityInfo &nodeConnInfo) |
| 286 |
{ |
| 287 |
const stk::mesh::ConnectedEntities nodes = bulkData.get_connected_entities(localElement, stk::topology::NODE_RANK); |
| 288 |
const unsigned numNodes = nodes.size(); |
| 289 |
|
| 290 |
for(unsigned i=0; i<numNodes; ++i) |
| 291 |
{ |
| 292 |
stk::mesh::Entity node = nodes[i]; |
| 293 |
|
| 294 |
int index = nodeConnInfo.nodeConnMap[node]; |
| 295 |
nodeConnInfo.nodeConn[index]--; |
| 296 |
|
| 297 |
EXPECT_TRUE( nodeConnInfo.nodeConn[index] > 0); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
int num_local_elements(const stk::mesh::BulkData &bulkData, stk::mesh::Entity node) |
| 302 |
{ |
| 303 |
const stk::mesh::ConnectedEntities elements = bulkData.get_connected_entities(node, stk::topology::ELEM_RANK); |
| 304 |
int numElems = elements.size(); |
| 305 |
int numLocalElems = numElems; |
| 306 |
|
| 307 |
for(int i=0; i<numElems; ++i) |
| 308 |
{ |
| 309 |
stk::mesh::Entity elem = elements[i]; |
| 310 |
if(!bulkData.bucket(elem).owned()) |
| 311 |
numLocalElems--; |
| 312 |
} |
| 313 |
|
| 314 |
return numLocalElems; |
| 315 |
} |
| 316 |
|
| 317 |
void initialize_node_connectivity_map(const stk::mesh::BulkData &bulkData, |
| 318 |
NodeConnectivityInfo &nodeConnInfo) |
| 319 |
{ |
| 320 |
stk::mesh::EntityVector allNodes; |
| 321 |
stk::mesh::get_selected_entities(bulkData.mesh_meta_data().universal_part(), bulkData.buckets(stk::topology::NODE_RANK), allNodes); |
| 322 |
|
| 323 |
nodeConnInfo.nodeConn.resize(allNodes.size()); |
| 324 |
|
| 325 |
for(unsigned i=0; i<allNodes.size(); ++i) |
| 326 |
{ |
| 327 |
stk::mesh::Entity node = allNodes[i]; |
| 328 |
nodeConnInfo.nodeConnMap[node] = i; |
| 329 |
nodeConnInfo.nodeConn[i] = num_local_elements( bulkData, node ); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
void populate_interior_perforated_mesh_ids(const stk::mesh::BulkData &bulkData, |
| 334 |
const stk::mesh::ElemElemGraph& eeGraph, |
| 335 |
const stk::mesh::EntityVector &localElems, |
| 336 |
NodeConnectivityInfo &nodeConnInfo, |
| 337 |
DeletedMeshInfo &meshInfo) |
| 338 |
{ |
| 339 |
for(unsigned lastIndex = 0; lastIndex < localElems.size(); ++lastIndex) |
| 340 |
{ |
| 341 |
stk::mesh::Entity localElement = localElems[lastIndex]; |
| 342 |
stk::mesh::EntityId elemId = bulkData.identifier( localElement ); |
| 343 |
|
| 344 |
if(!is_element_on_processor_boundary(eeGraph, localElement) && |
| 345 |
!will_deleting_element_create_orphaned_nodes(bulkData, localElement, nodeConnInfo)) |
| 346 |
{ |
| 347 |
meshInfo.elemIds.push_back(elemId); |
| 348 |
decrement_node_connectivity(bulkData, localElement, nodeConnInfo); |
| 349 |
} |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
void populate_processor_boundary_perforated_mesh_ids(const stk::mesh::BulkData &bulkData, |
| 354 |
const stk::mesh::ElemElemGraph& eeGraph, |
| 355 |
const stk::mesh::EntityVector &localElems, |
| 356 |
NodeConnectivityInfo &nodeConnInfo, |
| 357 |
DeletedMeshInfo &meshInfo) |
| 358 |
{ |
| 359 |
for(unsigned lastIndex = 0; lastIndex < localElems.size(); ++lastIndex) |
| 360 |
{ |
| 361 |
stk::mesh::Entity localElement = localElems[lastIndex]; |
| 362 |
stk::mesh::EntityId elemId = bulkData.identifier( localElement ); |
| 363 |
|
| 364 |
if(is_element_on_processor_boundary(eeGraph, localElement) && |
| 365 |
!will_deleting_element_create_orphaned_nodes(bulkData, localElement, nodeConnInfo)) |
| 366 |
{ |
| 367 |
meshInfo.elemIds.push_back(elemId); |
| 368 |
decrement_node_connectivity(bulkData, localElement, nodeConnInfo); |
| 369 |
} |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
void get_perforated_mesh_ids(const stk::mesh::BulkData &bulkData, const stk::mesh::ElemElemGraph& eeGraph, DeletedMeshInfo &meshInfo) |
| 374 |
{ |
| 375 |
stk::mesh::EntityVector localElems; |
| 376 |
stk::mesh::get_selected_entities(bulkData.mesh_meta_data().locally_owned_part(), bulkData.buckets(stk::topology::ELEM_RANK), localElems); |
| 377 |
|
| 378 |
meshInfo.elemIds.reserve(localElems.size()); |
| 379 |
|
| 380 |
NodeConnectivityInfo nodeConnInfo; |
| 381 |
|
| 382 |
initialize_node_connectivity_map(bulkData, nodeConnInfo); |
| 383 |
|
| 384 |
populate_interior_perforated_mesh_ids(bulkData, eeGraph, localElems, nodeConnInfo, meshInfo); |
| 385 |
|
| 386 |
populate_processor_boundary_perforated_mesh_ids(bulkData, eeGraph, localElems, nodeConnInfo, meshInfo); |
| 387 |
|
| 388 |
print_delete_info(bulkData, meshInfo); |
| 389 |
} |
| 390 |
|
| 391 |
class ElementGraphPerformance : public stk::unit_test_util::PerformanceTester |
| 392 |
{ |
| 393 |
public: |
| 394 |
ElementGraphPerformance(stk::mesh::BulkData &bulk, const std::string &fileSpec) |
| 395 |
: stk::unit_test_util::PerformanceTester(bulk.parallel()), |
| 396 |
bulkData(bulk), |
| 397 |
meshSpec(fileSpec) |
| 398 |
{ |
| 399 |
} |
| 400 |
|
| 401 |
virtual ~ElementGraphPerformance() |
| 402 |
{ |
| 403 |
} |
| 404 |
|
| 405 |
protected: |
| 406 |
void delete_elements(DeletedMeshInfo &meshInfo) |
| 407 |
{ |
| 408 |
meshInfo.elemNodes.resize(meshInfo.elemIds.size()); |
| 409 |
|
| 410 |
bulkData.modification_begin(); |
| 411 |
for(size_t i = 0; i < meshInfo.elemIds.size(); ++i) |
| 412 |
{ |
| 413 |
stk::mesh::EntityId elemId = meshInfo.elemIds[i]; |
| 414 |
stk::mesh::Entity elem = bulkData.get_entity(stk::topology::ELEM_RANK, elemId); |
| 415 |
|
| 416 |
meshInfo.elemNodes[i].assign(bulkData.begin_nodes(elem), bulkData.end_nodes(elem)); |
| 417 |
|
| 418 |
bulkData.destroy_entity(elem); |
| 419 |
} |
| 420 |
bulkData.modification_end(); |
| 421 |
} |
| 422 |
|
| 423 |
void add_elements(DeletedMeshInfo &meshInfo) |
| 424 |
{ |
| 425 |
bulkData.modification_begin(); |
| 426 |
stk::mesh::Part &hexPart = bulkData.mesh_meta_data().get_topology_root_part(stk::topology::HEX_8); |
| 427 |
stk::mesh::Part *block_1 = bulkData.mesh_meta_data().get_part("block_1"); |
| 428 |
stk::mesh::PartVector parts{&hexPart, block_1}; |
| 429 |
for(size_t i = 0; i < meshInfo.elemIds.size(); ++i) |
| 430 |
{ |
| 431 |
stk::mesh::EntityId elemId = meshInfo.elemIds[i]; |
| 432 |
stk::mesh::Entity elem = bulkData.declare_element(elemId, parts); |
| 433 |
|
| 434 |
for(size_t j = 0; j<meshInfo.elemNodes[i].size(); ++j) |
| 435 |
{ |
| 436 |
stk::mesh::Entity node = meshInfo.elemNodes[i][j]; |
| 437 |
bulkData.declare_relation(elem, node, j); |
| 438 |
} |
| 439 |
} |
| 440 |
bulkData.modification_end(); |
| 441 |
} |
| 442 |
|
| 443 |
virtual void run_algorithm_to_time() |
| 444 |
{ |
| 445 |
// Add graph creation (and, consequently, deletion) to the timing |
| 446 |
bulkData.delete_face_adjacent_element_graph(); |
| 447 |
bulkData.initialize_face_adjacent_element_graph(); |
| 448 |
|
| 449 |
stk::mesh::ElemElemGraph & elemGraph = bulkData.get_face_adjacent_element_graph(); |
| 450 |
DeletedMeshInfo meshInfo; |
| 451 |
|
| 452 |
unsigned oldGraphEdgeCount = elemGraph.num_edges(); |
| 453 |
get_ids_along_boundary(bulkData, meshSpec, meshInfo); |
| 454 |
|
| 455 |
delete_elements(meshInfo); |
| 456 |
//stk::io::write_mesh("afterDelete.g", bulkData, bulkData.parallel()); |
| 457 |
unsigned newGraphEdgeCount = elemGraph.num_edges(); |
| 458 |
ASSERT_TRUE(oldGraphEdgeCount > newGraphEdgeCount); |
| 459 |
|
| 460 |
add_elements(meshInfo); |
| 461 |
|
| 462 |
unsigned finalGraphEdgeCount = elemGraph.num_edges(); |
| 463 |
ASSERT_EQ(oldGraphEdgeCount, finalGraphEdgeCount); |
| 464 |
} |
| 465 |
virtual size_t get_value_to_output_as_iteration_count() |
| 466 |
{ |
| 467 |
return 1; |
| 468 |
} |
| 469 |
|
| 470 |
stk::mesh::BulkData &bulkData; |
| 471 |
const std::string meshSpec; |
| 472 |
}; |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
class PerforatedElementGraphPerformance : public ElementGraphPerformance |
| 477 |
{ |
| 478 |
public: |
| 479 |
PerforatedElementGraphPerformance(stk::mesh::BulkData &bulk, const std::string &fileSpec, const std::string &animateFile = "") : |
| 480 |
ElementGraphPerformance(bulk, fileSpec), |
| 481 |
animationFile(animateFile) |
| 482 |
{ |
| 483 |
|
| 484 |
} |
| 485 |
|
| 486 |
~PerforatedElementGraphPerformance() |
| 487 |
{ |
| 488 |
|
| 489 |
} |
| 490 |
|
| 491 |
void delete_graph() |
| 492 |
{ |
| 493 |
bulkData.delete_face_adjacent_element_graph(); |
| 494 |
} |
| 495 |
|
| 496 |
void create_graph() |
| 497 |
{ |
| 498 |
bulkData.initialize_face_adjacent_element_graph(); |
| 499 |
} |
| 500 |
|
| 501 |
void delete_sides() |
| 502 |
{ |
| 503 |
const stk::mesh::MetaData& meta = bulkData.mesh_meta_data(); |
| 504 |
stk::mesh::EntityVector elems; |
| 505 |
stk::mesh::get_selected_entities(meta.locally_owned_part(), |
| 506 |
bulkData.buckets(stk::topology::ELEM_RANK), elems); |
| 507 |
bulkData.modification_begin(); |
| 508 |
|
| 509 |
for(stk::mesh::Entity elem : elems) |
| 510 |
{ |
| 511 |
stk::mesh::destroy_relations(bulkData, elem, meta.side_rank()); |
| 512 |
} |
| 513 |
|
| 514 |
stk::mesh::EntityVector sides; |
| 515 |
stk::mesh::get_selected_entities(meta.locally_owned_part(), |
| 516 |
bulkData.buckets(meta.side_rank()), sides); |
| 517 |
for(stk::mesh::Entity side : sides) |
| 518 |
{ |
| 519 |
bulkData.destroy_entity(side); |
| 520 |
} |
| 521 |
|
| 522 |
bulkData.modification_end(); |
| 523 |
} |
| 524 |
|
| 525 |
protected: |
| 526 |
virtual void run_algorithm_to_time() |
| 527 |
{ |
| 528 |
stk::mesh::ElemElemGraph & elemGraph = bulkData.get_face_adjacent_element_graph(); |
| 529 |
DeletedMeshInfo meshInfo; |
| 530 |
|
| 531 |
stk::mesh::Part& surface = bulkData.mesh_meta_data().declare_part("Skinned Surface"); |
| 532 |
create_exposed_boundary(surface); |
| 533 |
|
| 534 |
unsigned oldGraphEdgeCount = elemGraph.num_edges(); |
| 535 |
get_perforated_mesh_ids(bulkData, elemGraph, meshInfo); |
| 536 |
|
| 537 |
delete_elements(meshInfo); |
| 538 |
//stk::io::write_mesh("afterDelete.g", bulkData, bulkData.parallel()); |
| 539 |
unsigned newGraphEdgeCount = elemGraph.num_edges(); |
| 540 |
ASSERT_TRUE(oldGraphEdgeCount > newGraphEdgeCount); |
| 541 |
|
| 542 |
add_elements(meshInfo); |
| 543 |
//stk::io::write_mesh("afterAdd.g", bulkData, bulkData.parallel()); |
| 544 |
unsigned finalGraphEdgeCount = elemGraph.num_edges(); |
| 545 |
ASSERT_EQ(oldGraphEdgeCount, finalGraphEdgeCount); |
| 546 |
|
| 547 |
animate_death(bulkData, meshInfo.elemIds, animationFile); |
| 548 |
} |
| 549 |
|
| 550 |
void create_exposed_boundary(stk::mesh::Part& surface) |
| 551 |
{ |
| 552 |
print_memory(bulkData.parallel(), "Before create exposed boundary sides"); |
| 553 |
stk::mesh::create_exposed_block_boundary_sides(bulkData, bulkData.mesh_meta_data().universal_part(), {&surface}); |
| 554 |
print_skin_info(bulkData, surface); |
| 555 |
} |
| 556 |
|
| 557 |
std::string animationFile; |
| 558 |
}; |
| 559 |
|
| 560 |
class ElementGraphPerformanceTest : public stk::unit_test_util::MeshFixture |
| 561 |
{ |
| 562 |
protected: |
| 563 |
void run_element_graph_perf_test() |
| 564 |
{ |
| 565 |
ElementGraphPerformance perfTester(get_bulk(), get_mesh_spec()); |
| 566 |
const int numTimes = 30; |
| 567 |
for (int i=0; i < numTimes; ++i) { |
| 568 |
perfTester.run_performance_test(); |
| 569 |
} |
| 570 |
} |
| 571 |
std::string get_mesh_spec() |
| 572 |
{ |
| 573 |
return stk::unit_test_util::get_option("-file", "NO_FILE_SPECIFIED"); |
| 574 |
} |
| 575 |
}; |
| 576 |
|
| 577 |
class PerforatedElementGraphPerformanceTest : public stk::unit_test_util::MeshFixture |
| 578 |
{ |
| 579 |
protected: |
| 580 |
void run_element_graph_perf_test() |
| 581 |
{ |
| 582 |
PerforatedElementGraphPerformance perfTester(get_bulk(), get_mesh_spec(), animationFile); |
| 583 |
const int numTimes = 12; |
| 584 |
for (int i=0; i < numTimes; ++i) { |
| 585 |
perfTester.delete_sides(); |
| 586 |
perfTester.delete_graph(); |
| 587 |
perfTester.create_graph(); |
| 588 |
perfTester.run_performance_test(); |
| 589 |
} |
| 590 |
} |
| 591 |
std::string get_mesh_spec() |
| 592 |
{ |
| 593 |
return stk::unit_test_util::get_option("-file", "NO_FILE_SPECIFIED"); |
| 594 |
} |
| 595 |
|
| 596 |
std::string animationFile = ""; |
| 597 |
}; |
| 598 |
|
| 599 |
TEST_F(ElementGraphPerformanceTest, read_mesh) |
| 600 |
{ |
| 601 |
print_memory(MPI_COMM_WORLD, "Before mesh creation"); |
| 602 |
setup_mesh(get_mesh_spec(), stk::mesh::BulkData::AUTO_AURA); |
| 603 |
|
| 604 |
run_element_graph_perf_test(); |
| 605 |
} |
| 606 |
|
| 607 |
TEST_F(ElementGraphPerformanceTest, read_mesh_no_aura) |
| 608 |
{ |
| 609 |
print_memory(MPI_COMM_WORLD, "Before mesh creation"); |
| 610 |
setup_mesh(get_mesh_spec(), stk::mesh::BulkData::NO_AUTO_AURA); |
| 611 |
|
| 612 |
run_element_graph_perf_test(); |
| 613 |
} |
| 614 |
|
| 615 |
TEST_F(PerforatedElementGraphPerformanceTest, read_mesh_with_auto_decomp) |
| 616 |
{ |
| 617 |
print_memory(MPI_COMM_WORLD, "Before mesh creation"); |
| 618 |
allocate_bulk(stk::mesh::BulkData::AUTO_AURA); |
| 619 |
declare_animation_field(get_meta(), animationFile); |
| 620 |
stk::unit_test_util::read_from_serial_file_and_decompose(get_mesh_spec(), get_bulk(), "rcb"); |
| 621 |
|
| 622 |
run_element_graph_perf_test(); |
| 623 |
} |
| 624 |
|
| 625 |
TEST_F(PerforatedElementGraphPerformanceTest, read_mesh_with_auto_decomp_no_aura) |
| 626 |
{ |
| 627 |
print_memory(MPI_COMM_WORLD, "Before mesh creation"); |
| 628 |
allocate_bulk(stk::mesh::BulkData::NO_AUTO_AURA); |
| 629 |
declare_animation_field(get_meta(), animationFile); |
| 630 |
stk::unit_test_util::read_from_serial_file_and_decompose(get_mesh_spec(), get_bulk(), "rcb"); |
| 631 |
|
| 632 |
run_element_graph_perf_test(); |
| 633 |
} |
| 634 |
|
| 635 |
} |
| 636 |
|