Intrepid2
Intrepid2_ProjectedGeometryExamples.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 
50 #ifndef Intrepid2_ProjectedGeometryExamples_h
51 #define Intrepid2_ProjectedGeometryExamples_h
52 
53 namespace Intrepid2 {
57  template<typename Scalar, const int spaceDim>
59  {
60  public:
62  KOKKOS_INLINE_FUNCTION
63  Scalar operator()(const Kokkos::Array<Scalar,spaceDim> &coords, const ordinal_type &d) const
64  {
65  return coords[d];
66  }
67 
69  KOKKOS_INLINE_FUNCTION
70  Scalar operator()(const Kokkos::Array<Scalar,spaceDim> &coords, const ordinal_type &d1, const ordinal_type &d2) const
71  {
72  return (d1 == d2) ? 1.0 : 0.0;
73  }
74  };
75 
81  template<typename Scalar>
83  {
84  public:
86  KOKKOS_INLINE_FUNCTION
87  Scalar operator()(const Kokkos::Array<Scalar,2> &coords, const ordinal_type &d) const
88  {
89  const Scalar &x = coords[0];
90  const Scalar &y = coords[1];
91 
92  Scalar x_prime = x * sqrt(1. - y * y / 2.);
93  Scalar y_prime = y * sqrt(1. - x * x / 2.);
94 
95  return (d==0) ? x_prime : y_prime;
96  }
97 
99  KOKKOS_INLINE_FUNCTION
100  Scalar operator()(const Kokkos::Array<Scalar,2> &coords, const ordinal_type &d1, const ordinal_type &d2) const
101  {
102  const Scalar &x = coords[0];
103  const Scalar &y = coords[1];
104 
105  Scalar x_prime_dx = sqrt(1. - y * y / 2.);
106  Scalar x_prime_dy = - x * y / sqrt(1. - y * y / 2.);
107  Scalar y_prime_dx = - x * y / sqrt(1. - x * x / 2.);
108  Scalar y_prime_dy = sqrt(1. - x * x / 2.);
109 
110  if ((d1 == 0) && (d2 == 0)) return x_prime_dx;
111  else if ((d1 == 0) && (d2 == 1)) return x_prime_dy;
112  else if ((d1 == 1) && (d2 == 0)) return y_prime_dx;
113  else if ((d1 == 1) && (d2 == 1)) return y_prime_dy;
114 
115  INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "Unsupported dim");
116  return 0;
117  }
118  };
119 
125  template<typename Scalar>
127  {
129  KOKKOS_INLINE_FUNCTION
130  Scalar operator()(const Kokkos::Array<Scalar,3> &coords, const ordinal_type &d) const
131  {
132  const int spaceDim = 3;
133  // value is x_i * sqrt(1 - sum(x_j * x_j / 2.)) where j ≠ i
134  const Scalar &x_d = coords[d];
135 
136  Scalar radical = 1.0;
137  for (int d1=0; d1<spaceDim; d1++)
138  {
139  const Scalar valueToSubtract = (d1 == d) ? 0.0 : coords[d1] * coords[d1] / 2.0;
140  radical -= valueToSubtract;
141  }
142 
143  return x_d * sqrt(radical);
144  }
145 
147  KOKKOS_INLINE_FUNCTION
148  Scalar operator()(const Kokkos::Array<Scalar,3> &coords, const ordinal_type &d1, const ordinal_type &d2) const
149  {
150  const int spaceDim = 3;
151  const Scalar &x_d1 = coords[d1];
152  const Scalar &x_d2 = coords[d2];
153 
154  Scalar radical = 1.0;
155  for (int d=0; d<spaceDim; d++)
156  {
157  const Scalar valueToSubtract = (d1 == d) ? 0.0 : coords[d] * coords[d] / 2.0;
158  radical -= valueToSubtract;
159  }
160 
161  Scalar weight = (d1 == d2) ? 1.0 : - x_d1 * x_d2;
162  return weight * sqrt(radical);
163  }
164  };
165 
166 }
167 #endif /* Intrepid2_ProjectedGeometryExamples_h */
#define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg)
KOKKOS_INLINE_FUNCTION Scalar operator()(const Kokkos::Array< Scalar, spaceDim > &coords, const ordinal_type &d1, const ordinal_type &d2) const
gradient of the (identity) mapping
KOKKOS_INLINE_FUNCTION Scalar operator()(const Kokkos::Array< Scalar, 2 > &coords, const ordinal_type &d) const
coordinate values
KOKKOS_INLINE_FUNCTION Scalar operator()(const Kokkos::Array< Scalar, 3 > &coords, const ordinal_type &d1, const ordinal_type &d2) const
gradient of the mapping
KOKKOS_INLINE_FUNCTION Scalar operator()(const Kokkos::Array< Scalar, 3 > &coords, const ordinal_type &d) const
coordinate values
Maps unit square [-1,1]x[-1,1] to circle of radius 1.
KOKKOS_INLINE_FUNCTION Scalar operator()(const Kokkos::Array< Scalar, 2 > &coords, const ordinal_type &d1, const ordinal_type &d2) const
gradient of the mapping
Maps unit cube [-1,1]x[-1,1]x[-1,1] to sphere of radius 1.
KOKKOS_INLINE_FUNCTION Scalar operator()(const Kokkos::Array< Scalar, spaceDim > &coords, const ordinal_type &d) const
coordinate values
Identity map; simply preserves linear geometry. Intended primarily for tests.