| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
|
| 34 |
#include <gtest/gtest.h> |
| 35 |
#include <stk_topology/topology.hpp> |
| 36 |
#include <stk_mesh/base/BulkData.hpp> |
| 37 |
#include <stk_mesh/base/MetaData.hpp> |
| 38 |
#include <stk_mesh/base/GetEntities.hpp> |
| 39 |
#include <stk_mesh/baseImpl/MeshImplUtils.hpp> |
| 40 |
#include <stk_mesh/baseImpl/ConnectEdgesImpl.hpp> |
| 41 |
#include <stk_mesh/base/Types.hpp> |
| 42 |
#include <stk_mesh/base/Comm.hpp> |
| 43 |
#include <stk_mesh/base/Field.hpp> |
| 44 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 45 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 46 |
#include <stk_unit_test_utils/GetMeshSpec.hpp> |
| 47 |
#include <stk_unit_test_utils/TextMesh.hpp> |
| 48 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 49 |
#include <stk_io/FillMesh.hpp> |
| 50 |
#include <stk_io/IossBridge.hpp> |
| 51 |
#include <stk_io/StkMeshIoBroker.hpp> |
| 52 |
#include <stk_util/parallel/Parallel.hpp> |
| 53 |
#include "UnitTestReadWriteEdges.hpp" |
| 54 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 55 |
|
| 56 |
using stk::unit_test_util::build_mesh; |
| 57 |
using stk::unit_test_util::build_mesh_no_simple_fields; |
| 58 |
|
| 59 |
void StkEdgeIoTest::setup_edge_mesh(unsigned numBlocks) |
| 60 |
{ |
| 61 |
std::string meshDesc = stk::unit_test_util::get_many_block_mesh_desc(numBlocks, stk::parallel_machine_size(MPI_COMM_WORLD)); |
| 62 |
std::vector<double> coords = stk::unit_test_util::get_many_block_coordinates(numBlocks); |
| 63 |
stk::mesh::Part* edgePart = &get_meta().declare_part_with_topology(edgePartName, stk::topology::LINE_2); |
| 64 |
stk::io::put_edge_block_io_part_attribute(*edgePart); |
| 65 |
stk::unit_test_util::setup_text_mesh(get_bulk(), stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coords)); |
| 66 |
|
| 67 |
stk::mesh::create_edges(get_bulk(), get_meta().universal_part(), edgePart); |
| 68 |
} |
| 69 |
|
| 70 |
void StkEdgeIoTest::setup_mesh_with_edges(unsigned numBlocks) |
| 71 |
{ |
| 72 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 73 |
setup_edge_mesh(numBlocks); |
| 74 |
} |
| 75 |
|
| 76 |
void StkEdgeIoTest::setup_mesh_with_edges_and_faces(unsigned numBlocks) |
| 77 |
{ |
| 78 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 79 |
std::string meshDesc = stk::unit_test_util::get_many_block_mesh_desc(numBlocks, stk::parallel_machine_size(MPI_COMM_WORLD)); |
| 80 |
std::vector<double> coords = stk::unit_test_util::get_many_block_coordinates(numBlocks); |
| 81 |
stk::mesh::Part* edgePart = &get_meta().declare_part_with_topology(edgePartName, stk::topology::LINE_2); |
| 82 |
stk::mesh::Part* facePart = &get_meta().declare_part_with_topology(facePartName, stk::topology::QUAD_4); |
| 83 |
stk::io::put_io_part_attribute(*facePart); |
| 84 |
stk::io::put_edge_block_io_part_attribute(*edgePart); |
| 85 |
stk::unit_test_util::setup_text_mesh(get_bulk(), stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coords)); |
| 86 |
|
| 87 |
stk::mesh::PartVector faceParts = {facePart}; |
| 88 |
stk::mesh::create_interior_block_boundary_sides(get_bulk(), get_meta().universal_part(), faceParts); |
| 89 |
stk::mesh::create_edges(get_bulk(), get_meta().universal_part(), edgePart); |
| 90 |
} |
| 91 |
|
| 92 |
void StkEdgeIoTest::test_connectivity_to_element(const stk::mesh::BulkData& bulk, stk::mesh::EntityRank entityRank) |
| 93 |
{ |
| 94 |
stk::mesh::EntityVector entities; |
| 95 |
const stk::mesh::MetaData& meta = bulk.mesh_meta_data(); |
| 96 |
const stk::mesh::BucketVector& buckets = bulk.buckets(entityRank); |
| 97 |
|
| 98 |
if(bulk.parallel_size() > 1) { |
| 99 |
|
| 100 |
stk::mesh::Selector ownedAndNotShared = meta.locally_owned_part() & !meta.globally_shared_part(); |
| 101 |
stk::mesh::get_selected_entities(ownedAndNotShared, buckets, entities); |
| 102 |
|
| 103 |
for(stk::mesh::Entity entity: entities) { |
| 104 |
EXPECT_EQ(1u, bulk.num_elements(entity)); |
| 105 |
} |
| 106 |
|
| 107 |
stk::mesh::Selector shared = meta.globally_shared_part(); |
| 108 |
stk::mesh::get_selected_entities(shared, buckets, entities); |
| 109 |
|
| 110 |
unsigned expectedNumElems = bulk.is_automatic_aura_on() ? 2u : 1u; |
| 111 |
for(stk::mesh::Entity entity : entities) { |
| 112 |
EXPECT_EQ(expectedNumElems, bulk.num_elements(entity)); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
void StkEdgeIoTest::test_entity_count(const stk::mesh::BulkData& bulk, stk::mesh::EntityRank entityRank, |
| 118 |
unsigned expectedNumLocalEntities, unsigned expectedNumEntities) |
| 119 |
{ |
| 120 |
stk::mesh::EntityVector entities; |
| 121 |
const stk::mesh::MetaData& meta = bulk.mesh_meta_data(); |
| 122 |
const stk::mesh::BucketVector& buckets = bulk.buckets(entityRank); |
| 123 |
|
| 124 |
unsigned numLocalEntities = stk::mesh::count_selected_entities(meta.locally_owned_part(), buckets); |
| 125 |
EXPECT_EQ(expectedNumLocalEntities, numLocalEntities); |
| 126 |
|
| 127 |
stk::mesh::Selector selector = meta.locally_owned_part() | meta.globally_shared_part(); |
| 128 |
unsigned numEntities = stk::mesh::count_selected_entities(selector, buckets); |
| 129 |
EXPECT_EQ(expectedNumEntities, numEntities); |
| 130 |
} |
| 131 |
|
| 132 |
void StkEdgeIoTest::test_edges(const stk::mesh::BulkData& bulk) |
| 133 |
{ |
| 134 |
test_entity_count(bulk, stk::topology::EDGE_RANK, expectedValues.numLocalEdgesPerProc[bulk.parallel_rank()], |
| 135 |
expectedValues.numEdgesPerProc[bulk.parallel_rank()]); |
| 136 |
test_connectivity_to_element(bulk, stk::topology::EDGE_RANK); |
| 137 |
} |
| 138 |
|
| 139 |
void StkEdgeIoTest::test_faces(const stk::mesh::BulkData& bulk) |
| 140 |
{ |
| 141 |
test_entity_count(bulk, stk::topology::FACE_RANK, expectedValues.numLocalFacesPerProc[bulk.parallel_rank()], |
| 142 |
expectedValues.numFacesPerProc[bulk.parallel_rank()]); |
| 143 |
test_connectivity_to_element(bulk, stk::topology::FACE_RANK); |
| 144 |
} |
| 145 |
|
| 146 |
void StkEdgeIoTest::output_mesh() |
| 147 |
{ |
| 148 |
stk::io::StkMeshIoBroker stkIo; |
| 149 |
stkIo.set_bulk_data(get_bulk()); |
| 150 |
size_t outputFileIndex = stkIo.create_output_mesh(fileName, stk::io::WRITE_RESULTS); |
| 151 |
|
| 152 |
stkIo.write_output_mesh(outputFileIndex); |
| 153 |
} |
| 154 |
|
| 155 |
void StkEdgeIoTest::test_output_mesh() |
| 156 |
{ |
| 157 |
std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(MPI_COMM_WORLD); |
| 158 |
|
| 159 |
load_output_mesh(*bulk); |
| 160 |
test_output_mesh(*bulk); |
| 161 |
} |
| 162 |
|
| 163 |
void StkEdgeIoTest::load_output_mesh(stk::mesh::BulkData& bulk) |
| 164 |
{ |
| 165 |
stk::io::fill_mesh(fileName, bulk); |
| 166 |
} |
| 167 |
|
| 168 |
void StkEdgeIoTest::test_output_mesh(stk::mesh::BulkData& bulk) |
| 169 |
{ |
| 170 |
std::vector<size_t> entityCounts; |
| 171 |
stk::mesh::comm_mesh_counts(bulk, entityCounts); |
| 172 |
EXPECT_EQ(expectedValues.globalEdgeCount, entityCounts[stk::topology::EDGE_RANK]); |
| 173 |
EXPECT_EQ(expectedValues.globalElemCount, entityCounts[stk::topology::ELEM_RANK]); |
| 174 |
|
| 175 |
test_edges(bulk); |
| 176 |
test_faces(bulk); |
| 177 |
} |
| 178 |
|
| 179 |
void StkEdgeIoTest::set_expected_values(io_test_utils::ExpectedValues& expectedValues_) |
| 180 |
{ |
| 181 |
expectedValues = expectedValues_; |
| 182 |
} |
| 183 |
|
| 184 |
TEST_F(StkEdgeIoTest, SerialWriteMesh) |
| 185 |
{ |
| 186 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 1) { return; } |
| 187 |
io_test_utils::ExpectedValues expectedTestValues; |
| 188 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{12}; |
| 189 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{12}; |
| 190 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{0}; |
| 191 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{0}; |
| 192 |
expectedTestValues.numConnectedEdges = 0; |
| 193 |
expectedTestValues.globalEdgeCount = 12; |
| 194 |
expectedTestValues.globalElemCount = 1; |
| 195 |
|
| 196 |
setup_mesh_with_edges(1); |
| 197 |
set_expected_values(expectedTestValues); |
| 198 |
test_edges(get_bulk()); |
| 199 |
output_mesh(); |
| 200 |
|
| 201 |
test_output_mesh(); |
| 202 |
} |
| 203 |
|
| 204 |
TEST_F(StkEdgeIoTest, ParallelWriteMesh) |
| 205 |
{ |
| 206 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { return; } |
| 207 |
io_test_utils::ExpectedValues expectedTestValues; |
| 208 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{12, 12}; |
| 209 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{12, 8}; |
| 210 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{0, 0}; |
| 211 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{0, 0}; |
| 212 |
expectedTestValues.numConnectedEdges = 0; |
| 213 |
expectedTestValues.globalEdgeCount = 20; |
| 214 |
expectedTestValues.globalElemCount = 2; |
| 215 |
|
| 216 |
setup_mesh_with_edges(2); |
| 217 |
set_expected_values(expectedTestValues); |
| 218 |
test_edges(get_bulk()); |
| 219 |
output_mesh(); |
| 220 |
|
| 221 |
test_output_mesh(); |
| 222 |
} |
| 223 |
|
| 224 |
TEST_F(StkEdgeIoTest, SerialWriteMeshWithFace) |
| 225 |
{ |
| 226 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 1) { return; } |
| 227 |
io_test_utils::ExpectedValues expectedTestValues; |
| 228 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{20}; |
| 229 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{20}; |
| 230 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{1}; |
| 231 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{1}; |
| 232 |
expectedTestValues.numConnectedEdges = 4; |
| 233 |
expectedTestValues.globalEdgeCount = 20; |
| 234 |
expectedTestValues.globalElemCount = 2; |
| 235 |
|
| 236 |
setup_mesh_with_edges_and_faces(2); |
| 237 |
set_expected_values(expectedTestValues); |
| 238 |
test_edges(get_bulk()); |
| 239 |
test_faces(get_bulk()); |
| 240 |
output_mesh(); |
| 241 |
|
| 242 |
test_output_mesh(); |
| 243 |
} |
| 244 |
|
| 245 |
TEST_F(StkEdgeIoTest, ParallelWriteMeshWithFace) |
| 246 |
{ |
| 247 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { return; } |
| 248 |
io_test_utils::ExpectedValues expectedTestValues; |
| 249 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{12, 12}; |
| 250 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{12, 8}; |
| 251 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{1, 1}; |
| 252 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{1, 0}; |
| 253 |
expectedTestValues.numConnectedEdges = 4; |
| 254 |
expectedTestValues.globalEdgeCount = 20; |
| 255 |
expectedTestValues.globalElemCount = 2; |
| 256 |
|
| 257 |
setup_mesh_with_edges_and_faces(2); |
| 258 |
set_expected_values(expectedTestValues); |
| 259 |
test_edges(get_bulk()); |
| 260 |
test_faces(get_bulk()); |
| 261 |
output_mesh(); |
| 262 |
|
| 263 |
test_output_mesh(); |
| 264 |
} |
| 265 |
|
| 266 |
class StkEdgeKeyholeIoTest : public StkEdgeIoTest |
| 267 |
{ |
| 268 |
public: |
| 269 |
StkEdgeKeyholeIoTest() : StkEdgeIoTest(3) |
| 270 |
{ |
| 271 |
} |
| 272 |
|
| 273 |
void setup_edge_mesh(unsigned /*numBlocks*/) override |
| 274 |
{ |
| 275 |
/* *1 |
| 276 |
/ \ P0 |
| 277 |
/ 1 \ |
| 278 |
*2----*3-----*4----*5 <--proc-boundary--> |
| 279 |
\ 2 / \ 3 / |
| 280 |
\ / \ / P1 |
| 281 |
*6 *7 |
| 282 |
*/ |
| 283 |
std::string meshDesc = "0,1,SHELL_TRI_3,1,4,3\n" |
| 284 |
"1,2,SHELL_TRI_3,2,3,6\n" |
| 285 |
"1,3,SHELL_TRI_3,4,5,7"; |
| 286 |
std::vector<double> coords = { |
| 287 |
3,2,0, |
| 288 |
0,1,0, 2,1,0, 4,1,0, 6,1,0, |
| 289 |
1,0,0, 5,0,0 |
| 290 |
}; |
| 291 |
|
| 292 |
stk::mesh::Part* edgePart = &get_meta().declare_part_with_topology(edgePartName, stk::topology::LINE_2); |
| 293 |
stk::io::put_edge_block_io_part_attribute(*edgePart); |
| 294 |
stk::unit_test_util::setup_text_mesh(get_bulk(), stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coords)); |
| 295 |
|
| 296 |
stk::mesh::create_edges(get_bulk(), get_meta().universal_part(), edgePart); |
| 297 |
} |
| 298 |
}; |
| 299 |
|
| 300 |
TEST_F(StkEdgeKeyholeIoTest, ParallelWriteAndReadMesh) |
| 301 |
{ |
| 302 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { return; } |
| 303 |
io_test_utils::ExpectedValues expectedTestValues; |
| 304 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{3, 6}; |
| 305 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{3, 6}; |
| 306 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{0, 0}; |
| 307 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{0, 0}; |
| 308 |
expectedTestValues.numConnectedEdges = 0; |
| 309 |
expectedTestValues.globalEdgeCount = 9; |
| 310 |
expectedTestValues.globalElemCount = 3; |
| 311 |
|
| 312 |
setup_mesh_with_edges(1); |
| 313 |
set_expected_values(expectedTestValues); |
| 314 |
test_edges(get_bulk()); |
| 315 |
output_mesh(); |
| 316 |
|
| 317 |
test_output_mesh(); |
| 318 |
} |