| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
|
| 17 |
#ifndef KOKKOS_HEXELEMENT_HPP |
| 18 |
#define KOKKOS_HEXELEMENT_HPP |
| 19 |
|
| 20 |
namespace Kokkos { |
| 21 |
namespace Example { |
| 22 |
|
| 23 |
template< unsigned NodeCount > |
| 24 |
class HexElement_TensorData ; |
| 25 |
|
| 26 |
template< unsigned NodeCount , class Device > |
| 27 |
class HexElement_TensorEval ; |
| 28 |
|
| 29 |
//---------------------------------------------------------------------------- |
| 30 |
/** \brief Evaluate Hex element on interval [-1,1]^3 */ |
| 31 |
template<> |
| 32 |
class HexElement_TensorData< 8 > { |
| 33 |
public: |
| 34 |
|
| 35 |
static const unsigned element_node_count = 8 ; |
| 36 |
static const unsigned spatial_dimension = 3 ; |
| 37 |
static const unsigned integration_count_1d = 2 ; |
| 38 |
static const unsigned function_count_1d = 2 ; |
| 39 |
|
| 40 |
double values_1d [ function_count_1d ][ integration_count_1d ]; |
| 41 |
double derivs_1d [ function_count_1d ][ integration_count_1d ]; |
| 42 |
double weights_1d[ integration_count_1d ]; |
| 43 |
|
| 44 |
unsigned char eval_map[ element_node_count ][4] ; |
| 45 |
|
| 46 |
static double eval_value_1d( const unsigned jf , const double x ) |
| 47 |
{ |
| 48 |
return 0 == jf ? 0.5 * ( 1.0 - x ) : ( |
| 49 |
1 == jf ? 0.5 * ( 1.0 + x ) : 0 ); |
| 50 |
} |
| 51 |
|
| 52 |
static double eval_deriv_1d( const unsigned jf , const double ) |
| 53 |
{ |
| 54 |
return 0 == jf ? -0.5 : ( |
| 55 |
1 == jf ? 0.5 : 0 ); |
| 56 |
} |
| 57 |
|
| 58 |
HexElement_TensorData() |
| 59 |
{ |
| 60 |
const unsigned char tmp_map[ element_node_count ][ spatial_dimension ] = |
| 61 |
{ { 0 , 0 , 0 }, |
| 62 |
{ 1 , 0 , 0 }, |
| 63 |
{ 1 , 1 , 0 }, |
| 64 |
{ 0 , 1 , 0 }, |
| 65 |
{ 0 , 0 , 1 }, |
| 66 |
{ 1 , 0 , 1 }, |
| 67 |
{ 1 , 1 , 1 }, |
| 68 |
{ 0 , 1 , 1 } }; |
| 69 |
|
| 70 |
weights_1d[0] = 1 ; |
| 71 |
weights_1d[1] = 1 ; |
| 72 |
|
| 73 |
const double points_1d[ integration_count_1d ] = |
| 74 |
{ -0.577350269189623 , 0.577350269189623 }; |
| 75 |
|
| 76 |
for ( unsigned i = 0 ; i < element_node_count ; ++i ) { |
| 77 |
eval_map[i][0] = tmp_map[i][0]; |
| 78 |
eval_map[i][1] = tmp_map[i][1]; |
| 79 |
eval_map[i][2] = tmp_map[i][2]; |
| 80 |
} |
| 81 |
|
| 82 |
for ( unsigned xp = 0 ; xp < integration_count_1d ; ++xp ) { |
| 83 |
for ( unsigned xf = 0 ; xf < function_count_1d ; ++xf ) { |
| 84 |
values_1d[xp][xf] = eval_value_1d( xf , points_1d[xp] ); |
| 85 |
derivs_1d[xp][xf] = eval_deriv_1d( xf , points_1d[xp] ); |
| 86 |
}} |
| 87 |
} |
| 88 |
}; |
| 89 |
|
| 90 |
//---------------------------------------------------------------------------- |
| 91 |
|
| 92 |
template<> |
| 93 |
class HexElement_TensorData< 27 > { |
| 94 |
public: |
| 95 |
|
| 96 |
static const unsigned element_node_count = 27 ; |
| 97 |
static const unsigned spatial_dimension = 3 ; |
| 98 |
static const unsigned integration_count_1d = 3 ; |
| 99 |
static const unsigned function_count_1d = 3 ; |
| 100 |
|
| 101 |
double values_1d [ function_count_1d ][ integration_count_1d ]; |
| 102 |
double derivs_1d [ function_count_1d ][ integration_count_1d ]; |
| 103 |
double weights_1d[ integration_count_1d ]; |
| 104 |
|
| 105 |
unsigned char eval_map[ element_node_count ][4] ; |
| 106 |
|
| 107 |
// sizeof(EvaluateElementHex) = 111 bytes = |
| 108 |
// sizeof(double) * 9 + |
| 109 |
// sizeof(double) * 9 + |
| 110 |
// sizeof(double) * 3 + |
| 111 |
// sizeof(char) * 27 |
| 112 |
|
| 113 |
static double eval_value_1d( const unsigned jf , const double p ) |
| 114 |
{ |
| 115 |
return 0 == jf ? 0.5 * p * ( p - 1 ) : ( |
| 116 |
1 == jf ? 1.0 - p * p : ( |
| 117 |
2 == jf ? 0.5 * p * ( p + 1 ) : 0 )); |
| 118 |
} |
| 119 |
|
| 120 |
static double eval_deriv_1d( const unsigned jf , const double p ) |
| 121 |
{ |
| 122 |
return 0 == jf ? p - 0.5 : ( |
| 123 |
1 == jf ? -2.0 * p : ( |
| 124 |
2 == jf ? p + 0.5 : 0 )); |
| 125 |
} |
| 126 |
|
| 127 |
HexElement_TensorData() |
| 128 |
{ |
| 129 |
const unsigned char tmp_map[ element_node_count ][ spatial_dimension ] = |
| 130 |
{ { 0 , 0 , 0 }, |
| 131 |
{ 2 , 0 , 0 }, |
| 132 |
{ 2 , 2 , 0 }, |
| 133 |
{ 0 , 2 , 0 }, |
| 134 |
{ 0 , 0 , 2 }, |
| 135 |
{ 2 , 0 , 2 }, |
| 136 |
{ 2 , 2 , 2 }, |
| 137 |
{ 0 , 2 , 2 }, |
| 138 |
{ 1 , 0 , 0 }, |
| 139 |
{ 2 , 1 , 0 }, |
| 140 |
{ 1 , 2 , 0 }, |
| 141 |
{ 0 , 1 , 0 }, |
| 142 |
{ 0 , 0 , 1 }, |
| 143 |
{ 2 , 0 , 1 }, |
| 144 |
{ 2 , 2 , 1 }, |
| 145 |
{ 0 , 2 , 1 }, |
| 146 |
{ 1 , 0 , 2 }, |
| 147 |
{ 2 , 1 , 2 }, |
| 148 |
{ 1 , 2 , 2 }, |
| 149 |
{ 0 , 1 , 2 }, |
| 150 |
{ 1 , 1 , 1 }, |
| 151 |
{ 1 , 1 , 0 }, |
| 152 |
{ 1 , 1 , 2 }, |
| 153 |
{ 0 , 1 , 1 }, |
| 154 |
{ 2 , 1 , 1 }, |
| 155 |
{ 1 , 0 , 1 }, |
| 156 |
{ 1 , 2 , 1 } }; |
| 157 |
|
| 158 |
// Interval [-1,1] |
| 159 |
|
| 160 |
weights_1d[0] = 0.55555555555556 ; |
| 161 |
weights_1d[1] = 0.88888888888889 ; |
| 162 |
weights_1d[2] = 0.55555555555556 ; |
| 163 |
|
| 164 |
const double points_1d[3] = { -0.774596669241483 , |
| 165 |
0.000000000000000 , |
| 166 |
0.774596669241483 }; |
| 167 |
|
| 168 |
for ( unsigned i = 0 ; i < element_node_count ; ++i ) { |
| 169 |
eval_map[i][0] = tmp_map[i][0]; |
| 170 |
eval_map[i][1] = tmp_map[i][1]; |
| 171 |
eval_map[i][2] = tmp_map[i][2]; |
| 172 |
} |
| 173 |
|
| 174 |
for ( unsigned xp = 0 ; xp < integration_count_1d ; ++xp ) { |
| 175 |
for ( unsigned xf = 0 ; xf < function_count_1d ; ++xf ) { |
| 176 |
values_1d[xp][xf] = eval_value_1d( xf , points_1d[xp] ); |
| 177 |
derivs_1d[xp][xf] = eval_deriv_1d( xf , points_1d[xp] ); |
| 178 |
}} |
| 179 |
} |
| 180 |
}; |
| 181 |
|
| 182 |
//---------------------------------------------------------------------------- |
| 183 |
|
| 184 |
template< unsigned NodeCount > |
| 185 |
class HexElement_Data { |
| 186 |
public: |
| 187 |
static const unsigned spatial_dimension = 3 ; |
| 188 |
static const unsigned element_node_count = NodeCount ; |
| 189 |
static const unsigned integration_count = NodeCount ; |
| 190 |
static const unsigned function_count = NodeCount ; |
| 191 |
|
| 192 |
double weights[ integration_count ] ; |
| 193 |
double values[ integration_count ][ function_count ]; |
| 194 |
double gradients[ integration_count ][ spatial_dimension ][ function_count ]; |
| 195 |
|
| 196 |
HexElement_Data() |
| 197 |
{ |
| 198 |
HexElement_TensorData< NodeCount > tensor_data ; |
| 199 |
|
| 200 |
for ( unsigned ip = 0 ; ip < integration_count ; ++ip ) { |
| 201 |
|
| 202 |
const unsigned ipx = tensor_data.eval_map[ip][0] ; |
| 203 |
const unsigned ipy = tensor_data.eval_map[ip][1] ; |
| 204 |
const unsigned ipz = tensor_data.eval_map[ip][2] ; |
| 205 |
|
| 206 |
weights[ip] = tensor_data.weights_1d[ ipx ] * |
| 207 |
tensor_data.weights_1d[ ipy ] * |
| 208 |
tensor_data.weights_1d[ ipz ] ; |
| 209 |
|
| 210 |
for ( unsigned jf = 0 ; jf < function_count ; ++jf ) { |
| 211 |
|
| 212 |
const unsigned jfx = tensor_data.eval_map[jf][0] ; |
| 213 |
const unsigned jfy = tensor_data.eval_map[jf][1] ; |
| 214 |
const unsigned jfz = tensor_data.eval_map[jf][2] ; |
| 215 |
|
| 216 |
values[ip][jf] = tensor_data.values_1d[ ipx ][ jfx ] * |
| 217 |
tensor_data.values_1d[ ipy ][ jfy ] * |
| 218 |
tensor_data.values_1d[ ipz ][ jfz ] ; |
| 219 |
|
| 220 |
gradients[ip][0][jf] = tensor_data.derivs_1d[ ipx ][ jfx ] * |
| 221 |
tensor_data.values_1d[ ipy ][ jfy ] * |
| 222 |
tensor_data.values_1d[ ipz ][ jfz ] ; |
| 223 |
|
| 224 |
gradients[ip][1][jf] = tensor_data.values_1d[ ipx ][ jfx ] * |
| 225 |
tensor_data.derivs_1d[ ipy ][ jfy ] * |
| 226 |
tensor_data.values_1d[ ipz ][ jfz ] ; |
| 227 |
|
| 228 |
gradients[ip][2][jf] = tensor_data.values_1d[ ipx ][ jfx ] * |
| 229 |
tensor_data.values_1d[ ipy ][ jfy ] * |
| 230 |
tensor_data.derivs_1d[ ipz ][ jfz ] ; |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
}; |
| 235 |
|
| 236 |
//---------------------------------------------------------------------------- |
| 237 |
|
| 238 |
} /* namespace Example */ |
| 239 |
} /* namespace Kokkos */ |
| 240 |
|
| 241 |
#endif /* #ifndef KOKKOS_HEXELEMENT_HPP */ |
| 242 |
|
| 243 |
|