Debian Codegraph @

packages/stk/stk_performance_tests/stk_mesh/HexRefine.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 #ifndef __IBMCPP__
36 #include <gtest/gtest.h>
37 #include <unordered_map>
38
39 #include <stk_mesh/base/BulkData.hpp>
40 #include <stk_mesh/base/GetEntities.hpp>
41 #include <stk_mesh/base/FEMHelpers.hpp>
42
43 #include "stk_unit_test_utils/stk_mesh_fixtures/HexFixture.hpp"
44
45 #include <stk_util/environment/CPUTime.hpp>
46 #include <stk_util/environment/perf_util.hpp>
47
48 #include <stk_performance_tests/stk_mesh/calculate_centroid.hpp>
49 #include <stk_performance_tests/stk_mesh/hex_refine_info.hpp>
50
51 #include <iostream>
52
53 using namespace stk::mesh;
54
55 namespace stk {
56 namespace performance_tests {
57
58 namespace {
59
60 void create_entities( BulkData & bulk,
61 PartVector& node_parts,
62 PartVector& elem_parts,
63 // FIXME Part& active_elements_part,
64 HexRefineInfo& refine_info)
65 {
66 HexRefineInfo refine_info_half(refine_info.m_level-1, refine_info.m_nx, refine_info.m_ny, refine_info.m_nz);
67
68 unsigned eid_start = 1 + refine_info.elem_id_offset();
69 unsigned eid_end = eid_start + refine_info.num_elems();
70
71 unsigned nid_start = 1 + refine_info.node_id_offset();
72 unsigned nid_end = nid_start + refine_info.num_nodes();
73
74 std::unordered_map<unsigned, Entity> node_map;
75
76 for(unsigned nid=nid_start; nid<nid_end; ++nid) {
77 Entity e = bulk.declare_node(nid, node_parts);
78 node_map[nid] = e;
79 }
80
81 EntityIdVector elem_node(8);
82 for (unsigned entity_id = eid_start; entity_id < eid_end; ++entity_id) {
83 unsigned ix = 0, iy = 0, iz = 0;
84 refine_info.elem_x_y_z(entity_id, ix, iy, iz);
85 EntityId ie_check = refine_info.elem_id(ix, iy, iz);
86 EXPECT_EQ(ie_check, entity_id);
87
88 elem_node[0] = refine_info.node_id( ix , iy , iz );
89 elem_node[1] = refine_info.node_id( ix+1 , iy , iz );
90 elem_node[2] = refine_info.node_id( ix+1 , iy , iz+1 );
91 elem_node[3] = refine_info.node_id( ix , iy , iz+1 );
92 elem_node[4] = refine_info.node_id( ix , iy+1 , iz );
93 elem_node[5] = refine_info.node_id( ix+1 , iy+1 , iz );
94 elem_node[6] = refine_info.node_id( ix+1 , iy+1 , iz+1 );
95 elem_node[7] = refine_info.node_id( ix , iy+1 , iz+1 );
96
97 // check if a parent node
98 for (unsigned i = 0; i<8; ++i) {
99 unsigned ixn = 0, iyn = 0, izn = 0;
100 refine_info.node_x_y_z(elem_node[i], ixn, iyn, izn);
101 EntityId in_check = refine_info.node_id(ixn, iyn, izn);
102 EXPECT_EQ(in_check, elem_node[i]);
103
104 if (
105 ((ixn - 1) % 2 == 0) &&
106 ((iyn - 1) % 2 == 0) &&
107 ((izn - 1) % 2 == 0))
108 {
109 elem_node[i] = refine_info_half.node_id(ixn/2, iyn/2, izn/2);
110 }
111 }
112
113 stk::mesh::declare_element( bulk, elem_parts, entity_id , elem_node);
114 }
115 }
116
117 } // empty namespace
118
119 TEST( hex_refine, hex_refine)
120 {
121 double start_time = stk::cpu_time();
122 const int max_levels = 2;
123 unsigned nn = 100/(1 << (max_levels-1));
124 unsigned ex=nn, ey=nn, ez=nn;
125
126 fixtures::HexFixture fixture(MPI_COMM_WORLD, ex, ey, ez);
127 fixture.m_meta.commit();
128 fixture.generate_mesh();
129 double create_time = stk::cpu_time() - start_time;
130
131 std::vector<double> avg_centroid(3, 0.0);
132
133 start_time = stk::cpu_time();
134
135 for (int level=1; level <= max_levels; ++level) {
136
137 HexRefineInfo refine_info(level, ex, ey, ez);
138
139 //Selector hex_elem_selector(fixture.m_hex_part & !fixture.m_node_part);
140
141 unsigned num_elems_new = refine_info.num_elems();
142 std::cout << "num_elems_new for level = " << level << " = " << num_elems_new << std::endl;
143 fixture.m_bulk_data.modification_begin();
144 create_entities(fixture.m_bulk_data, fixture.m_node_parts, fixture.m_elem_parts, refine_info);
145 fixture.m_bulk_data.modification_end();
146 }
147
148 double refine_time = stk::cpu_time() - start_time;
149 double total_time = refine_time + create_time;
150
151 static const int NUM_TIMERS = 3;
152 const double timers[NUM_TIMERS] = {create_time, refine_time, total_time};
153 const char* timer_names[NUM_TIMERS] = {"Create mesh", "Refine", "Total time"};
154
155 stk::print_timers_and_memory(timer_names, timers, NUM_TIMERS);
156
157 stk::parallel_print_time_without_output_and_hwm(MPI_COMM_WORLD, total_time);
158 }
159
160 } // namespace performance_tests
161 } // namespace std
162
163 #endif