| 1 |
// Copyright(C) 1999-2022 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include <cstddef> // for size_t, nullptr |
| 8 |
#include <fmt/format.h> |
| 9 |
#include <fmt/ostream.h> |
| 10 |
#include <stdint.h> |
| 11 |
#include <vector> // for vector |
| 12 |
|
| 13 |
#include "Ioss_DatabaseIO.h" // for DatabaseIO |
| 14 |
#include "Ioss_ElementBlock.h" // for ElementBlock |
| 15 |
#include "Ioss_Utils.h" |
| 16 |
|
| 17 |
namespace { |
| 18 |
void comp_grad12x(double *const grad_ptr, const double *const x, const double *const y, |
| 19 |
const double *const z) |
| 20 |
{ |
| 21 |
double R42 = (z[3] - z[1]); |
| 22 |
double R52 = (z[4] - z[1]); |
| 23 |
double R54 = (z[4] - z[3]); |
| 24 |
|
| 25 |
double R63 = (z[5] - z[2]); |
| 26 |
double R83 = (z[7] - z[2]); |
| 27 |
double R86 = (z[7] - z[5]); |
| 28 |
|
| 29 |
double R31 = (z[2] - z[0]); |
| 30 |
double R61 = (z[5] - z[0]); |
| 31 |
double R74 = (z[6] - z[3]); |
| 32 |
|
| 33 |
double R72 = (z[6] - z[1]); |
| 34 |
double R75 = (z[6] - z[4]); |
| 35 |
double R81 = (z[7] - z[0]); |
| 36 |
|
| 37 |
double t1 = (R63 + R54); |
| 38 |
double t2 = (R61 + R74); |
| 39 |
double t3 = (R72 + R81); |
| 40 |
|
| 41 |
double t4 = (R86 + R42); |
| 42 |
double t5 = (R83 + R52); |
| 43 |
double t6 = (R75 + R31); |
| 44 |
|
| 45 |
grad_ptr[0] = |
| 46 |
(y[1] * t1) - (y[2] * R42) - (y[3] * t5) + (y[4] * t4) + (y[5] * R52) - (y[7] * R54); |
| 47 |
grad_ptr[1] = |
| 48 |
(y[2] * t2) + (y[3] * R31) - (y[0] * t1) - (y[5] * t6) + (y[6] * R63) - (y[4] * R61); |
| 49 |
grad_ptr[2] = |
| 50 |
(y[3] * t3) + (y[0] * R42) - (y[1] * t2) - (y[6] * t4) + (y[7] * R74) - (y[5] * R72); |
| 51 |
grad_ptr[3] = |
| 52 |
(y[0] * t5) - (y[1] * R31) - (y[2] * t3) + (y[7] * t6) + (y[4] * R81) - (y[6] * R83); |
| 53 |
grad_ptr[4] = |
| 54 |
(y[5] * t3) + (y[6] * R86) - (y[7] * t2) - (y[0] * t4) - (y[3] * R81) + (y[1] * R61); |
| 55 |
grad_ptr[5] = |
| 56 |
(y[6] * t5) - (y[4] * t3) - (y[7] * R75) + (y[1] * t6) - (y[0] * R52) + (y[2] * R72); |
| 57 |
grad_ptr[6] = |
| 58 |
(y[7] * t1) - (y[5] * t5) - (y[4] * R86) + (y[2] * t4) - (y[1] * R63) + (y[3] * R83); |
| 59 |
grad_ptr[7] = |
| 60 |
(y[4] * t2) - (y[6] * t1) + (y[5] * R75) - (y[3] * t6) - (y[2] * R74) + (y[0] * R54); |
| 61 |
|
| 62 |
R42 = (x[3] - x[1]); |
| 63 |
R52 = (x[4] - x[1]); |
| 64 |
R54 = (x[4] - x[3]); |
| 65 |
|
| 66 |
R63 = (x[5] - x[2]); |
| 67 |
R83 = (x[7] - x[2]); |
| 68 |
R86 = (x[7] - x[5]); |
| 69 |
|
| 70 |
R31 = (x[2] - x[0]); |
| 71 |
R61 = (x[5] - x[0]); |
| 72 |
R74 = (x[6] - x[3]); |
| 73 |
|
| 74 |
R72 = (x[6] - x[1]); |
| 75 |
R75 = (x[6] - x[4]); |
| 76 |
R81 = (x[7] - x[0]); |
| 77 |
|
| 78 |
t1 = (R63 + R54); |
| 79 |
t2 = (R61 + R74); |
| 80 |
t3 = (R72 + R81); |
| 81 |
|
| 82 |
t4 = (R86 + R42); |
| 83 |
t5 = (R83 + R52); |
| 84 |
t6 = (R75 + R31); |
| 85 |
|
| 86 |
grad_ptr[8] = |
| 87 |
(z[1] * t1) - (z[2] * R42) - (z[3] * t5) + (z[4] * t4) + (z[5] * R52) - (z[7] * R54); |
| 88 |
grad_ptr[9] = |
| 89 |
(z[2] * t2) + (z[3] * R31) - (z[0] * t1) - (z[5] * t6) + (z[6] * R63) - (z[4] * R61); |
| 90 |
grad_ptr[10] = |
| 91 |
(z[3] * t3) + (z[0] * R42) - (z[1] * t2) - (z[6] * t4) + (z[7] * R74) - (z[5] * R72); |
| 92 |
grad_ptr[11] = |
| 93 |
(z[0] * t5) - (z[1] * R31) - (z[2] * t3) + (z[7] * t6) + (z[4] * R81) - (z[6] * R83); |
| 94 |
grad_ptr[12] = |
| 95 |
(z[5] * t3) + (z[6] * R86) - (z[7] * t2) - (z[0] * t4) - (z[3] * R81) + (z[1] * R61); |
| 96 |
grad_ptr[13] = |
| 97 |
(z[6] * t5) - (z[4] * t3) - (z[7] * R75) + (z[1] * t6) - (z[0] * R52) + (z[2] * R72); |
| 98 |
grad_ptr[14] = |
| 99 |
(z[7] * t1) - (z[5] * t5) - (z[4] * R86) + (z[2] * t4) - (z[1] * R63) + (z[3] * R83); |
| 100 |
grad_ptr[15] = |
| 101 |
(z[4] * t2) - (z[6] * t1) + (z[5] * R75) - (z[3] * t6) - (z[2] * R74) + (z[0] * R54); |
| 102 |
|
| 103 |
R42 = (y[3] - y[1]); |
| 104 |
R52 = (y[4] - y[1]); |
| 105 |
R54 = (y[4] - y[3]); |
| 106 |
|
| 107 |
R63 = (y[5] - y[2]); |
| 108 |
R83 = (y[7] - y[2]); |
| 109 |
R86 = (y[7] - y[5]); |
| 110 |
|
| 111 |
R31 = (y[2] - y[0]); |
| 112 |
R61 = (y[5] - y[0]); |
| 113 |
R74 = (y[6] - y[3]); |
| 114 |
|
| 115 |
R72 = (y[6] - y[1]); |
| 116 |
R75 = (y[6] - y[4]); |
| 117 |
R81 = (y[7] - y[0]); |
| 118 |
|
| 119 |
t1 = (R63 + R54); |
| 120 |
t2 = (R61 + R74); |
| 121 |
t3 = (R72 + R81); |
| 122 |
|
| 123 |
t4 = (R86 + R42); |
| 124 |
t5 = (R83 + R52); |
| 125 |
t6 = (R75 + R31); |
| 126 |
|
| 127 |
grad_ptr[16] = |
| 128 |
(x[1] * t1) - (x[2] * R42) - (x[3] * t5) + (x[4] * t4) + (x[5] * R52) - (x[7] * R54); |
| 129 |
grad_ptr[17] = |
| 130 |
(x[2] * t2) + (x[3] * R31) - (x[0] * t1) - (x[5] * t6) + (x[6] * R63) - (x[4] * R61); |
| 131 |
grad_ptr[18] = |
| 132 |
(x[3] * t3) + (x[0] * R42) - (x[1] * t2) - (x[6] * t4) + (x[7] * R74) - (x[5] * R72); |
| 133 |
grad_ptr[19] = |
| 134 |
(x[0] * t5) - (x[1] * R31) - (x[2] * t3) + (x[7] * t6) + (x[4] * R81) - (x[6] * R83); |
| 135 |
grad_ptr[20] = |
| 136 |
(x[5] * t3) + (x[6] * R86) - (x[7] * t2) - (x[0] * t4) - (x[3] * R81) + (x[1] * R61); |
| 137 |
grad_ptr[21] = |
| 138 |
(x[6] * t5) - (x[4] * t3) - (x[7] * R75) + (x[1] * t6) - (x[0] * R52) + (x[2] * R72); |
| 139 |
grad_ptr[22] = |
| 140 |
(x[7] * t1) - (x[5] * t5) - (x[4] * R86) + (x[2] * t4) - (x[1] * R63) + (x[3] * R83); |
| 141 |
grad_ptr[23] = |
| 142 |
(x[4] * t2) - (x[6] * t1) + (x[5] * R75) - (x[3] * t6) - (x[2] * R74) + (x[0] * R54); |
| 143 |
} |
| 144 |
|
| 145 |
inline double dot8(const double *const x1, const double *const x2) |
| 146 |
{ |
| 147 |
double d1 = x1[0] * x2[0] + x1[1] * x2[1]; |
| 148 |
double d2 = x1[2] * x2[2] + x1[3] * x2[3]; |
| 149 |
double d4 = x1[4] * x2[4] + x1[5] * x2[5]; |
| 150 |
double d5 = x1[6] * x2[6] + x1[7] * x2[7]; |
| 151 |
return d1 + d2 + d4 + d5; |
| 152 |
} |
| 153 |
} // namespace |
| 154 |
|
| 155 |
template <typename T> |
| 156 |
void hex_volume_internal(Ioss::ElementBlock *block, const std::vector<double> &coordinates, |
| 157 |
const std::vector<T> &connectivity, size_t nelem) |
| 158 |
{ |
| 159 |
const double one12th = 1.0 / 12.0; |
| 160 |
|
| 161 |
double gradop12x[24]; |
| 162 |
double x[8]; |
| 163 |
double y[8]; |
| 164 |
double z[8]; |
| 165 |
std::vector<double> volume(nelem); |
| 166 |
|
| 167 |
size_t t1 = Ioss::Utils::timer(); |
| 168 |
|
| 169 |
size_t count = 0; |
| 170 |
for (size_t ielem = 0; ielem < nelem; ++ielem) { |
| 171 |
if (count++ >= nelem / 100) { |
| 172 |
fmt::print(Ioss::OUTPUT(), "."); |
| 173 |
count = 0; |
| 174 |
} |
| 175 |
for (size_t j = 0; j < 8; j++) { |
| 176 |
size_t node = connectivity[ielem * 8 + j] - 1; |
| 177 |
x[j] = coordinates[node * 3 + 0]; |
| 178 |
y[j] = coordinates[node * 3 + 1]; |
| 179 |
z[j] = coordinates[node * 3 + 2]; |
| 180 |
} |
| 181 |
|
| 182 |
comp_grad12x(&gradop12x[0], x, y, z); |
| 183 |
const double volume12x = dot8(x, &gradop12x[0]); |
| 184 |
volume[ielem] = volume12x * one12th; |
| 185 |
} |
| 186 |
size_t t2 = Ioss::Utils::timer(); |
| 187 |
|
| 188 |
if (nelem > 0) { |
| 189 |
fmt::print(Ioss::OUTPUT(), |
| 190 |
"\n{:12}\tMin volume = {:12} Max volume = {:12} Elements = {:12} Time/Elem = " |
| 191 |
"{:5.3f} micro-sec.\n", |
| 192 |
block->name(), *std::min_element(volume.begin(), volume.end()), |
| 193 |
*std::max_element(volume.begin(), volume.end()), fmt::group_digits(nelem), |
| 194 |
1'000'000 * double(t2 - t1) / nelem); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
void hex_volume(Ioss::ElementBlock *block, const std::vector<double> &coordinates) |
| 199 |
{ |
| 200 |
|
| 201 |
size_t nelem = block->entity_count(); |
| 202 |
if (block->get_database()->int_byte_size_api() == 8) { |
| 203 |
std::vector<int64_t> connectivity(nelem); |
| 204 |
block->get_field_data("connectivity_raw", connectivity); |
| 205 |
hex_volume_internal(block, coordinates, connectivity, nelem); |
| 206 |
} |
| 207 |
else { |
| 208 |
std::vector<int> connectivity(nelem); |
| 209 |
block->get_field_data("connectivity_raw", connectivity); |
| 210 |
hex_volume_internal(block, coordinates, connectivity, nelem); |
| 211 |
} |
| 212 |
} |