Intrepid2
Intrepid2_CellGeometryTestUtils.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid2 Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kyungjoo Kim (kyukim@sandia.gov),
38 // Mauro Perego (mperego@sandia.gov), or
39 // Nate Roberts (nvrober@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 #ifndef Intrepid2_CellGeometryTestUtils_h
50 #define Intrepid2_CellGeometryTestUtils_h
51 
53 #include "Intrepid2_ScalarView.hpp"
54 
55 #include "Intrepid2_TestUtils.hpp"
56 
57 namespace Intrepid2
58 {
64  template< typename PointScalar, int spaceDim, typename DeviceType >
65  inline
66  CellGeometry<PointScalar, spaceDim, DeviceType> getNodalCellGeometry(CellGeometry<PointScalar, spaceDim, DeviceType> &anyCellGeometry,
67  const bool &copyAffineness)
68  {
69  // copy the nodes from CellGeometry into a raw View
70  const int numCells = anyCellGeometry.extent_int(0);
71  const int numNodes = anyCellGeometry.extent_int(1);
72 
73  using PointScalarView = ScalarView<PointScalar, DeviceType >;
74  using intView = ScalarView< int, DeviceType >;
75 
76  auto cellToNodes = intView ("cell to nodes", numCells, numNodes); // this will be a one-to-one mapping
77  PointScalarView nodes = getView<PointScalar,DeviceType>("nodes", numCells * numNodes, spaceDim); // we store redundant copies of vertices for each cell
78 
79  using ExecutionSpace = typename DeviceType::execution_space;
80  auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<2>>({0,0},{numCells,numNodes});
81 
82  Kokkos::parallel_for("copy cell nodes from CellGeometry", policy,
83  KOKKOS_LAMBDA (const int &cellOrdinal, const int &nodeOrdinalInCell) {
84  const int globalNodeOrdinal = cellOrdinal * numNodes + nodeOrdinalInCell;
85  for (int d=0; d<spaceDim; d++)
86  {
87  nodes(globalNodeOrdinal,d) = anyCellGeometry(cellOrdinal,nodeOrdinalInCell,d);
88  }
89  cellToNodes(cellOrdinal,nodeOrdinalInCell) = globalNodeOrdinal;
90  });
91 
92  ExecutionSpace().fence();
93 
94  const bool claimAffine = copyAffineness && anyCellGeometry.affine();
95  const auto nodeOrdering = anyCellGeometry.nodeOrderingForHypercubes();
96 
97  const auto cellTopology = anyCellGeometry.cellTopology();
98  CellGeometry<PointScalar, spaceDim, DeviceType> nodalCellGeometry(cellTopology,cellToNodes,nodes,claimAffine,nodeOrdering);
99 
100  return nodalCellGeometry;
101  }
102 
108  template<class PointScalar, int spaceDim, typename DeviceType>
109  inline CellGeometry<PointScalar,spaceDim,DeviceType> uniformCartesianMesh(const Kokkos::Array<PointScalar,spaceDim> &domainExtents,
110  const Kokkos::Array<int,spaceDim> &gridCellCounts)
111  {
112  Kokkos::Array<PointScalar,spaceDim> origin;
113  for (int d=0; d<spaceDim; d++)
114  {
115  origin[d] = 0.0;
116  }
117 
119  const auto NO_SUBDIVISION = CellGeometry::NO_SUBDIVISION;
120  const auto HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS = CellGeometry::HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS;
121 
122  return CellGeometry(origin, domainExtents, gridCellCounts, NO_SUBDIVISION, HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS);
123  }
124 
130  template<class PointScalar, int spaceDim, typename DeviceType>
131  inline CellGeometry<PointScalar,spaceDim,DeviceType> uniformCartesianMesh(const PointScalar &domainExtent, const int &meshWidth)
132  {
133  Kokkos::Array<PointScalar,spaceDim> origin;
134  Kokkos::Array<PointScalar,spaceDim> domainExtents;
135  Kokkos::Array<int,spaceDim> gridCellCounts;
136  for (int d=0; d<spaceDim; d++)
137  {
138  origin[d] = 0.0;
139  domainExtents[d] = domainExtent;
140  gridCellCounts[d] = meshWidth;
141  }
142 
144  const auto NO_SUBDIVISION = CellGeometry::NO_SUBDIVISION;
145  const auto HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS = CellGeometry::HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS;
146 
147  return CellGeometry(origin, domainExtents, gridCellCounts, NO_SUBDIVISION, HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS);
148  }
149 } // namespace Intrepid2
150 
151 #endif /* Intrepid2_CellGeometryTestUtils_h */
CellGeometry provides the nodes for a set of cells; has options that support efficient definition of ...
Allows definition of cell geometry information, including uniform and curvilinear mesh definition...
Utility methods for Intrepid2 unit tests.