Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
view/HexElement.hpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos: Manycore Performance-Portable Multidimensional Arrays
6 // Copyright (2012) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_HEXELEMENT_HPP
45 #define KOKKOS_HEXELEMENT_HPP
46 
47 namespace Kokkos {
48 namespace Example {
49 
50 template< unsigned NodeCount >
51 class HexElement_TensorData ;
52 
53 template< unsigned NodeCount , class Device >
54 class HexElement_TensorEval ;
55 
56 //----------------------------------------------------------------------------
58 template<>
59 class HexElement_TensorData< 8 > {
60 public:
61 
62  static const unsigned element_node_count = 8 ;
63  static const unsigned spatial_dimension = 3 ;
64  static const unsigned integration_count_1d = 2 ;
65  static const unsigned function_count_1d = 2 ;
66 
67  double values_1d [ function_count_1d ][ integration_count_1d ];
68  double derivs_1d [ function_count_1d ][ integration_count_1d ];
69  double weights_1d[ integration_count_1d ];
70 
71  unsigned char eval_map[ element_node_count ][4] ;
72 
73  static double eval_value_1d( const unsigned jf , const double x )
74  {
75  return 0 == jf ? 0.5 * ( 1.0 - x ) : (
76  1 == jf ? 0.5 * ( 1.0 + x ) : 0 );
77  }
78 
79  static double eval_deriv_1d( const unsigned jf , const double )
80  {
81  return 0 == jf ? -0.5 : (
82  1 == jf ? 0.5 : 0 );
83  }
84 
86  {
87  const unsigned char tmp_map[ element_node_count ][ spatial_dimension ] =
88  { { 0 , 0 , 0 },
89  { 1 , 0 , 0 },
90  { 1 , 1 , 0 },
91  { 0 , 1 , 0 },
92  { 0 , 0 , 1 },
93  { 1 , 0 , 1 },
94  { 1 , 1 , 1 },
95  { 0 , 1 , 1 } };
96 
97  weights_1d[0] = 1 ;
98  weights_1d[1] = 1 ;
99 
100  const double points_1d[ integration_count_1d ] =
101  { -0.577350269189623 , 0.577350269189623 };
102 
103  for ( unsigned i = 0 ; i < element_node_count ; ++i ) {
104  eval_map[i][0] = tmp_map[i][0];
105  eval_map[i][1] = tmp_map[i][1];
106  eval_map[i][2] = tmp_map[i][2];
107  }
108 
109  for ( unsigned xp = 0 ; xp < integration_count_1d ; ++xp ) {
110  for ( unsigned xf = 0 ; xf < function_count_1d ; ++xf ) {
111  values_1d[xp][xf] = eval_value_1d( xf , points_1d[xp] );
112  derivs_1d[xp][xf] = eval_deriv_1d( xf , points_1d[xp] );
113  }}
114  }
115 };
116 
117 //----------------------------------------------------------------------------
118 
119 template<>
120 class HexElement_TensorData< 27 > {
121 public:
122 
123  static const unsigned element_node_count = 27 ;
124  static const unsigned spatial_dimension = 3 ;
125  static const unsigned integration_count_1d = 3 ;
126  static const unsigned function_count_1d = 3 ;
127 
128  double values_1d [ function_count_1d ][ integration_count_1d ];
129  double derivs_1d [ function_count_1d ][ integration_count_1d ];
130  double weights_1d[ integration_count_1d ];
131 
132  unsigned char eval_map[ element_node_count ][4] ;
133 
134  // sizeof(EvaluateElementHex) = 111 bytes =
135  // sizeof(double) * 9 +
136  // sizeof(double) * 9 +
137  // sizeof(double) * 3 +
138  // sizeof(char) * 27
139 
140  static double eval_value_1d( const unsigned jf , const double p )
141  {
142  return 0 == jf ? 0.5 * p * ( p - 1 ) : (
143  1 == jf ? 1.0 - p * p : (
144  2 == jf ? 0.5 * p * ( p + 1 ) : 0 ));
145  }
146 
147  static double eval_deriv_1d( const unsigned jf , const double p )
148  {
149  return 0 == jf ? p - 0.5 : (
150  1 == jf ? -2.0 * p : (
151  2 == jf ? p + 0.5 : 0 ));
152  }
153 
155  {
156  const unsigned char tmp_map[ element_node_count ][ spatial_dimension ] =
157  { { 0 , 0 , 0 },
158  { 2 , 0 , 0 },
159  { 2 , 2 , 0 },
160  { 0 , 2 , 0 },
161  { 0 , 0 , 2 },
162  { 2 , 0 , 2 },
163  { 2 , 2 , 2 },
164  { 0 , 2 , 2 },
165  { 1 , 0 , 0 },
166  { 2 , 1 , 0 },
167  { 1 , 2 , 0 },
168  { 0 , 1 , 0 },
169  { 0 , 0 , 1 },
170  { 2 , 0 , 1 },
171  { 2 , 2 , 1 },
172  { 0 , 2 , 1 },
173  { 1 , 0 , 2 },
174  { 2 , 1 , 2 },
175  { 1 , 2 , 2 },
176  { 0 , 1 , 2 },
177  { 1 , 1 , 1 },
178  { 1 , 1 , 0 },
179  { 1 , 1 , 2 },
180  { 0 , 1 , 1 },
181  { 2 , 1 , 1 },
182  { 1 , 0 , 1 },
183  { 1 , 2 , 1 } };
184 
185  // Interval [-1,1]
186 
187  weights_1d[0] = 0.55555555555556 ;
188  weights_1d[1] = 0.88888888888889 ;
189  weights_1d[2] = 0.55555555555556 ;
190 
191  const double points_1d[3] = { -0.774596669241483 ,
192  0.000000000000000 ,
193  0.774596669241483 };
194 
195  for ( unsigned i = 0 ; i < element_node_count ; ++i ) {
196  eval_map[i][0] = tmp_map[i][0];
197  eval_map[i][1] = tmp_map[i][1];
198  eval_map[i][2] = tmp_map[i][2];
199  }
200 
201  for ( unsigned xp = 0 ; xp < integration_count_1d ; ++xp ) {
202  for ( unsigned xf = 0 ; xf < function_count_1d ; ++xf ) {
203  values_1d[xp][xf] = eval_value_1d( xf , points_1d[xp] );
204  derivs_1d[xp][xf] = eval_deriv_1d( xf , points_1d[xp] );
205  }}
206  }
207 };
208 
209 //----------------------------------------------------------------------------
210 
211 template< unsigned NodeCount >
212 class HexElement_Data {
213 public:
214  static const unsigned spatial_dimension = 3 ;
215  static const unsigned element_node_count = NodeCount ;
216  static const unsigned integration_count = NodeCount ;
217  static const unsigned function_count = NodeCount ;
218 
219  double weights[ integration_count ] ;
222 
224  {
226 
227  for ( unsigned ip = 0 ; ip < integration_count ; ++ip ) {
228 
229  const unsigned ipx = tensor_data.eval_map[ip][0] ;
230  const unsigned ipy = tensor_data.eval_map[ip][1] ;
231  const unsigned ipz = tensor_data.eval_map[ip][2] ;
232 
233  weights[ip] = tensor_data.weights_1d[ ipx ] *
234  tensor_data.weights_1d[ ipy ] *
235  tensor_data.weights_1d[ ipz ] ;
236 
237  for ( unsigned jf = 0 ; jf < function_count ; ++jf ) {
238 
239  const unsigned jfx = tensor_data.eval_map[jf][0] ;
240  const unsigned jfy = tensor_data.eval_map[jf][1] ;
241  const unsigned jfz = tensor_data.eval_map[jf][2] ;
242 
243  values[ip][jf] = tensor_data.values_1d[ ipx ][ jfx ] *
244  tensor_data.values_1d[ ipy ][ jfy ] *
245  tensor_data.values_1d[ ipz ][ jfz ] ;
246 
247  gradients[ip][0][jf] = tensor_data.derivs_1d[ ipx ][ jfx ] *
248  tensor_data.values_1d[ ipy ][ jfy ] *
249  tensor_data.values_1d[ ipz ][ jfz ] ;
250 
251  gradients[ip][1][jf] = tensor_data.values_1d[ ipx ][ jfx ] *
252  tensor_data.derivs_1d[ ipy ][ jfy ] *
253  tensor_data.values_1d[ ipz ][ jfz ] ;
254 
255  gradients[ip][2][jf] = tensor_data.values_1d[ ipx ][ jfx ] *
256  tensor_data.values_1d[ ipy ][ jfy ] *
257  tensor_data.derivs_1d[ ipz ][ jfz ] ;
258  }
259  }
260  }
261 };
262 
263 //----------------------------------------------------------------------------
264 
265 } /* namespace Example */
266 } /* namespace Kokkos */
267 
268 #endif /* #ifndef KOKKOS_HEXELEMENT_HPP */
269 
270 
double weights[integration_count]
Definition: HexElement.hpp:219
static double eval_value_1d(const unsigned jf, const double p)
static const unsigned element_node_count
Definition: HexElement.hpp:215
static const unsigned function_count
Definition: HexElement.hpp:217
double gradients[integration_count][spatial_dimension][function_count]
Definition: HexElement.hpp:221
static double eval_deriv_1d(const unsigned jf, const double p)
static double eval_value_1d(const unsigned jf, const double x)
static double eval_deriv_1d(const unsigned jf, const double)
double values[integration_count][function_count]
Definition: HexElement.hpp:220
static const unsigned integration_count
Definition: HexElement.hpp:216
static const unsigned spatial_dimension
Definition: HexElement.hpp:214