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
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  // "workset"
83  Kokkos::parallel_for("copy cell nodes from CellGeometry", policy,
84  KOKKOS_LAMBDA (const int &cellOrdinal, const int &nodeOrdinalInCell) {
85  const int globalNodeOrdinal = cellOrdinal * numNodes + nodeOrdinalInCell;
86  for (int d=0; d<spaceDim; d++)
87  {
88  nodes(globalNodeOrdinal,d) = anyCellGeometry(cellOrdinal,nodeOrdinalInCell,d);
89  }
90  cellToNodes(cellOrdinal,nodeOrdinalInCell) = globalNodeOrdinal;
91  });
92 
93  ExecutionSpace().fence();
94 
95  const bool claimAffine = copyAffineness && anyCellGeometry.affine();
96  const auto nodeOrdering = anyCellGeometry.nodeOrderingForHypercubes();
97 
98  const auto cellTopology = anyCellGeometry.cellTopology();
99  CellGeometry<PointScalar, spaceDim, DeviceType> nodalCellGeometry(cellTopology,cellToNodes,nodes,claimAffine,nodeOrdering);
100 
101  return nodalCellGeometry;
102  }
103 
109  template<class PointScalar, int spaceDim, typename DeviceType>
110  inline CellGeometry<PointScalar,spaceDim,DeviceType> uniformCartesianMesh(const Kokkos::Array<PointScalar,spaceDim> &domainExtents,
111  const Kokkos::Array<int,spaceDim> &gridCellCounts)
112  {
113  Kokkos::Array<PointScalar,spaceDim> origin;
114  for (int d=0; d<spaceDim; d++)
115  {
116  origin[d] = 0.0;
117  }
118 
120  const auto NO_SUBDIVISION = CellGeometry::NO_SUBDIVISION;
121  const auto HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS = CellGeometry::HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS;
122 
123  return CellGeometry(origin, domainExtents, gridCellCounts, NO_SUBDIVISION, HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS);
124  }
125 
131  template<class PointScalar, int spaceDim, typename DeviceType>
132  inline CellGeometry<PointScalar,spaceDim,DeviceType> uniformCartesianMesh(const PointScalar &domainExtent, const int &meshWidth)
133  {
134  Kokkos::Array<PointScalar,spaceDim> origin;
135  Kokkos::Array<PointScalar,spaceDim> domainExtents;
136  Kokkos::Array<int,spaceDim> gridCellCounts;
137  for (int d=0; d<spaceDim; d++)
138  {
139  origin[d] = 0.0;
140  domainExtents[d] = domainExtent;
141  gridCellCounts[d] = meshWidth;
142  }
143 
145  const auto NO_SUBDIVISION = CellGeometry::NO_SUBDIVISION;
146  const auto HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS = CellGeometry::HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS;
147 
148  return CellGeometry(origin, domainExtents, gridCellCounts, NO_SUBDIVISION, HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS);
149  }
150 } // namespace Intrepid2
151 
152 #endif /* Intrepid2_CellGeometryTestUtils_h */
const shards::CellTopology & cellTopology() const
The shards CellTopology for each cell within the CellGeometry object. Note that this is always a lowe...
CellGeometry provides the nodes for a set of cells; has options that support efficient definition of ...
KOKKOS_INLINE_FUNCTION bool affine() const
Returns true if Jacobian is constant within each cell.
KOKKOS_INLINE_FUNCTION std::enable_if< std::is_integral< iType >::value, int >::type extent_int(const iType &r) const
Returns the logical extent of the container in the specified dimension as an int; the shape of CellGe...
KOKKOS_INLINE_FUNCTION HypercubeNodeOrdering nodeOrderingForHypercubes() const
Returns the node ordering used for hypercubes.
Allows definition of cell geometry information, including uniform and curvilinear mesh definition...
Utility methods for Intrepid2 unit tests.
CellGeometry< PointScalar, spaceDim, DeviceType > uniformCartesianMesh(const Kokkos::Array< PointScalar, spaceDim > &domainExtents, const Kokkos::Array< int, spaceDim > &gridCellCounts)
Create a uniform Cartesian mesh, with origin at 0, and domain extents and mesh widths that can be dif...
CellGeometry< PointScalar, spaceDim, DeviceType > getNodalCellGeometry(CellGeometry< PointScalar, spaceDim, DeviceType > &anyCellGeometry, const bool &copyAffineness)
Use the cell nodes provided by one cell geometry object to create another CellGeometry that is node-b...