| 1 |
#include "stk_mesh/base/GetEntities.hpp" // for get_selected_entities |
| 2 |
#include "stk_mesh/base/SideSetUtil.hpp" |
| 3 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 4 |
#include <stk_unit_test_utils/getOption.h> |
| 5 |
#include <stk_io/StkIoUtils.hpp> |
| 6 |
|
| 7 |
namespace |
| 8 |
{ |
| 9 |
|
| 10 |
class StkToolsB : public stk::unit_test_util::MeshFixture {}; |
| 11 |
|
| 12 |
TEST_F(StkToolsB, GetBlockIdsForSpecifiedSideset) |
| 13 |
{ |
| 14 |
const std::string unNamed = "mesh not specified"; |
| 15 |
const std::string meshName = stk::unit_test_util::get_option("-i", unNamed); |
| 16 |
STK_ThrowRequireMsg(meshName!=unNamed, "Please specify mesh with -i option."); |
| 17 |
setup_mesh(meshName, stk::mesh::BulkData::NO_AUTO_AURA); |
| 18 |
|
| 19 |
int invalidSideset = -1; |
| 20 |
int sideset = stk::unit_test_util::get_command_line_option("-s", invalidSideset); |
| 21 |
STK_ThrowRequireMsg(sideset!=invalidSideset, "Please specify sideset with -s."); |
| 22 |
|
| 23 |
std::string sidesetName = "surface_" + std::to_string(sideset); |
| 24 |
stk::mesh::Part* ss = get_meta().get_part(sidesetName); |
| 25 |
STK_ThrowRequire(ss!=nullptr); |
| 26 |
stk::mesh::EntityVector sides; |
| 27 |
stk::mesh::get_selected_entities(*ss, get_bulk().buckets(get_meta().side_rank()),sides); |
| 28 |
|
| 29 |
std::ofstream outfile("test.out.txt", std::ofstream::app); |
| 30 |
|
| 31 |
std::set<int> blockIds; |
| 32 |
for (stk::mesh::Entity side : sides) |
| 33 |
{ |
| 34 |
unsigned numElements = get_bulk().num_elements(side); |
| 35 |
if (numElements > 1) |
| 36 |
{ |
| 37 |
outfile << "This is an internal side" << std::endl; |
| 38 |
} |
| 39 |
const stk::mesh::Entity *elements = get_bulk().begin_elements(side); |
| 40 |
for (unsigned i = 0; i < numElements; ++i) |
| 41 |
{ |
| 42 |
const stk::mesh::Part *block = stk::mesh::get_element_block_part(get_bulk(), elements[i]); |
| 43 |
blockIds.insert(block->id()); |
| 44 |
} |
| 45 |
} |
| 46 |
for (int id : blockIds) |
| 47 |
{ |
| 48 |
outfile << "blockId: " << id << std::endl; |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
} |