| 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/stk_config.h> |
| 37 |
|
| 38 |
#ifdef STK_HAVE_INTREPID2 |
| 39 |
|
| 40 |
#include <stk_topology/topology.hpp> |
| 41 |
#include <stk_mesh/base/MetaData.hpp> |
| 42 |
#include <Intrepid2_CellTools.hpp> |
| 43 |
#include <array> |
| 44 |
|
| 45 |
using intrepid2ct = Intrepid2::CellTools<Kokkos::DefaultHostExecutionSpace>; |
| 46 |
|
| 47 |
TEST(SearchUtil, Intrepid2_hasReferenceCell) |
| 48 |
{ |
| 49 |
//volume-elements; i.e., not beams/shells, not 2D tris/quads etc. |
| 50 |
std::array<stk::topology,14> stkVolumeElemTopos = |
| 51 |
{ |
| 52 |
stk::topology::TET_4, |
| 53 |
stk::topology::TET_8, |
| 54 |
stk::topology::TET_10, |
| 55 |
stk::topology::TET_11, |
| 56 |
stk::topology::PYRAMID_5, |
| 57 |
stk::topology::PYRAMID_13, |
| 58 |
stk::topology::PYRAMID_14, |
| 59 |
stk::topology::WEDGE_6, |
| 60 |
stk::topology::WEDGE_12, |
| 61 |
stk::topology::WEDGE_15, |
| 62 |
stk::topology::WEDGE_18, |
| 63 |
stk::topology::HEX_8, |
| 64 |
stk::topology::HEX_20, |
| 65 |
stk::topology::HEX_27 |
| 66 |
}; |
| 67 |
|
| 68 |
for(stk::topology stkElem : stkVolumeElemTopos) { |
| 69 |
shards::CellTopology shardsCellTopo = stk::mesh::get_cell_topology(stkElem); |
| 70 |
if (shardsCellTopo.isValid()) { |
| 71 |
const bool hasReferenceCell = intrepid2ct::hasReferenceCell(shardsCellTopo); |
| 72 |
std::cout<<"stk '"<<stkElem<<"' -> shards '"<<shardsCellTopo.getName() |
| 73 |
<<"' (base "<<shardsCellTopo.getBaseName() |
| 74 |
<<"), hasReferenceCell="<<std::boolalpha<<hasReferenceCell<<std::endl; |
| 75 |
} |
| 76 |
else { |
| 77 |
std::cout<<" !!! stk-topo '"<<stkElem<<"' doesn't map to a valid shards CellTopology. !!!"<<std::endl; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
TEST(SearchUtil, Intrepid2_checkPointwiseInclusion) |
| 83 |
{ |
| 84 |
using Intrepid2FloatView = Kokkos::DynRankView<float,Kokkos::DefaultHostExecutionSpace>; |
| 85 |
using Intrepid2IntView = Kokkos::DynRankView<int,Kokkos::DefaultHostExecutionSpace>; |
| 86 |
|
| 87 |
constexpr unsigned spatialDim=3, numNodes=4, numCells=1, numPoints=2; |
| 88 |
Intrepid2FloatView tet4coords("Tet4Cell", numCells, numNodes, spatialDim); |
| 89 |
Intrepid2FloatView points("Point", numCells, numPoints, spatialDim); |
| 90 |
|
| 91 |
tet4coords(0, 0, 0) = 0.0; |
| 92 |
tet4coords(0, 0, 1) = 0.0; |
| 93 |
tet4coords(0, 0, 2) = 0.0; |
| 94 |
tet4coords(0, 1, 0) = 1.0; |
| 95 |
tet4coords(0, 1, 1) = 0.0; |
| 96 |
tet4coords(0, 1, 2) = 0.0; |
| 97 |
tet4coords(0, 2, 0) = 0.0; |
| 98 |
tet4coords(0, 2, 1) = 1.0; |
| 99 |
tet4coords(0, 2, 2) = 0.0; |
| 100 |
tet4coords(0, 3, 0) = 0.0; |
| 101 |
tet4coords(0, 3, 1) = 0.0; |
| 102 |
tet4coords(0, 3, 2) = 1.0; |
| 103 |
|
| 104 |
points(0, 0, 0) = 0.2; //this point is inside the tet4 |
| 105 |
points(0, 0, 1) = 0.2; |
| 106 |
points(0, 0, 2) = 0.2; |
| 107 |
|
| 108 |
points(0, 1, 0) = 1.2; //this point is NOT inside the tet4 |
| 109 |
points(0, 1, 1) = 1.2; |
| 110 |
points(0, 1, 2) = 1.2; |
| 111 |
|
| 112 |
shards::CellTopology tet4 = stk::mesh::get_cell_topology(stk::topology::TET_4); |
| 113 |
ASSERT_TRUE(tet4.isValid()); |
| 114 |
|
| 115 |
Intrepid2IntView inCell("inCell", numCells, numPoints); |
| 116 |
|
| 117 |
intrepid2ct::checkPointwiseInclusion(inCell, points, tet4coords, tet4); |
| 118 |
|
| 119 |
EXPECT_EQ(1, inCell(0,0)) << "got wrong answer: point 0 should be in Tet4!"; |
| 120 |
EXPECT_EQ(0, inCell(0,1)) << "got wrong answer: point 1 should not be in Tet4!"; |
| 121 |
} |
| 122 |
|
| 123 |
TEST(SearchUtil, Intrepid2_mapToReferenceFrame_checkPointwiseInclusion) |
| 124 |
{ |
| 125 |
using Intrepid2FloatView = Kokkos::DynRankView<float,Kokkos::DefaultHostExecutionSpace>; |
| 126 |
using Intrepid2IntView = Kokkos::DynRankView<int,Kokkos::DefaultHostExecutionSpace>; |
| 127 |
|
| 128 |
constexpr unsigned spatialDim=3, numNodes=4, numCells=1, numPoints=2; |
| 129 |
Intrepid2FloatView tet4coords("Tet4Cell", numCells, numNodes, spatialDim); |
| 130 |
Intrepid2FloatView points("Point", numCells, numPoints, spatialDim); |
| 131 |
Intrepid2FloatView refPoints("Point", numCells, numPoints, spatialDim); |
| 132 |
|
| 133 |
tet4coords(0, 0, 0) = 0.0; |
| 134 |
tet4coords(0, 0, 1) = 0.0; |
| 135 |
tet4coords(0, 0, 2) = 0.0; |
| 136 |
tet4coords(0, 1, 0) = 1.0; |
| 137 |
tet4coords(0, 1, 1) = 0.0; |
| 138 |
tet4coords(0, 1, 2) = 0.0; |
| 139 |
tet4coords(0, 2, 0) = 0.0; |
| 140 |
tet4coords(0, 2, 1) = 1.0; |
| 141 |
tet4coords(0, 2, 2) = 0.0; |
| 142 |
tet4coords(0, 3, 0) = 0.0; |
| 143 |
tet4coords(0, 3, 1) = 0.0; |
| 144 |
tet4coords(0, 3, 2) = 1.0; |
| 145 |
|
| 146 |
points(0, 0, 0) = 0.2; //this point is inside the tet4 |
| 147 |
points(0, 0, 1) = 0.2; |
| 148 |
points(0, 0, 2) = 0.2; |
| 149 |
|
| 150 |
points(0, 1, 0) = 1.2; //this point is NOT inside the tet4 |
| 151 |
points(0, 1, 1) = 1.2; |
| 152 |
points(0, 1, 2) = 1.2; |
| 153 |
|
| 154 |
shards::CellTopology tet4 = stk::mesh::get_cell_topology(stk::topology::TET_4); |
| 155 |
ASSERT_TRUE(tet4.isValid()); |
| 156 |
|
| 157 |
Intrepid2IntView inCell("inCell", numCells, numPoints); |
| 158 |
|
| 159 |
intrepid2ct::mapToReferenceFrame(refPoints, points, tet4coords, tet4); |
| 160 |
intrepid2ct::checkPointwiseInclusion(inCell, refPoints, tet4); |
| 161 |
|
| 162 |
EXPECT_EQ(1, inCell(0,0)) << "got wrong answer: point 0 should be in Tet4!"; |
| 163 |
EXPECT_EQ(0, inCell(0,1)) << "got wrong answer: point 1 should not be in Tet4!"; |
| 164 |
} |
| 165 |
|
| 166 |
#endif // STK_HAVE_INTREPID2 |
| 167 |
|