| 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/CreateEdges.hpp> // for create_edges |
| 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 |
#include "stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp" // for QuadFixture |
| 50 |
|
| 51 |
using stk::mesh::MetaData; |
| 52 |
|
| 53 |
TEST ( UnitTestCreateEdges, Quad_2x2 ) |
| 54 |
{ |
| 55 |
stk::mesh::fixtures::QuadFixture fixture( MPI_COMM_WORLD, 2, 2); |
| 56 |
|
| 57 |
fixture.m_meta.commit(); |
| 58 |
fixture.generate_mesh(); |
| 59 |
|
| 60 |
stk::mesh::skin_mesh(fixture.m_bulk_data); |
| 61 |
|
| 62 |
{ |
| 63 |
std::vector<size_t> counts ; |
| 64 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 65 |
|
| 66 |
EXPECT_EQ( counts[0] , 9u ); // nodes |
| 67 |
EXPECT_EQ( counts[1] , 8u ); // edges |
| 68 |
EXPECT_EQ( counts[2] , 0u ); // faces |
| 69 |
EXPECT_EQ( counts[3] , 4u ); // elements |
| 70 |
} |
| 71 |
|
| 72 |
stk::mesh::create_edges(fixture.m_bulk_data); |
| 73 |
|
| 74 |
{ |
| 75 |
std::vector<size_t> counts ; |
| 76 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 77 |
|
| 78 |
EXPECT_EQ( counts[0] , 9u ); // nodes |
| 79 |
EXPECT_EQ( counts[1] , 12u ); // edges |
| 80 |
EXPECT_EQ( counts[2] , 0u ); // faces |
| 81 |
EXPECT_EQ( counts[3] , 4u ); // elements |
| 82 |
} |
| 83 |
|
| 84 |
//shouldn't do anything |
| 85 |
stk::mesh::create_edges(fixture.m_bulk_data); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
TEST( UnitTestCreateEdges , testSkinAndCreateEdges3x3x3 ) |
| 90 |
{ |
| 91 |
const stk::mesh::EntityRank elem_rank = stk::topology::ELEMENT_RANK; |
| 92 |
const stk::mesh::EntityRank face_rank = stk::topology::FACE_RANK; |
| 93 |
const stk::mesh::EntityRank edge_rank = stk::topology::EDGE_RANK; |
| 94 |
const stk::mesh::EntityRank node_rank = stk::topology::NODE_RANK; |
| 95 |
|
| 96 |
const size_t NX = 3; |
| 97 |
const size_t NY = 3; |
| 98 |
const size_t NZ = 3; |
| 99 |
|
| 100 |
stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, NX, NY, NZ); |
| 101 |
|
| 102 |
fixture.m_meta.commit(); |
| 103 |
fixture.generate_mesh(); |
| 104 |
|
| 105 |
{ |
| 106 |
std::vector<size_t> counts ; |
| 107 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 108 |
|
| 109 |
EXPECT_EQ( counts[node_rank] , 64u ); // nodes |
| 110 |
EXPECT_EQ( counts[edge_rank] , 0u ); // edges |
| 111 |
EXPECT_EQ( counts[face_rank] , 0u ); // faces |
| 112 |
EXPECT_EQ( counts[elem_rank] , 27u ); // elements |
| 113 |
} |
| 114 |
|
| 115 |
stk::mesh::skin_mesh(fixture.m_bulk_data); |
| 116 |
stk::mesh::create_edges(fixture.m_bulk_data); |
| 117 |
|
| 118 |
{ |
| 119 |
std::vector<size_t> counts ; |
| 120 |
stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts); |
| 121 |
|
| 122 |
EXPECT_EQ( 64u, counts[node_rank] ); // nodes |
| 123 |
EXPECT_EQ( 144u, counts[edge_rank] ); // edges |
| 124 |
EXPECT_EQ( 54u, counts[face_rank] ); // faces |
| 125 |
EXPECT_EQ( 27u, counts[elem_rank] ); // elements |
| 126 |
} |
| 127 |
|
| 128 |
stk::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank); |
| 129 |
for ( stk::mesh::BucketVector::iterator b_itr = elem_buckets.begin(); |
| 130 |
b_itr != elem_buckets.end(); |
| 131 |
++b_itr |
| 132 |
) |
| 133 |
{ |
| 134 |
stk::mesh::Bucket & b = **b_itr; |
| 135 |
for ( size_t i = 0; i< b.size(); ++i) { |
| 136 |
unsigned elem_ordinal = i; |
| 137 |
EXPECT_EQ( 12u, b.num_edges(elem_ordinal) ); |
| 138 |
EXPECT_EQ( 8u, b.num_nodes(elem_ordinal) ); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
stk::mesh::BucketVector face_buckets = fixture.m_bulk_data.buckets(face_rank); |
| 143 |
for ( stk::mesh::BucketVector::iterator b_itr = face_buckets.begin(); |
| 144 |
b_itr != face_buckets.end(); |
| 145 |
++b_itr |
| 146 |
) |
| 147 |
{ |
| 148 |
stk::mesh::Bucket & b = **b_itr; |
| 149 |
for ( size_t i = 0; i< b.size(); ++i) { |
| 150 |
unsigned face_ordinal = i; |
| 151 |
EXPECT_EQ( 4u, b.num_edges(face_ordinal) ); |
| 152 |
EXPECT_EQ( 4u, b.num_nodes(face_ordinal) ); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
stk::mesh::BucketVector edge_buckets = fixture.m_bulk_data.buckets(edge_rank); |
| 157 |
for ( stk::mesh::BucketVector::iterator b_itr = edge_buckets.begin(); |
| 158 |
b_itr != edge_buckets.end(); |
| 159 |
++b_itr |
| 160 |
) |
| 161 |
{ |
| 162 |
stk::mesh::Bucket & b = **b_itr; |
| 163 |
for ( size_t i = 0; i< b.size(); ++i) { |
| 164 |
unsigned edge_ordinal = i; |
| 165 |
EXPECT_EQ( 2u, b.num_nodes(edge_ordinal) ); |
| 166 |
} |
| 167 |
} |
| 168 |
} |