Debian Codegraph @

packages/stk/stk_performance_tests/stk_mesh/NodeRels.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 #include <stk_util/environment/CPUTime.hpp>
36 #include <gtest/gtest.h>
37 #include <stk_util/environment/perf_util.hpp>
38
39 #include <stk_io/util/Gmesh_STKmesh_Fixture.hpp>
40
41 #include <stk_mesh/base/Relation.hpp>
42 #include <stk_mesh/base/Entity.hpp>
43 #include <stk_mesh/base/BulkData.hpp>
44 #include <stk_mesh/base/Selector.hpp>
45 #include <stk_mesh/base/MetaData.hpp>
46
47 #include <sstream>
48
49 //This very simple test will visit all local elements and traverse the
50 //element's node relations. It will return the number of nodes visited.
51 //The purpose of this test is to stress the relation-traversal for a
52 //performance test.
53 size_t do_stk_node_rel_test(stk::mesh::BulkData& bulk)
54 {
55 using namespace stk::mesh;
56
57 const MetaData& meta = bulk.mesh_meta_data();
58
59 Selector local = meta.locally_owned_part();
60
61 BucketVector const& buckets = bulk.get_buckets(stk::topology::ELEMENT_RANK, local);
62
63 size_t nodes_visited = 0;
64
65 for(size_t ib=0; ib<buckets.size(); ++ib) {
66 const Bucket& b = *buckets[ib];
67
68 for(size_t i=0; i<b.size(); ++i) {
69 Entity const *node_itr = b.begin_nodes(i);
70 Entity const *nodes_end = b.end_nodes(i);
71
72 for (; node_itr != nodes_end; ++node_itr)
73 {
74 Entity node = *node_itr;
75 EXPECT_TRUE(bulk.is_valid(node));
76 ++nodes_visited;
77 }
78 }
79 }
80 return nodes_visited;
81 }
82
83 TEST(node_rels, node_rels)
84 {
85 //vector of mesh-dimensions holds the number of elements in each dimension.
86 //Hard-wired to 3. This test can run with spatial-dimension less than 3,
87 //(if generated-mesh can do that) but not greater than 3.
88 std::vector<int> mesh_dims(3);
89 #ifndef NDEBUG
90 mesh_dims[0]=50; //num_elems_x
91 mesh_dims[1]=50; //num_elems_y
92 mesh_dims[2]=50; //num_elems_z
93 #else
94 mesh_dims[0]=150; //num_elems_x
95 mesh_dims[1]=150; //num_elems_y
96 mesh_dims[2]=150; //num_elems_z
97 #endif
98
99 std::ostringstream oss;
100 oss << mesh_dims[0] << "x" << mesh_dims[1] << "x" << mesh_dims[2] << "|sideset:xXyYzZ";
101
102 double start_time = stk::cpu_time();
103
104 stk::io::util::Gmesh_STKmesh_Fixture fixture(MPI_COMM_WORLD, oss.str());
105 fixture.commit();
106
107 double mesh_create_time = stk::cpu_time() - start_time;
108
109 //compute total number of elements in the mesh:
110 const size_t spatial_dim = fixture.getMetaData().spatial_dimension();
111 size_t num_elems = mesh_dims[0];
112 for(size_t d=1; d<spatial_dim; ++d) {
113 num_elems *= mesh_dims[d];
114 }
115
116 std::cout << "num_elems: " << num_elems << std::endl;
117 std::cout << "sizeof(stk::mesh::Relation): " << sizeof(stk::mesh::Relation) << std::endl;
118 std::cout << "sizeof(stk::mesh::Entity): " << sizeof(stk::mesh::Entity) << std::endl;
119
120 start_time = stk::cpu_time();
121
122 const int num_iters = 50;
123 for(int t=0; t<num_iters; ++t) {
124
125 size_t nodes_visited = do_stk_node_rel_test(fixture.getBulkData());
126 size_t expected_nodes_visited = num_elems*8;
127
128 EXPECT_EQ(nodes_visited, expected_nodes_visited);
129 }
130
131 double traverse_time = stk::cpu_time() - start_time;
132 double total_time = mesh_create_time + traverse_time;
133
134 static const int NUM_TIMERS = 3;
135 const double timers[NUM_TIMERS] = {mesh_create_time, traverse_time, total_time};
136 const char* timer_names[NUM_TIMERS] = {"Create mesh", "Traverse", "Total time"};
137
138 stk::print_timers_and_memory(timer_names, timers, NUM_TIMERS);
139
140 stk::parallel_print_time_without_output_and_hwm(MPI_COMM_WORLD, total_time);
141 }