| 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 |
|
| 35 |
#include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc |
| 36 |
#include <stddef.h> // for size_t |
| 37 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 38 |
#include <stk_mesh/base/Comm.hpp> // for comm_mesh_counts |
| 39 |
#include <stk_mesh/base/CreateFaces.hpp> // for create_faces |
| 40 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData |
| 41 |
#include <stk_mesh/base/SkinMesh.hpp> // for skin_mesh |
| 42 |
#include <vector> // for vector, vector<>::iterator |
| 43 |
#include "mpi.h" // for MPI_COMM_WORLD |
| 44 |
|
| 45 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 46 |
#include "stk_mesh/base/Types.hpp" // for BucketVector, EntityRank |
| 47 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 48 |
#include "stk_unit_test_utils/stk_mesh_fixtures/HexFixture.hpp" // for HexFixture |
| 49 |
|
| 50 |
using stk::mesh::MetaData; |
| 51 |
|
| 52 |
namespace { |
| 53 |
const size_t nodes_per_hex = 8; |
| 54 |
const size_t faces_per_hex = 6; |
| 55 |
const size_t nodes_per_quad= 4; |
| 56 |
|
| 57 |
size_t exp_hex_face_count(size_t nx, size_t ny, size_t nz) |
| 58 |
{ |
| 59 |
size_t exp_face = 3 * nx * ny * nz; |
| 60 |
exp_face += ny * nz + nz * nx + nx * ny; |
| 61 |
return exp_face; |
| 62 |
} |
| 63 |
|
| 64 |
size_t exp_node_count(size_t nx, size_t ny, size_t nz) |
| 65 |
{ |
| 66 |
size_t exp_node = (nx+1) * (ny+1) * (nz+1); |
| 67 |
return exp_node; |
| 68 |
} |
| 69 |
|
| 70 |
size_t exp_hex_count(size_t nx, size_t ny, size_t nz) |
| 71 |
{ |
| 72 |
size_t exp_elem = nx * ny * nz; |
| 73 |
return exp_elem; |
| 74 |
} |
| 75 |
|
| 76 |
TEST( UnitTestCreateFaces , testSkinAndCreateFaces3x3x3 ) |
| 77 |
{ |
| 78 |
const stk::mesh::EntityRank elem_rank = stk::topology::ELEMENT_RANK; |
| 79 |
const stk::mesh::EntityRank face_rank = stk::topology::FACE_RANK; |
| 80 |
const stk::mesh::EntityRank edge_rank = stk::topology::EDGE_RANK; |
| 81 |
const stk::mesh::EntityRank node_rank = stk::topology::NODE_RANK; |
| 82 |
|
| 83 |
const size_t NX = 3; |
| 84 |
const size_t NY = 3; |
| 85 |
const size_t NZ = 3; |
| 86 |
|
| 87 |
stk::mesh::fixtures::HexFixture fixture( MPI_COMM_WORLD, NX, NY, NZ); |
| 88 |
|
| 89 |
fixture.m_meta.commit(); |
| 90 |
fixture.generate_mesh(); |
| 91 |
|
| 92 |
{ |
| 93 |
std::vector<size_t> counts ; |
| 94 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 95 |
|
| 96 |
EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes |
| 97 |
EXPECT_EQ( 0u, counts[edge_rank] ); // edges |
| 98 |
EXPECT_EQ( 0u, counts[face_rank] ); // faces |
| 99 |
EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements |
| 100 |
} |
| 101 |
|
| 102 |
stk::mesh::skin_mesh(fixture.m_bulk_data); |
| 103 |
{ |
| 104 |
std::vector<size_t> counts ; |
| 105 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 106 |
|
| 107 |
EXPECT_EQ( 64u, counts[node_rank] ); // nodes |
| 108 |
EXPECT_EQ( 0u, counts[edge_rank] ); // edges |
| 109 |
EXPECT_EQ( 54u, counts[face_rank] ); // faces |
| 110 |
EXPECT_EQ( 27u, counts[elem_rank] ); // elements |
| 111 |
} |
| 112 |
|
| 113 |
stk::mesh::create_faces(fixture.m_bulk_data); |
| 114 |
|
| 115 |
{ |
| 116 |
std::vector<size_t> counts ; |
| 117 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 118 |
|
| 119 |
EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes |
| 120 |
EXPECT_EQ( 0u , counts[edge_rank] ); // edges |
| 121 |
EXPECT_EQ( exp_hex_face_count(NX, NY, NZ), counts[face_rank] ); // faces |
| 122 |
EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements |
| 123 |
} |
| 124 |
|
| 125 |
stk::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank); |
| 126 |
for ( stk::mesh::BucketVector::iterator b_itr = elem_buckets.begin(); |
| 127 |
b_itr != elem_buckets.end(); |
| 128 |
++b_itr |
| 129 |
) |
| 130 |
{ |
| 131 |
stk::mesh::Bucket & b = **b_itr; |
| 132 |
for ( size_t i = 0; i< b.size(); ++i) { |
| 133 |
unsigned elem_ordinal = i; |
| 134 |
EXPECT_EQ( faces_per_hex, b.num_faces(elem_ordinal) ); |
| 135 |
EXPECT_EQ( nodes_per_hex, b.num_nodes(elem_ordinal) ); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
stk::mesh::BucketVector face_buckets = fixture.m_bulk_data.buckets(face_rank); |
| 140 |
for ( stk::mesh::BucketVector::iterator b_itr = face_buckets.begin(); |
| 141 |
b_itr != face_buckets.end(); |
| 142 |
++b_itr |
| 143 |
) |
| 144 |
{ |
| 145 |
stk::mesh::Bucket & b = **b_itr; |
| 146 |
for ( size_t i = 0; i< b.size(); ++i) { |
| 147 |
unsigned face_ordinal = i; |
| 148 |
EXPECT_EQ( 0u, b.num_edges(face_ordinal) ); |
| 149 |
EXPECT_EQ( nodes_per_quad, b.num_nodes(face_ordinal) ); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
TEST( UnitTestCreateFaces , testCreateFacesThenSkin3x3x3 ) |
| 157 |
{ |
| 158 |
const stk::mesh::EntityRank elem_rank = stk::topology::ELEMENT_RANK; |
| 159 |
const stk::mesh::EntityRank face_rank = stk::topology::FACE_RANK; |
| 160 |
const stk::mesh::EntityRank edge_rank = stk::topology::EDGE_RANK; |
| 161 |
const stk::mesh::EntityRank node_rank = stk::topology::NODE_RANK; |
| 162 |
|
| 163 |
const size_t NX = 3; |
| 164 |
const size_t NY = 3; |
| 165 |
const size_t NZ = 3; |
| 166 |
|
| 167 |
stk::mesh::fixtures::HexFixture fixture( MPI_COMM_WORLD, NX, NY, NZ); |
| 168 |
|
| 169 |
fixture.m_meta.commit(); |
| 170 |
fixture.generate_mesh(); |
| 171 |
|
| 172 |
{ |
| 173 |
std::vector<size_t> counts ; |
| 174 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 175 |
|
| 176 |
EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes |
| 177 |
EXPECT_EQ( 0u, counts[edge_rank] ); // edges |
| 178 |
EXPECT_EQ( 0u, counts[face_rank] ); // faces |
| 179 |
EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements |
| 180 |
} |
| 181 |
|
| 182 |
stk::mesh::create_faces(fixture.m_bulk_data); |
| 183 |
|
| 184 |
{ |
| 185 |
std::vector<size_t> counts ; |
| 186 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 187 |
|
| 188 |
EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes |
| 189 |
EXPECT_EQ( 0u , counts[edge_rank] ); // edges |
| 190 |
EXPECT_EQ( exp_hex_face_count(NX, NY, NZ), counts[face_rank] ); // faces |
| 191 |
EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements |
| 192 |
} |
| 193 |
|
| 194 |
stk::mesh::skin_mesh(fixture.m_bulk_data); |
| 195 |
|
| 196 |
{ |
| 197 |
std::vector<size_t> counts ; |
| 198 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 199 |
|
| 200 |
EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes |
| 201 |
EXPECT_EQ( 0u , counts[edge_rank] ); // edges |
| 202 |
EXPECT_EQ( exp_hex_face_count(NX, NY, NZ), counts[face_rank] ); // faces |
| 203 |
EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements |
| 204 |
} |
| 205 |
|
| 206 |
stk::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank); |
| 207 |
for ( stk::mesh::BucketVector::iterator b_itr = elem_buckets.begin(); |
| 208 |
b_itr != elem_buckets.end(); |
| 209 |
++b_itr |
| 210 |
) |
| 211 |
{ |
| 212 |
stk::mesh::Bucket & b = **b_itr; |
| 213 |
for ( size_t i = 0; i< b.size(); ++i) { |
| 214 |
unsigned elem_ordinal = i; |
| 215 |
EXPECT_EQ( faces_per_hex, b.num_faces(elem_ordinal) ); |
| 216 |
EXPECT_EQ( nodes_per_hex, b.num_nodes(elem_ordinal) ); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
stk::mesh::BucketVector face_buckets = fixture.m_bulk_data.buckets(face_rank); |
| 221 |
for ( stk::mesh::BucketVector::iterator b_itr = face_buckets.begin(); |
| 222 |
b_itr != face_buckets.end(); |
| 223 |
++b_itr |
| 224 |
) |
| 225 |
{ |
| 226 |
stk::mesh::Bucket & b = **b_itr; |
| 227 |
for ( size_t i = 0; i< b.size(); ++i) { |
| 228 |
unsigned face_ordinal = i; |
| 229 |
EXPECT_EQ( 0u, b.num_edges(face_ordinal) ); |
| 230 |
EXPECT_EQ( nodes_per_quad, b.num_nodes(face_ordinal) ); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
} |
| 235 |
|
| 236 |
} //end empty namespace |
| 237 |
|