| 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 <stk_mesh/base/BulkData.hpp> // for BulkData |
| 37 |
#include <stk_mesh/base/MeshBuilder.hpp> // for MeshBuilder |
| 38 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData, entity_rank_names, etc |
| 39 |
#include <stk_topology/topology.hpp> // for topology, etc |
| 40 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 41 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 42 |
#include "stk_mesh/base/Types.hpp" // for EntityId |
| 43 |
namespace stk { namespace mesh { class Part; } } |
| 44 |
|
| 45 |
namespace { |
| 46 |
|
| 47 |
void declare_element_nodes(stk::mesh::BulkData &mesh, stk::mesh::Entity elem1, stk::mesh::Entity elem2) |
| 48 |
{ |
| 49 |
for(unsigned node_ord = 0; node_ord < 4; ++node_ord) |
| 50 |
{ |
| 51 |
stk::mesh::Entity new_node = mesh.declare_node(node_ord + 100 * mesh.identifier(elem1)); |
| 52 |
mesh.declare_relation(elem1, new_node, node_ord); |
| 53 |
} |
| 54 |
|
| 55 |
for(unsigned node_ord = 0; node_ord < 8; ++node_ord) |
| 56 |
{ |
| 57 |
stk::mesh::Entity new_node2 = mesh.declare_node(node_ord + 100 * mesh.identifier(elem2)); |
| 58 |
mesh.declare_relation(elem2, new_node2, node_ord); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
//-BEGIN |
| 63 |
TEST(stkMeshHowTo, setAndGetTopology) |
| 64 |
{ |
| 65 |
const unsigned spatialDimension = 3; |
| 66 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 67 |
builder.set_spatial_dimension(spatialDimension); |
| 68 |
builder.set_entity_rank_names(stk::mesh::entity_rank_names()); |
| 69 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 70 |
stk::mesh::MetaData& metaData = bulkPtr->mesh_meta_data(); |
| 71 |
stk::mesh::Part &tetPart = metaData.declare_part_with_topology("tet part", stk::topology::TET_4); |
| 72 |
|
| 73 |
stk::mesh::Part &hexPart = metaData.declare_part("existing part with currently unknown topology"); |
| 74 |
// . . . then later assigned |
| 75 |
stk::mesh::set_topology(hexPart, stk::topology::HEX_8); |
| 76 |
|
| 77 |
metaData.commit(); |
| 78 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 79 |
|
| 80 |
bulkData.modification_begin(); |
| 81 |
stk::mesh::EntityId elem1Id = 1, elem2Id = 2; |
| 82 |
stk::mesh::Entity elem1 = bulkData.declare_element(elem1Id, stk::mesh::ConstPartVector{&tetPart}); |
| 83 |
stk::mesh::Entity elem2 = bulkData.declare_element(elem2Id, stk::mesh::ConstPartVector{&hexPart}); |
| 84 |
declare_element_nodes(bulkData, elem1, elem2); |
| 85 |
bulkData.modification_end(); |
| 86 |
|
| 87 |
stk::topology elem1_topology = bulkData.bucket(elem1).topology(); |
| 88 |
stk::topology elem2_topology = bulkData.bucket(elem2).topology(); |
| 89 |
|
| 90 |
EXPECT_EQ(stk::topology::TET_4, elem1_topology); |
| 91 |
EXPECT_EQ(stk::topology::HEX_8, elem2_topology); |
| 92 |
} |
| 93 |
//-END |
| 94 |
} |