| 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 |
#include <gtest/gtest.h> |
| 36 |
#include <stk_util/parallel/Parallel.hpp> |
| 37 |
#include <stk_mesh/base/BulkData.hpp> |
| 38 |
#include <stk_mesh/base/GetEntities.hpp> |
| 39 |
#include <stk_middle_mesh/create_mesh.hpp> |
| 40 |
#include <stk_middle_mesh_util/create_stk_mesh.hpp> |
| 41 |
#include <stk_unit_test_utils/getOption.h> |
| 42 |
#include <stk_unit_test_utils/timer.hpp> |
| 43 |
|
| 44 |
namespace { |
| 45 |
|
| 46 |
static constexpr int VERT_RANK = 0; |
| 47 |
static constexpr int EDGE_RANK = 1; |
| 48 |
static constexpr int ELEM_RANK = 2; |
| 49 |
|
| 50 |
TEST(MiddleMeshOps, GetAndDeleteDown) |
| 51 |
{ |
| 52 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 53 |
if (stk::middle_mesh::utils::impl::comm_size(comm) > 1) |
| 54 |
GTEST_SKIP(); |
| 55 |
|
| 56 |
const int NUM_RUNS = 40; |
| 57 |
const int NUM_ITERS = 1; |
| 58 |
|
| 59 |
stk::middle_mesh::mesh::impl::MeshSpec spec{1000, 1000, 0, 1, 0, 1}; |
| 60 |
auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; }; |
| 61 |
|
| 62 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 63 |
batchTimer.initialize_batch_timer(); |
| 64 |
for (unsigned i = 0; i < NUM_RUNS; ++i) { |
| 65 |
auto mesh = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 66 |
|
| 67 |
batchTimer.start_batch_timer(); |
| 68 |
|
| 69 |
auto& elements = mesh->get_mesh_entities(ELEM_RANK); |
| 70 |
|
| 71 |
for (auto elem : elements) { |
| 72 |
if (elem == nullptr) { continue; } |
| 73 |
[[maybe_unused]] auto elemId = elem->get_id(); |
| 74 |
auto numEdges = elem->count_down(); |
| 75 |
|
| 76 |
for (auto e = numEdges-1; e > 0; --e) { |
| 77 |
auto edge = elem->get_down(e); |
| 78 |
if (edge == nullptr) { continue; } |
| 79 |
[[maybe_unused]] auto eId = edge->get_id(); |
| 80 |
auto numVerts = edge->count_down(); |
| 81 |
|
| 82 |
for (auto v = numVerts-1; v > 0; --v) { |
| 83 |
auto vert = edge->get_down(v); |
| 84 |
if (vert == nullptr) { continue; } |
| 85 |
[[maybe_unused]] auto vId = vert->get_id(); |
| 86 |
edge->delete_down(v); |
| 87 |
} |
| 88 |
elem->delete_down(e); |
| 89 |
} |
| 90 |
} |
| 91 |
batchTimer.stop_batch_timer(); |
| 92 |
} |
| 93 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 94 |
} |
| 95 |
|
| 96 |
TEST(MiddleMeshOps, GetAndDeleteUp) |
| 97 |
{ |
| 98 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 99 |
if (stk::middle_mesh::utils::impl::comm_size(comm) > 1) |
| 100 |
GTEST_SKIP(); |
| 101 |
|
| 102 |
const int NUM_RUNS = 40; |
| 103 |
const int NUM_ITERS = 1; |
| 104 |
|
| 105 |
stk::middle_mesh::mesh::impl::MeshSpec spec{1000, 1000, 0, 1, 0, 1}; |
| 106 |
auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; }; |
| 107 |
|
| 108 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 109 |
batchTimer.initialize_batch_timer(); |
| 110 |
for (unsigned i = 0; i < NUM_RUNS; ++i) { |
| 111 |
auto mesh = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 112 |
|
| 113 |
batchTimer.start_batch_timer(); |
| 114 |
|
| 115 |
auto& verts = mesh->get_mesh_entities(VERT_RANK); |
| 116 |
|
| 117 |
for (auto vert : verts) { |
| 118 |
if (vert == nullptr) { continue; } |
| 119 |
[[maybe_unused]] auto vId = vert->get_id(); |
| 120 |
auto numEdges = vert->count_up(); |
| 121 |
|
| 122 |
for (auto e = numEdges-1; e > 0; --e) { |
| 123 |
auto edge = vert->get_up(e); |
| 124 |
if (edge == nullptr) { continue; } |
| 125 |
[[maybe_unused]] auto eId = edge->get_id(); |
| 126 |
auto numElems = edge->count_up(); |
| 127 |
|
| 128 |
for (auto el = numElems-1; el > 0; --el) { |
| 129 |
auto elem = edge->get_up(el); |
| 130 |
if (elem == nullptr) { continue; } |
| 131 |
[[maybe_unused]] auto elemId = elem->get_id(); |
| 132 |
edge->delete_up(el); |
| 133 |
} |
| 134 |
vert->delete_up(e); |
| 135 |
} |
| 136 |
} |
| 137 |
batchTimer.stop_batch_timer(); |
| 138 |
} |
| 139 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 140 |
} |
| 141 |
|
| 142 |
TEST(MiddleMeshOps, GetUpward) |
| 143 |
{ |
| 144 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 145 |
if (stk::middle_mesh::utils::impl::comm_size(comm) > 1) |
| 146 |
GTEST_SKIP(); |
| 147 |
|
| 148 |
const int NUM_RUNS = 25; |
| 149 |
const int NUM_ITERS = 1; |
| 150 |
|
| 151 |
stk::middle_mesh::mesh::impl::MeshSpec spec{1000, 1000, 0, 1, 0, 1}; |
| 152 |
auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; }; |
| 153 |
|
| 154 |
std::vector<stk::middle_mesh::mesh::MeshEntityPtr> edges, elems; |
| 155 |
|
| 156 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 157 |
batchTimer.initialize_batch_timer(); |
| 158 |
|
| 159 |
auto mesh = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 160 |
|
| 161 |
for (unsigned i = 0; i < NUM_RUNS; ++i) { |
| 162 |
batchTimer.start_batch_timer(); |
| 163 |
auto& verts = mesh->get_mesh_entities(VERT_RANK); |
| 164 |
|
| 165 |
for (auto vert : verts) { |
| 166 |
get_upward(vert, EDGE_RANK, edges); |
| 167 |
get_upward(vert, ELEM_RANK, elems); |
| 168 |
|
| 169 |
for (auto edge : edges) { |
| 170 |
get_upward(edge, ELEM_RANK, elems); |
| 171 |
} |
| 172 |
} |
| 173 |
batchTimer.stop_batch_timer(); |
| 174 |
} |
| 175 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 176 |
} |
| 177 |
|
| 178 |
TEST(MiddleMeshOps, GetDownward) |
| 179 |
{ |
| 180 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 181 |
if (stk::middle_mesh::utils::impl::comm_size(comm) > 1) |
| 182 |
GTEST_SKIP(); |
| 183 |
|
| 184 |
const int NUM_RUNS = 50; |
| 185 |
const int NUM_ITERS = 1; |
| 186 |
|
| 187 |
stk::middle_mesh::mesh::impl::MeshSpec spec{1000, 1000, 0, 1, 0, 1}; |
| 188 |
auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; }; |
| 189 |
|
| 190 |
std::vector<stk::middle_mesh::mesh::MeshEntityPtr> edges, verts; |
| 191 |
|
| 192 |
edges.resize(stk::middle_mesh::mesh::MAX_DOWN); |
| 193 |
verts.resize(stk::middle_mesh::mesh::MAX_DOWN); |
| 194 |
|
| 195 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 196 |
batchTimer.initialize_batch_timer(); |
| 197 |
|
| 198 |
auto mesh = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 199 |
|
| 200 |
for (unsigned i = 0; i < NUM_RUNS; ++i) { |
| 201 |
batchTimer.start_batch_timer(); |
| 202 |
auto& elems = mesh->get_mesh_entities(ELEM_RANK); |
| 203 |
|
| 204 |
for (auto elem : elems) { |
| 205 |
get_downward(elem, EDGE_RANK, edges.data()); |
| 206 |
get_downward(elem, VERT_RANK, verts.data()); |
| 207 |
|
| 208 |
for (auto edge : edges) { |
| 209 |
get_downward(edge, VERT_RANK, verts.data()); |
| 210 |
} |
| 211 |
} |
| 212 |
batchTimer.stop_batch_timer(); |
| 213 |
} |
| 214 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 215 |
} |
| 216 |
|
| 217 |
} |