| 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/base/Types.hpp> |
| 41 |
#include <stk_mesh/base/Comm.hpp> |
| 42 |
#include <stk_mesh/base/Field.hpp> |
| 43 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 44 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 45 |
#include <stk_unit_test_utils/GetMeshSpec.hpp> |
| 46 |
#include <stk_unit_test_utils/TextMesh.hpp> |
| 47 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 48 |
#include <stk_io/FillMesh.hpp> |
| 49 |
#include <stk_io/IossBridge.hpp> |
| 50 |
#include <stk_io/StkMeshIoBroker.hpp> |
| 51 |
#include <stk_util/parallel/Parallel.hpp> |
| 52 |
#include <stk_util/util/string_case_compare.hpp> |
| 53 |
#include <Ioss_FaceBlock.h> |
| 54 |
#include <Ioss_Region.h> |
| 55 |
#include "UnitTestReadWriteFaces.hpp" |
| 56 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 57 |
|
| 58 |
using stk::unit_test_util::build_mesh; |
| 59 |
using stk::unit_test_util::build_mesh_no_simple_fields; |
| 60 |
|
| 61 |
void StkFaceIoTest::setup_face_mesh(unsigned numBlocks) |
| 62 |
{ |
| 63 |
std::string meshDesc = stk::unit_test_util::get_many_block_mesh_desc(numBlocks, stk::parallel_machine_size(MPI_COMM_WORLD)); |
| 64 |
std::vector<double> coords = stk::unit_test_util::get_many_block_coordinates(numBlocks); |
| 65 |
stk::mesh::Part* facePart = &get_meta().declare_part_with_topology(facePartName, stk::topology::QUAD_4); |
| 66 |
stk::io::put_face_block_io_part_attribute(*facePart); |
| 67 |
stk::unit_test_util::setup_text_mesh(get_bulk(), stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coords)); |
| 68 |
|
| 69 |
stk::mesh::PartVector faceParts = {facePart}; |
| 70 |
stk::mesh::create_interior_block_boundary_sides(get_bulk(), get_meta().universal_part(), faceParts); |
| 71 |
} |
| 72 |
|
| 73 |
void StkFaceIoTest::setup_mesh_with_faces(unsigned numBlocks) |
| 74 |
{ |
| 75 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 76 |
setup_face_mesh(numBlocks); |
| 77 |
} |
| 78 |
|
| 79 |
void StkFaceIoTest::setup_mesh_with_edges_and_faces(unsigned numBlocks) |
| 80 |
{ |
| 81 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 82 |
std::string meshDesc = stk::unit_test_util::get_many_block_mesh_desc(numBlocks, stk::parallel_machine_size(MPI_COMM_WORLD)); |
| 83 |
std::vector<double> coords = stk::unit_test_util::get_many_block_coordinates(numBlocks); |
| 84 |
stk::mesh::Part* edgePart = &get_meta().declare_part_with_topology(edgePartName, stk::topology::LINE_2); |
| 85 |
stk::mesh::Part* facePart = &get_meta().declare_part_with_topology(facePartName, stk::topology::QUAD_4); |
| 86 |
stk::io::put_face_block_io_part_attribute(*facePart); |
| 87 |
stk::io::put_edge_block_io_part_attribute(*edgePart); |
| 88 |
stk::unit_test_util::setup_text_mesh(get_bulk(), stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coords)); |
| 89 |
|
| 90 |
stk::mesh::PartVector faceParts = {facePart}; |
| 91 |
stk::mesh::create_interior_block_boundary_sides(get_bulk(), get_meta().universal_part(), faceParts); |
| 92 |
stk::mesh::create_edges(get_bulk(), get_meta().universal_part(), edgePart); |
| 93 |
} |
| 94 |
|
| 95 |
void StkFaceIoTest::test_connectivity_to_element(const stk::mesh::BulkData& bulk, stk::mesh::EntityRank entityRank) |
| 96 |
{ |
| 97 |
stk::mesh::EntityVector entities; |
| 98 |
const stk::mesh::MetaData& meta = bulk.mesh_meta_data(); |
| 99 |
const stk::mesh::BucketVector& buckets = bulk.buckets(entityRank); |
| 100 |
|
| 101 |
if(bulk.parallel_size() > 1) { |
| 102 |
|
| 103 |
stk::mesh::Selector ownedAndNotShared = meta.locally_owned_part() & !meta.globally_shared_part(); |
| 104 |
stk::mesh::get_selected_entities(ownedAndNotShared, buckets, entities); |
| 105 |
|
| 106 |
for(stk::mesh::Entity entity: entities) { |
| 107 |
EXPECT_EQ(1u, bulk.num_elements(entity)); |
| 108 |
} |
| 109 |
|
| 110 |
stk::mesh::Selector shared = meta.globally_shared_part(); |
| 111 |
stk::mesh::get_selected_entities(shared, buckets, entities); |
| 112 |
|
| 113 |
unsigned expectedNumElems = bulk.is_automatic_aura_on() ? 2u : 1u; |
| 114 |
for(stk::mesh::Entity entity : entities) { |
| 115 |
EXPECT_EQ(expectedNumElems, bulk.num_elements(entity)); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
void StkFaceIoTest::test_entity_count(const stk::mesh::BulkData& bulk, stk::mesh::EntityRank entityRank, |
| 121 |
unsigned expectedNumLocalEntities, unsigned expectedNumEntities) |
| 122 |
{ |
| 123 |
stk::mesh::EntityVector entities; |
| 124 |
const stk::mesh::MetaData& meta = bulk.mesh_meta_data(); |
| 125 |
const stk::mesh::BucketVector& buckets = bulk.buckets(entityRank); |
| 126 |
|
| 127 |
unsigned numLocalEntities = stk::mesh::count_selected_entities(meta.locally_owned_part(), buckets); |
| 128 |
EXPECT_EQ(expectedNumLocalEntities, numLocalEntities); |
| 129 |
|
| 130 |
stk::mesh::Selector selector = meta.locally_owned_part() | meta.globally_shared_part(); |
| 131 |
unsigned numEntities = stk::mesh::count_selected_entities(selector, buckets); |
| 132 |
EXPECT_EQ(expectedNumEntities, numEntities); |
| 133 |
} |
| 134 |
|
| 135 |
void StkFaceIoTest::test_edges(const stk::mesh::BulkData& bulk) |
| 136 |
{ |
| 137 |
test_entity_count(bulk, stk::topology::EDGE_RANK, expectedValues.numLocalEdgesPerProc[bulk.parallel_rank()], |
| 138 |
expectedValues.numEdgesPerProc[bulk.parallel_rank()]); |
| 139 |
test_connectivity_to_element(bulk, stk::topology::EDGE_RANK); |
| 140 |
} |
| 141 |
|
| 142 |
void StkFaceIoTest::test_faces(const stk::mesh::BulkData& bulk) |
| 143 |
{ |
| 144 |
test_entity_count(bulk, stk::topology::FACE_RANK, expectedValues.numLocalFacesPerProc[bulk.parallel_rank()], |
| 145 |
expectedValues.numFacesPerProc[bulk.parallel_rank()]); |
| 146 |
test_connectivity_to_element(bulk, stk::topology::FACE_RANK); |
| 147 |
} |
| 148 |
|
| 149 |
void StkFaceIoTest::output_mesh() |
| 150 |
{ |
| 151 |
stkIoOutput.set_bulk_data(get_bulk()); |
| 152 |
size_t outputFileIndex = stkIoOutput.create_output_mesh(fileName, stk::io::WRITE_RESULTS); |
| 153 |
|
| 154 |
stkIoOutput.write_output_mesh(outputFileIndex); |
| 155 |
} |
| 156 |
|
| 157 |
void StkFaceIoTest::test_output_mesh() |
| 158 |
{ |
| 159 |
std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(MPI_COMM_WORLD); |
| 160 |
|
| 161 |
load_output_mesh(*bulk); |
| 162 |
test_output_mesh(*bulk); |
| 163 |
} |
| 164 |
|
| 165 |
void StkFaceIoTest::load_output_mesh(stk::mesh::BulkData& bulk) |
| 166 |
{ |
| 167 |
stk::io::fill_mesh(fileName, bulk, stkIoInput); |
| 168 |
} |
| 169 |
|
| 170 |
void StkFaceIoTest::test_output_mesh(stk::mesh::BulkData& bulk) |
| 171 |
{ |
| 172 |
std::vector<size_t> entityCounts; |
| 173 |
stk::mesh::comm_mesh_counts(bulk, entityCounts); |
| 174 |
EXPECT_EQ(expectedValues.globalEdgeCount, entityCounts[stk::topology::EDGE_RANK]); |
| 175 |
EXPECT_EQ(expectedValues.globalElemCount, entityCounts[stk::topology::ELEM_RANK]); |
| 176 |
|
| 177 |
std::shared_ptr<Ioss::Region> inputRegion = stkIoInput.get_input_ioss_region(); |
| 178 |
const Ioss::FaceBlockContainer& faceBlocks = inputRegion->get_face_blocks(); |
| 179 |
ASSERT_EQ(1u, faceBlocks.size()); |
| 180 |
EXPECT_TRUE(stk::equal_case(facePartName, faceBlocks[0]->name())); |
| 181 |
|
| 182 |
test_edges(bulk); |
| 183 |
test_faces(bulk); |
| 184 |
} |
| 185 |
|
| 186 |
void StkFaceIoTest::set_expected_values(io_test_utils::ExpectedValues& expectedValues_) |
| 187 |
{ |
| 188 |
expectedValues = expectedValues_; |
| 189 |
} |
| 190 |
|
| 191 |
TEST_F(StkFaceIoTest, SerialSetupFaceMesh) |
| 192 |
{ |
| 193 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 1) { return; } |
| 194 |
|
| 195 |
setup_mesh_with_faces(2); |
| 196 |
|
| 197 |
stk::mesh::Part* facePart = get_meta().get_part(facePartName); |
| 198 |
EXPECT_FALSE(facePart == nullptr); |
| 199 |
EXPECT_TRUE(stk::io::is_part_face_block_io_part(*facePart)); |
| 200 |
} |
| 201 |
|
| 202 |
TEST_F(StkFaceIoTest, SerialWriteMesh) |
| 203 |
{ |
| 204 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 1) { return; } |
| 205 |
io_test_utils::ExpectedValues expectedTestValues; |
| 206 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{0}; |
| 207 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{0}; |
| 208 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{1}; |
| 209 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{1}; |
| 210 |
expectedTestValues.numConnectedEdges = 0; |
| 211 |
expectedTestValues.globalEdgeCount = 0; |
| 212 |
expectedTestValues.globalElemCount = 2; |
| 213 |
|
| 214 |
setup_mesh_with_faces(2); |
| 215 |
set_expected_values(expectedTestValues); |
| 216 |
test_faces(get_bulk()); |
| 217 |
output_mesh(); |
| 218 |
|
| 219 |
test_output_mesh(); |
| 220 |
} |
| 221 |
|
| 222 |
TEST_F(StkFaceIoTest, ParallelWriteMesh) |
| 223 |
{ |
| 224 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { return; } |
| 225 |
io_test_utils::ExpectedValues expectedTestValues; |
| 226 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{0, 0}; |
| 227 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{0, 0}; |
| 228 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{1, 1}; |
| 229 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{1, 0}; |
| 230 |
expectedTestValues.numConnectedEdges = 0; |
| 231 |
expectedTestValues.globalEdgeCount = 0; |
| 232 |
expectedTestValues.globalElemCount = 2; |
| 233 |
|
| 234 |
setup_mesh_with_faces(2); |
| 235 |
set_expected_values(expectedTestValues); |
| 236 |
test_faces(get_bulk()); |
| 237 |
output_mesh(); |
| 238 |
|
| 239 |
test_output_mesh(); |
| 240 |
} |
| 241 |
|
| 242 |
TEST_F(StkFaceIoTest, SerialWriteMeshWithEdge) |
| 243 |
{ |
| 244 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 1) { return; } |
| 245 |
io_test_utils::ExpectedValues expectedTestValues; |
| 246 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{20}; |
| 247 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{20}; |
| 248 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{1}; |
| 249 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{1}; |
| 250 |
expectedTestValues.numConnectedEdges = 4; |
| 251 |
expectedTestValues.globalEdgeCount = 20; |
| 252 |
expectedTestValues.globalElemCount = 2; |
| 253 |
|
| 254 |
setup_mesh_with_edges_and_faces(2); |
| 255 |
set_expected_values(expectedTestValues); |
| 256 |
test_edges(get_bulk()); |
| 257 |
test_faces(get_bulk()); |
| 258 |
output_mesh(); |
| 259 |
|
| 260 |
test_output_mesh(); |
| 261 |
} |
| 262 |
|
| 263 |
TEST_F(StkFaceIoTest, ParallelWriteMeshWithEdge) |
| 264 |
{ |
| 265 |
if(stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { return; } |
| 266 |
io_test_utils::ExpectedValues expectedTestValues; |
| 267 |
expectedTestValues.numEdgesPerProc = std::vector<unsigned>{12, 12}; |
| 268 |
expectedTestValues.numLocalEdgesPerProc = std::vector<unsigned>{12, 8}; |
| 269 |
expectedTestValues.numFacesPerProc = std::vector<unsigned>{1, 1}; |
| 270 |
expectedTestValues.numLocalFacesPerProc = std::vector<unsigned>{1, 0}; |
| 271 |
expectedTestValues.numConnectedEdges = 4; |
| 272 |
expectedTestValues.globalEdgeCount = 20; |
| 273 |
expectedTestValues.globalElemCount = 2; |
| 274 |
|
| 275 |
setup_mesh_with_edges_and_faces(2); |
| 276 |
set_expected_values(expectedTestValues); |
| 277 |
test_edges(get_bulk()); |
| 278 |
test_faces(get_bulk()); |
| 279 |
output_mesh(); |
| 280 |
|
| 281 |
test_output_mesh(); |
| 282 |
} |