Compadre  1.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GMLS_Manifold.hpp
Go to the documentation of this file.
1 #ifndef _GMLS_MANIFOLD_HPP_
2 #define _GMLS_MANIFOLD_HPP_
3 
4 #include <Kokkos_Core.hpp>
5 #include <cmath>
6 
7 #define PI 3.14159265358979323846
8 
9 KOKKOS_INLINE_FUNCTION
10 double device_max(double d1, double d2) {
11  return (d1 > d2) ? d1 : d2;
12 }
13 
14 KOKKOS_INLINE_FUNCTION
15 double atan4(const double y, const double x) {
16  double result = 0.0;
17  if (x == 0.0)
18  {
19  if (y > 0.0)
20  result = 0.5 * PI;
21  else if ( y < 0.0 )
22  result = 1.5 * PI;
23  else if ( y == 0.0 )
24  result = 0.0;
25  }
26  else if (y == 0)
27  {
28  if (x > 0.0)
29  result = 0.0;
30  else if ( x < 0.0 )
31  result = PI;
32  }
33  else
34  {
35  double theta = std::atan2( std::abs(y), std::abs(x) );
36  if (x > 0.0 && y > 0.0)
37  result = theta;
38  else if ( x < 0.0 && y > 0.0 )
39  result = PI - theta;
40  else if ( x < 0.0 && y < 0.0 )
41  result = PI + theta;
42  else if ( x > 0.0 && y < 0.0 )
43  result = 2.0 * PI - theta;
44  }
45  return result;
46 }
47 
48 KOKKOS_INLINE_FUNCTION
49 double latitude(double x, double y, double z) {
50  return std::atan2(z, std::sqrt( x*x + y*y));
51 }
52 
53 KOKKOS_INLINE_FUNCTION
54 double longitude(double x, double y, double z) {
55  return atan4(y, x);
56 }
57 
58 KOKKOS_INLINE_FUNCTION
59 double legendre54(double z) {
60  return z * ( z * z - 1.0 ) * ( z * z - 1.0 );
61 }
62 
63 KOKKOS_INLINE_FUNCTION
64 double sphere_harmonic54(double x, double y, double z) {
65  const double lon = longitude(x, y, z);
66  return std::cos(4.0 * lon) * legendre54(z);
67 }
68 
69 KOKKOS_INLINE_FUNCTION
70 void curl_sphere_harmonic54(double *curl, double x, double y, double z) {
71  const scalar_type lon = longitude(x, y, z); // theta
72  const scalar_type lat = acos(z); // phi
73  const scalar_type sigma_lon_comp = std::pow(sin(lat), 2) * (5.0* std::pow(cos(lat), 2) - 1.0) * cos(4.0 *lon);
74  const scalar_type sigma_lat_comp = 4*cos(lat) * std::pow(sin(lat), 3) * sin(4.0 * lon);
75  // solution oriented for inward normal, so we flip sign for outward
76  curl[0] = -(-sin(lat)*sin(lon)*sigma_lon_comp + cos(lat)*cos(lon)*sigma_lat_comp);
77  curl[1] = -(sin(lat)*cos(lon)*sigma_lon_comp + cos(lat)*sin(lon)*sigma_lat_comp);
78  curl[2] = -(-sin(lat)*sigma_lat_comp);
79 }
80 
81 
82 KOKKOS_INLINE_FUNCTION
83 double laplace_beltrami_sphere_harmonic54(double x, double y, double z) {
84  const double lon = longitude(x, y, z);
85  return -30 * std::cos(4.0 * lon) * legendre54(z);
86 }
87 
88 KOKKOS_INLINE_FUNCTION
89 void gradient_sphereHarmonic54_local(double *gradient, double x, double y, double z) {
90  const double lat = latitude(x, y, z); // phi
91  const double lon = longitude(x, y, z); // lambda
92 
93  const double A = -4.0 * std::pow(std::cos(lat),3) * std::sin(4.0 * lon) * std::sin(lat);
94  const double B = 0.5* std::cos(4.0 * lon) * std::pow(std::cos(lat),3) * ( 5 * std::cos(2.0 * lat) - 3.0 );
95 
96  gradient[0] = A;
97  gradient[1] = B;
98 }
99 
100 KOKKOS_INLINE_FUNCTION
101 void gradient_sphereHarmonic54_ambient(double *gradient, double x, double y, double z) {
102  const double lat = latitude(x, y, z); // phi
103  const double lon = longitude(x, y, z); // lambda
104 
105  const double A = -4.0 * std::pow(std::cos(lat),3) * std::sin(4.0 * lon) * std::sin(lat);
106  const double B = 0.5* std::cos(4.0 * lon) * std::pow(std::cos(lat),3) * ( 5 * std::cos(2.0 * lat) - 3.0 );
107 
108  gradient[0] = -A * std::sin(lon) - B * std::sin(lat) * std::cos(lon);
109  gradient[1] = A * std::cos(lon) - B * std::sin(lat) * std::sin(lon);
110  gradient[2] = B * std::cos(lat);
111 }
112 
113 KOKKOS_INLINE_FUNCTION
114 void velocity_sphereHarmonic54_ambient(double *velocity, double x, double y, double z) {
115  const double lat = latitude(x, y, z); // phi
116  const double lon = longitude(x, y, z); // lambda
117 
118  const double U = 0.5* std::cos(4.0 * lon) * std::pow(std::cos(lat),3) * ( 5 * std::cos(2.0 * lat) - 3.0 );
119  const double V = 4.0 * std::pow(std::cos(lat),3) * std::sin(4.0 * lon) * std::sin(lat);
120 
121  velocity[0] = -U * std::sin(lon) - V * std::sin(lat) * std::cos(lon);
122  velocity[1] = U * std::cos(lon) - V * std::sin(lat) * std::sin(lon);
123  velocity[2] = V * std::cos(lat);
124 }
125 
126 
127 
128 /** Manifold GMLS Example
129  *
130  * Exercises GMLS operator evaluation with data over various orders and numbers of targets for targets including point evaluation, Laplace-Beltrami, gradient and gradient on a manifold.
131  */
132 int main (int argc, char* args[]);
133 
134 /**
135  * \example "Manifold GMLS Tutorial" based on GMLS_Manifold.cpp
136  * \section ex GMLS Example with Device Views
137  *
138  * This tutorial sets up a batch of GMLS problems, solves the minimization problems, and applies the coefficients produced to data.
139  *
140  * \section ex1a Parse Command Line Arguments
141  * \snippet GMLS_Manifold.cpp Parse Command Line Arguments
142  *
143  * \section ex1b Setting Up The Point Cloud
144  * \snippet GMLS_Manifold.cpp Setting Up The Point Cloud
145  *
146  * \section ex1c Performing Neighbor Search
147  * \snippet GMLS_Manifold.cpp Performing Neighbor Search
148  *
149  * \section ex2 Creating The Data
150  * \snippet GMLS_Manifold.cpp Creating The Data
151  *
152  * \section ex3 Setting Up The GMLS Object
153  * \snippet GMLS_Manifold.cpp Setting Up The GMLS Object
154  *
155  * \section ex4 Apply GMLS Alphas To Data
156  * \snippet GMLS_Manifold.cpp Apply GMLS Alphas To Data
157  *
158  * \section ex5 Check That Solutions Are Correct
159  * \snippet GMLS_Manifold.cpp Check That Solutions Are Correct
160  *
161  * \section ex6 Finalize Program
162  * \snippet GMLS_Manifold.cpp Finalize Program
163  */
164 
165 #endif
KOKKOS_INLINE_FUNCTION double sphere_harmonic54(double x, double y, double z)
double scalar_type
KOKKOS_INLINE_FUNCTION void gradient_sphereHarmonic54_local(double *gradient, double x, double y, double z)
KOKKOS_INLINE_FUNCTION double latitude(double x, double y, double z)
#define PI
KOKKOS_INLINE_FUNCTION void curl_sphere_harmonic54(double *curl, double x, double y, double z)
KOKKOS_INLINE_FUNCTION double atan4(const double y, const double x)
KOKKOS_INLINE_FUNCTION double device_max(double d1, double d2)
int main(int argc, char *args[])
[Parse Command Line Arguments]
Definition: GMLS_Device.cpp:29
KOKKOS_INLINE_FUNCTION double longitude(double x, double y, double z)
KOKKOS_INLINE_FUNCTION double legendre54(double z)
KOKKOS_INLINE_FUNCTION void velocity_sphereHarmonic54_ambient(double *velocity, double x, double y, double z)
KOKKOS_INLINE_FUNCTION void gradient_sphereHarmonic54_ambient(double *gradient, double x, double y, double z)
KOKKOS_INLINE_FUNCTION double laplace_beltrami_sphere_harmonic54(double x, double y, double z)