Debian Codegraph @

packages/stk/stk_performance_tests/stk_mesh/hex_refine_info.hpp

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 hex_refine_info_hpp
36 #define hex_refine_info_hpp
37
38 namespace stk {
39 namespace performance_tests {
40
41 class HexRefineInfo
42 {
43 public:
44 typedef unsigned HRF_EntityId;
45
46 const unsigned m_level;
47 const unsigned m_nx;
48 const unsigned m_ny;
49 const unsigned m_nz;
50 const unsigned m_one_based_offset;
51
52 // nx, ny, nz are the *original* sizes of the mesh
53 HexRefineInfo(unsigned level, unsigned nx, unsigned ny, unsigned nz, unsigned one_based_offset=1)
54 : m_level(level), m_nx(nx), m_ny(ny), m_nz(nz), m_one_based_offset(one_based_offset)
55 {
56
57 }
58
59 #define POW3(x) ((x)*(x)*(x))
60
61 HRF_EntityId elem_id_offset(unsigned level) const
62 {
63 if (level == 0)
64 return 0;
65 else
66 return elem_id_offset(level-1) + m_nx*m_ny*m_nz*POW3(1u << (level-1));
67 }
68
69 HRF_EntityId elem_id_offset() const
70 {
71 return elem_id_offset(m_level);
72 }
73
74 HRF_EntityId node_id_offset(unsigned level) const
75 {
76 if (level == 0)
77 return 0;
78 else
79 return node_id_offset(level-1) + (m_nx+1)*(m_ny+1)*(m_nz+1)*POW3(1u << (level-1));
80 }
81
82 HRF_EntityId node_id_offset() const
83 {
84 return node_id_offset(m_level);
85 }
86
87 unsigned lnx() const { return m_nx*(1u<<m_level); }
88 unsigned lny() const { return m_ny*(1u<<m_level); }
89 unsigned lnz() const { return m_nz*(1u<<m_level); }
90 unsigned num_nodes() const { return (1+lnx())*(1+lny())*(1+lnz()); }
91 unsigned num_elems() const { return lnx()*lny()*lnz(); }
92 /**
93 * Thinking in terms of a 3D grid of nodes, get the id of the node in
94 * the (x, y, z) position.
95 */
96 HRF_EntityId node_id( unsigned x , unsigned y , unsigned z ) const {
97 return node_id_offset() + m_one_based_offset + x + ( lnx() + 1 ) * ( y + ( lny() + 1 ) * z );
98 }
99
100 /**
101 * Thinking in terms of a 3D grid of elements, get the id of the
102 * element in the (x, y, z) position.
103 */
104 HRF_EntityId elem_id( unsigned x , unsigned y , unsigned z ) const {
105 return elem_id_offset() + m_one_based_offset + x + lnx() * ( y + lny() * z );
106 }
107
108 /**
109 * Thinking in terms of a 3D grid of nodes, compute the (x, y, z) position
110 * of a node given it's id.
111 */
112 void node_x_y_z( HRF_EntityId entity_id, unsigned &x , unsigned &y , unsigned &z ) const
113 {
114 entity_id -= m_one_based_offset;
115 entity_id -= node_id_offset();
116
117 x = entity_id % (lnx()+1);
118 entity_id /= (lnx()+1);
119
120 y = entity_id % (lny()+1);
121 entity_id /= (lny()+1);
122
123 z = entity_id;
124 }
125
126 /**
127 * Thinking in terms of a 3D grid of elements, compute the (x, y, z) position
128 * of an element given it's id.
129 */
130 void elem_x_y_z( HRF_EntityId entity_id, unsigned &x , unsigned &y , unsigned &z ) const
131 {
132 entity_id -= m_one_based_offset;
133 entity_id -= elem_id_offset();
134
135 x = entity_id % lnx();
136 entity_id /= lnx();
137
138 y = entity_id % lny();
139 entity_id /= lny();
140
141 z = entity_id;
142 }
143
144
145 };
146
147 }
148 }
149
150 #endif