Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestGenerateNewEntities.cpp

raw
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 // ####################### Start Clang Header Tool Managed Headers ########################
36 // clang-format off
37 #include <gtest/gtest.h> // for AssertHelper, etc
38 #include <stddef.h> // for size_t
39 #include <stk_mesh/base/BulkData.hpp> // for BulkData
40 #include <stk_mesh/base/MetaData.hpp> // for MetaData
41 #include <stk_util/parallel/Parallel.hpp> // for ParallelMachine
42 #include <vector> // for vector, etc
43 #include "mpi.h" // for MPI_COMM_WORLD, etc
44 #include "stk_mesh/base/Types.hpp" // for EntityVector, etc
45 #include <stk_unit_test_utils/BuildMesh.hpp>
46 // clang-format on
47 // ####################### End Clang Header Tool Managed Headers ########################
48
49 namespace {
50 using stk::unit_test_util::build_mesh;
51
52 TEST( UnitTestStkMeshGenerateNewEntities , testUnit )
53 {
54 // Test BulkData's generate_new_entities method.
55
56 stk::ParallelMachine pm(MPI_COMM_WORLD);
57
58 const int spatial_dimension = 3;
59 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatial_dimension, pm);
60 stk::mesh::MetaData& meta_data = bulkPtr->mesh_meta_data();
61 stk::mesh::BulkData& bulk_data = *bulkPtr;
62
63 meta_data.commit();
64
65 const stk::mesh::PartVector no_parts;
66
67 bulk_data.modification_begin();
68
69 bulk_data.declare_node(bulk_data.parallel_rank() + 1, no_parts);
70
71 bulk_data.modification_end();
72
73 // Create a request vector for 2 new nodes on each processor
74 size_t num_nodes_requested = 2;
75 std::vector<size_t> requests(meta_data.entity_rank_count(), 0);
76 requests[0] = num_nodes_requested;
77
78 bulk_data.modification_begin();
79
80 // generate_new_entities creates new blank entities of the requested ranks
81 stk::mesh::EntityVector new_nodes;
82 bulk_data.generate_new_entities(requests, new_nodes);
83 ASSERT_EQ(new_nodes.size(), num_nodes_requested);
84
85 // confirm that the nodes we created earlier are not in the new entities
86 for (stk::mesh::EntityVector::const_iterator itr = new_nodes.begin();
87 itr != new_nodes.end(); ++itr) {
88 ASSERT_GT(static_cast<int>(bulk_data.identifier(*itr)), bulk_data.parallel_size());
89 }
90
91 bulk_data.modification_end();
92 }
93
94 }