Compadre  1.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GMLS_DivergenceFree.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 #include <map>
5 #include <stdlib.h>
6 #include <cstdio>
7 #include <random>
8 
9 #include <Compadre_Config.h>
10 #include <Compadre_GMLS.hpp>
11 #include <Compadre_Evaluator.hpp>
13 
14 #include "GMLS_Tutorial.hpp"
15 
16 #ifdef COMPADRE_USE_MPI
17 #include <mpi.h>
18 #endif
19 
20 #include <Kokkos_Timer.hpp>
21 #include <Kokkos_Core.hpp>
22 
23 using namespace Compadre;
24 
25 //! [Parse Command Line Arguments]
26 
27 // called from command line
28 int main (int argc, char* args[]) {
29 
30 // initializes MPI (if available) with command line arguments given
31 #ifdef COMPADRE_USE_MPI
32 MPI_Init(&argc, &args);
33 #endif
34 
35 // initializes Kokkos with command line arguments given
36 Kokkos::initialize(argc, args);
37 
38 // becomes false if the computed solution not within the failure_threshold of the actual solution
39 bool all_passed = true;
40 
41 // code block to reduce scope for all Kokkos View allocations
42 // otherwise, Views may be deallocating when we call Kokkos::finalize() later
43 {
44  // check if 7 arguments are given from the command line, the first being the program name
45  // constraint_type used in solving each GMLS problem:
46  // 0 - No constraints used in solving each GMLS problem
47  // 1 - Neumann Gradient Scalar used in solving each GMLS problem
48  int constraint_type = 0; // No constraints by default
49  if (argc >= 7) {
50  int arg7toi = atoi(args[6]);
51  if (arg7toi > 0) {
52  constraint_type = arg7toi;
53  }
54  }
55 
56  // check if 6 arguments are given from the command line, the first being the program name
57  // problem_type used in solving each GMLS problem:
58  // 0 - Standard GMLS problem
59  // 1 - Manifold GMLS problem
60  int problem_type = 0; // Standard by default
61  if (argc >= 6) {
62  int arg6toi = atoi(args[5]);
63  if (arg6toi > 0) {
64  problem_type = arg6toi;
65  }
66  }
67 
68  // check if 5 arguments are given from the command line, the first being the program name
69  // solver_type used for factorization in solving each GMLS problem:
70  // 0 - SVD used for factorization in solving each GMLS problem
71  // 1 - QR used for factorization in solving each GMLS problem
72  // 2 - LU used for factorization in solving each GMLS problem
73  int solver_type = 1; // QR by default
74  if (argc >= 5) {
75  int arg5toi = atoi(args[4]);
76  if (arg5toi >= 0) {
77  solver_type = arg5toi;
78  }
79  }
80 
81  // check if 4 arguments are given from the command line
82  // dimension for the coordinates and the solution
83  int dimension = 3; // dimension 3 by default
84  if (argc >= 4) {
85  int arg4toi = atoi(args[3]);
86  if (arg4toi > 0) {
87  dimension = arg4toi;
88  }
89  }
90 
91  // check if 3 arguments are given from the command line
92  // set the number of target sites where we will reconstruct the target functionals at
93  int number_target_coords = 200; // 200 target sites by default
94  if (argc >= 3) {
95  int arg3toi = atoi(args[2]);
96  if (arg3toi > 0) {
97  number_target_coords = arg3toi;
98  }
99  }
100 
101  // check if 2 arguments are given from the command line
102  // set the number of target sites where we will reconstruct the target functionals at
103  int order = 3; // 3rd degree polynomial basis by default
104  if (argc >= 2) {
105  int arg2toi = atoi(args[1]);
106  if (arg2toi > 0) {
107  order = arg2toi;
108  }
109  }
110 
111  // the functions we will be seeking to reconstruct are in the span of the basis
112  // of the reconstruction space we choose for GMLS, so the error should be very small
113  const double failure_tolerance = 1e-9;
114 
115  // minimum neighbors for unisolvency is the same as the size of the polynomial basis
116  const int min_neighbors = Compadre::GMLS::getNP(order, dimension, DivergenceFreeVectorTaylorPolynomial);
117 
118  //! [Parse Command Line Arguments]
119  Kokkos::Timer timer;
120  Kokkos::Profiling::pushRegion("Setup Point Data");
121  //! [Setting Up The Point Cloud]
122 
123  // approximate spacing of source sites
124  double h_spacing = 0.05;
125  int n_neg1_to_1 = 2*(1/h_spacing) + 1; // always odd
126 
127  // number of source coordinate sites that will fill a box of [-1,1]x[-1,1]x[-1,1] with a spacing approximately h
128  const int number_source_coords = std::pow(n_neg1_to_1, dimension);
129 
130  // coordinates of source sites
131  Kokkos::View<double**, Kokkos::DefaultExecutionSpace> source_coords_device("source coordinates",
132  number_source_coords, 3);
133  Kokkos::View<double**>::HostMirror source_coords = Kokkos::create_mirror_view(source_coords_device);
134 
135  // coordinates of target sites
136  Kokkos::View<double**, Kokkos::DefaultExecutionSpace> target_coords_device ("target coordinates", number_target_coords, 3);
137  Kokkos::View<double**>::HostMirror target_coords = Kokkos::create_mirror_view(target_coords_device);
138 
139 
140  // fill source coordinates with a uniform grid
141  int source_index = 0;
142  double this_coord[3] = {0,0,0};
143  for (int i=-n_neg1_to_1/2; i<n_neg1_to_1/2+1; ++i) {
144  this_coord[0] = i*h_spacing;
145  for (int j=-n_neg1_to_1/2; j<n_neg1_to_1/2+1; ++j) {
146  this_coord[1] = j*h_spacing;
147  for (int k=-n_neg1_to_1/2; k<n_neg1_to_1/2+1; ++k) {
148  this_coord[2] = k*h_spacing;
149  if (dimension==3) {
150  source_coords(source_index,0) = this_coord[0];
151  source_coords(source_index,1) = this_coord[1];
152  source_coords(source_index,2) = this_coord[2];
153  source_index++;
154  }
155  }
156  if (dimension==2) {
157  source_coords(source_index,0) = this_coord[0];
158  source_coords(source_index,1) = this_coord[1];
159  source_coords(source_index,2) = 0;
160  source_index++;
161  }
162  }
163  if (dimension==1) {
164  source_coords(source_index,0) = this_coord[0];
165  source_coords(source_index,1) = 0;
166  source_coords(source_index,2) = 0;
167  source_index++;
168  }
169  }
170 
171  // Generate target points - these are random permutation from available source points
172  // Note that this is assuming that the number of targets in this test will not exceed
173  // the number of source coords, which is 41^3 = 68921
174  // seed random number generator
175  std::mt19937 rng(50);
176  // generate random integers in [0..number_source_coords-1] (used to pick target sites)
177  std::uniform_int_distribution<int> gen_num_neighbours(0, source_index);
178  // fill target sites with random selections from source sites
179  for (int i=0; i<number_target_coords; ++i) {
180  const int source_site_to_copy = gen_num_neighbours(rng);
181  for (int j=0; j<3; j++) {
182  target_coords(i, j) = source_coords(source_site_to_copy, j);
183  }
184  }
185 
186  //! [Setting Up The Point Cloud]
187 
188  Kokkos::Profiling::popRegion();
189  Kokkos::Profiling::pushRegion("Creating Data");
190 
191  //! [Creating The Data]
192 
193 
194  // source coordinates need copied to device before using to construct sampling data
195  Kokkos::deep_copy(source_coords_device, source_coords);
196 
197  // target coordinates copied next, because it is a convenient time to send them to device
198  Kokkos::deep_copy(target_coords_device, target_coords);
199 
200  // need Kokkos View storing true solution
201  Kokkos::View<double**, Kokkos::DefaultExecutionSpace> vector_sampling_span_basis_data_device("samples of true vector solution",
202  source_coords_device.extent(0), dimension);
203  Kokkos::View<double**, Kokkos::DefaultExecutionSpace> vector_sampling_single_polynomial_data_device("samples of true vector solution",
204  source_coords_device.extent(0), dimension);
205 
206  Kokkos::parallel_for("Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>
207  (0,source_coords.extent(0)), KOKKOS_LAMBDA(const int i) {
208  // coordinates of source site i
209  double xval = source_coords_device(i,0);
210  double yval = (dimension>1) ? source_coords_device(i,1) : 0;
211  double zval = (dimension>2) ? source_coords_device(i,2) : 0;
212 
213  // data for targets with vector input
214  for (int j=0; j<dimension; ++j) {
215  vector_sampling_span_basis_data_device(i, j) = divfreeTestSolution_span_basis(xval, yval, zval, j, dimension, order);
216  vector_sampling_single_polynomial_data_device(i, j) = divfreeTestSolution_single_polynomial(xval, yval, zval, j, dimension);
217  }
218  });
219 
220 
221  //! [Creating The Data]
222 
223  Kokkos::Profiling::popRegion();
224  Kokkos::Profiling::pushRegion("Neighbor Search");
225 
226  //! [Performing Neighbor Search]
227 
228 
229  // Point cloud construction for neighbor search
230  // CreatePointCloudSearch constructs an object of type PointCloudSearch, but deduces the templates for you
231  auto point_cloud_search(CreatePointCloudSearch(source_coords, dimension));
232 
233  // each row is a neighbor list for a target site, with the first column of each row containing
234  // the number of neighbors for that rows corresponding target site
235  // for the default values in this test, the multiplier is suggested to be 2.2
236  double epsilon_multiplier = 2.2;
237  int estimated_upper_bound_number_neighbors =
238  point_cloud_search.getEstimatedNumberNeighborsUpperBound(min_neighbors, dimension, epsilon_multiplier);
239 
240  Kokkos::View<int**, Kokkos::DefaultExecutionSpace> neighbor_lists_device("neighbor lists",
241  number_target_coords, estimated_upper_bound_number_neighbors); // first column is # of neighbors
242  Kokkos::View<int**>::HostMirror neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
243 
244  // each target site has a window size
245  Kokkos::View<double*, Kokkos::DefaultExecutionSpace> epsilon_device("h supports", number_target_coords);
246  Kokkos::View<double*>::HostMirror epsilon = Kokkos::create_mirror_view(epsilon_device);
247 
248  // query the point cloud to generate the neighbor lists using a kdtree to produce the n nearest neighbor
249  // to each target site, adding (epsilon_multiplier-1)*100% to whatever the distance away the further neighbor used is from
250  // each target to the view for epsilon
251  point_cloud_search.generate2DNeighborListsFromKNNSearch(false /*not dry run*/, target_coords, neighbor_lists,
252  epsilon, min_neighbors, epsilon_multiplier);
253 
254  //! [Performing Neighbor Search]
255 
256  Kokkos::Profiling::popRegion();
257  Kokkos::fence(); // let call to build neighbor lists complete before copying back to device
258  timer.reset();
259 
260  //! [Setting Up The GMLS Object]
261 
262 
263  // Copy data back to device (they were filled on the host)
264  // We could have filled Kokkos Views with memory space on the host
265  // and used these instead, and then the copying of data to the device
266  // would be performed in the GMLS class
267  Kokkos::deep_copy(neighbor_lists_device, neighbor_lists);
268  Kokkos::deep_copy(epsilon_device, epsilon);
269 
270  // solver name for passing into the GMLS class
271  std::string solver_name;
272  if (solver_type == 0) { // SVD
273  solver_name = "SVD";
274  } else if (solver_type == 1) { // QR
275  solver_name = "QR";
276  } else if (solver_type == 2) { // LU
277  solver_name = "LU";
278  }
279 
280  // problem name for passing into the GMLS class
281  std::string problem_name;
282  if (problem_type == 0) { // Standard
283  problem_name = "STANDARD";
284  } else if (problem_type == 1) { // Manifold
285  problem_name = "MANIFOLD";
286  }
287 
288  // boundary name for passing into the GMLS class
289  std::string constraint_name;
290  if (constraint_type == 0) { // No constraints
291  constraint_name = "NO_CONSTRAINT";
292  } else if (constraint_type == 1) { // Neumann Gradient Scalar
293  constraint_name = "NEUMANN_GRAD_SCALAR";
294  }
295 
296  // initialize an instance of the GMLS class
297  // NULL in manifold order indicates non-manifold case
298  // Vector basis to perform GMLS on divergence free basis
299  GMLS vector_divfree_basis_gmls(DivergenceFreeVectorTaylorPolynomial,
301  order, dimension,
302  solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
303  0 /*manifold order*/);
304 
305  // pass in neighbor lists, source coordinates, target coordinates, and window sizes
306  //
307  // neighbor lists have the format:
308  // dimensions: (# number of target sites) X (# maximum number of neighbors for any given target + 1)
309  // the first column contains the number of neighbors for that rows corresponding target index
310  //
311  // source coordinates have the format:
312  // dimensions: (# number of source sites) X (dimension)
313  // entries in the neighbor lists (integers) correspond to rows of this 2D array
314  //
315  // target coordinates have the format:
316  // dimensions: (# number of target sites) X (dimension)
317  // # of target sites is same as # of rows of neighbor lists
318  //
319  vector_divfree_basis_gmls.setProblemData(neighbor_lists_device, source_coords_device, target_coords_device, epsilon_device);
320 
321  // create a vector of target operations
322  std::vector<TargetOperation> lro(4);
323  lro[0] = VectorPointEvaluation;
327 
328  // and then pass them to the GMLS class
329  vector_divfree_basis_gmls.addTargets(lro);
330 
331  // sets the weighting kernel function from WeightingFunctionType
332  vector_divfree_basis_gmls.setWeightingType(WeightingFunctionType::Power);
333 
334  // power to use in that weighting kernel function
335  vector_divfree_basis_gmls.setWeightingPower(2);
336 
337  // generate the alphas that to be combined with data for each target operation requested in lro
338  vector_divfree_basis_gmls.generateAlphas(15 /* # batches */);
339 
340  //! [Setting Up The GMLS Object]
341 
342  double instantiation_time = timer.seconds();
343  std::cout << "Took " << instantiation_time << "s to complete alphas generation." << std::endl;
344  Kokkos::fence(); // let generateAlphas finish up before using alphas
345  Kokkos::Profiling::pushRegion("Apply Alphas to Data");
346 
347  //! [Apply GMLS Alphas To Data]
348 
349  // it is important to note that if you expect to use the data as a 1D view, then you should use double*
350  // however, if you know that the target operation will result in a 2D view (vector or matrix output),
351  // then you should template with double** as this is something that can not be infered from the input data
352  // or the target operator at compile time. Additionally, a template argument is required indicating either
353  // Kokkos::HostSpace or Kokkos::DefaultExecutionSpace::memory_space()
354 
355  // The Evaluator class takes care of handling input data views as well as the output data views.
356  // It uses information from the GMLS class to determine how many components are in the input
357  // as well as output for any choice of target functionals and then performs the contactions
358  // on the data using the alpha coefficients generated by the GMLS class, all on the device.
359  Evaluator gmls_evaluator_vector(&vector_divfree_basis_gmls);
360 
361  auto output_vector_evaluation = gmls_evaluator_vector.applyAlphasToDataAllComponentsAllTargetSites<double**, Kokkos::HostSpace>
362  (vector_sampling_span_basis_data_device, VectorPointEvaluation, VectorPointSample);
363  auto output_curl_vector_evaluation = gmls_evaluator_vector.applyAlphasToDataAllComponentsAllTargetSites<double**, Kokkos::HostSpace>
364  (vector_sampling_span_basis_data_device, CurlOfVectorPointEvaluation, VectorPointSample);
365  auto output_curlcurl_vector_evaluation = gmls_evaluator_vector.applyAlphasToDataAllComponentsAllTargetSites<double**, Kokkos::HostSpace>
366  (vector_sampling_single_polynomial_data_device, CurlCurlOfVectorPointEvaluation, VectorPointSample);
367  auto output_gradient_vector_evaluation = gmls_evaluator_vector.applyAlphasToDataAllComponentsAllTargetSites<double**, Kokkos::HostSpace>
368  (vector_sampling_span_basis_data_device, GradientOfVectorPointEvaluation, VectorPointSample);
369 
370  //! [Apply GMLS Alphas To Data]
371 
372  Kokkos::fence(); // let application of alphas to data finish before using results
373  Kokkos::Profiling::popRegion();
374  // times the Comparison in Kokkos
375  Kokkos::Profiling::pushRegion("Comparison");
376 
377  //! [Check That Solutions Are Correct]
378 
379  // loop through the target sites
380  for (int i=0; i<number_target_coords; i++) {
381  // load vector components from output
382  double GMLS_DivFree_VectorX = output_vector_evaluation(i, 0);
383  double GMLS_DivFree_VectorY = (dimension>1) ? output_vector_evaluation(i, 1) : 0;
384  double GMLS_DivFree_VectorZ = (dimension>2) ? output_vector_evaluation(i, 2) : 0;
385 
386  // load curl of vector components from output
387  double GMLS_Curl_DivFree_VectorX = output_curl_vector_evaluation(i, 0);
388  double GMLS_Curl_DivFree_VectorY = (dimension>2) ? output_curl_vector_evaluation(i, 1) : 0;
389  double GMLS_Curl_DivFree_VectorZ = (dimension>2) ? output_curl_vector_evaluation(i, 2) : 0;
390 
391  // load curl curl of vector components from output
392  double GMLS_CurlCurl_DivFree_VectorX = output_curlcurl_vector_evaluation(i, 0);
393  double GMLS_CurlCurl_DivFree_VectorY = (dimension>1) ? output_curlcurl_vector_evaluation(i, 1) : 0;
394  double GMLS_CurlCurl_DivFree_VectorZ = (dimension>2) ? output_curlcurl_vector_evaluation(i, 2) : 0;
395 
396  // load gradient of vector components from output
397  double GMLS_Gradient_DivFree_VectorXX = output_gradient_vector_evaluation(i, 0);
398  double GMLS_Gradient_DivFree_VectorXY = output_gradient_vector_evaluation(i, 1);
399  double GMLS_Gradient_DivFree_VectorXZ = (dimension==3) ? output_gradient_vector_evaluation(i, 2) : 0.0;
400  double GMLS_Gradient_DivFree_VectorYX = (dimension==3) ? output_gradient_vector_evaluation(i, 3) : output_gradient_vector_evaluation(i, 2);
401  double GMLS_Gradient_DivFree_VectorYY = (dimension==3) ? output_gradient_vector_evaluation(i, 4) : output_gradient_vector_evaluation(i, 3);
402  double GMLS_Gradient_DivFree_VectorYZ = (dimension==3) ? output_gradient_vector_evaluation(i, 5) : 0.0;
403  double GMLS_Gradient_DivFree_VectorZX = (dimension==3) ? output_gradient_vector_evaluation(i, 6) : 0.0;
404  double GMLS_Gradient_DivFree_VectorZY = (dimension==3) ? output_gradient_vector_evaluation(i, 7) : 0.0;
405  double GMLS_Gradient_DivFree_VectorZZ = (dimension==3) ? output_gradient_vector_evaluation(i, 8) : 0.0;
406 
407  // target site i's coordinate
408  double xval = target_coords(i,0);
409  double yval = (dimension>1) ? target_coords(i,1) : 0;
410  double zval = (dimension>2) ? target_coords(i,2) : 0;
411 
412  // evaluation of vector exact solutions
413  double actual_vector[3] = {0, 0, 0};
414  if (dimension>=1) {
415  actual_vector[0] = divfreeTestSolution_span_basis(xval, yval, zval, 0, dimension, order);
416  if (dimension>=2) {
417  actual_vector[1] = divfreeTestSolution_span_basis(xval, yval, zval, 1, dimension, order);
418  if (dimension==3) {
419  actual_vector[2] = divfreeTestSolution_span_basis(xval, yval, zval, 2, dimension, order);
420  }
421  }
422  }
423 
424  // evaluation of curl of vector exact solutions
425  double actual_curl_vector[3] = {0, 0, 0};
426  if (dimension>=1) {
427  actual_curl_vector[0] = curldivfreeTestSolution_span_basis(xval, yval, zval, 0, dimension, order);
428  if (dimension==3) {
429  actual_curl_vector[1] = curldivfreeTestSolution_span_basis(xval, yval, zval, 1, dimension, order);
430  actual_curl_vector[2] = curldivfreeTestSolution_span_basis(xval, yval, zval, 2, dimension, order);
431  }
432  }
433 
434  // evaluation of curl of curl of vector exact solutions
435  double actual_curlcurl_vector[3] = {0, 0, 0};
436  if (dimension>=1) {
437  actual_curlcurl_vector[0] = curlcurldivfreeTestSolution_single_polynomial(xval, yval, zval, 0, dimension);
438  if (dimension>=2) {
439  actual_curlcurl_vector[1] = curlcurldivfreeTestSolution_single_polynomial(xval, yval, zval, 1, dimension);
440  if (dimension==3) {
441  actual_curlcurl_vector[2] = curlcurldivfreeTestSolution_single_polynomial(xval, yval, zval, 2, dimension);
442  }
443  }
444  }
445 
446  double actual_gradient_vector[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
447  if (dimension==3) {
448  for (int axes = 0; axes < 9; ++axes)
449  actual_gradient_vector[axes] = gradientdivfreeTestSolution_span_basis(xval, yval, zval, axes/dimension, axes%dimension, dimension, order);
450  }
451  if (dimension==2) {
452  for (int axes = 0; axes < 4; ++axes)
453  actual_gradient_vector[axes] = gradientdivfreeTestSolution_span_basis(xval, yval, zval, axes/dimension, axes%dimension, dimension, order);
454  }
455 
456  // check vector evaluation
457  if(std::abs(actual_vector[0] - GMLS_DivFree_VectorX) > failure_tolerance) {
458  all_passed = false;
459  std::cout << i << " Failed VectorX by: " << std::abs(actual_vector[0] - GMLS_DivFree_VectorX) << std::endl;
460  if (dimension>1) {
461  if(std::abs(actual_vector[1] - GMLS_DivFree_VectorY) > failure_tolerance) {
462  all_passed = false;
463  std::cout << i << " Failed VectorY by: " << std::abs(actual_vector[1] - GMLS_DivFree_VectorY) << std::endl;
464  }
465  }
466  if (dimension>2) {
467  if(std::abs(actual_vector[2] - GMLS_DivFree_VectorZ) > failure_tolerance) {
468  all_passed = false;
469  std::cout << i << " Failed VectorZ by: " << std::abs(actual_vector[2] - GMLS_DivFree_VectorZ) << std::endl;
470  }
471  }
472  }
473 
474  // check curl of vector evaluation
475  if (dimension==2) {
476  if(std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) > failure_tolerance) {
477  all_passed = false;
478  std::cout << i << " Failed curl VectorX by: " << std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorX) << std::endl;
479  }
480  } else if (dimension>2) {
481  if(std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) > failure_tolerance) {
482  all_passed = false;
483  std::cout << i << " Failed curl VectorX by: " << std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) << std::endl;
484  }
485  if(std::abs(actual_curl_vector[1] - GMLS_Curl_DivFree_VectorY) > failure_tolerance) {
486  all_passed = false;
487  std::cout << i << " Failed curl VectorY by: " << std::abs(actual_curl_vector[1] - GMLS_Curl_DivFree_VectorY) << std::endl;
488  }
489  if(std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorZ) > failure_tolerance) {
490  all_passed = false;
491  std::cout << i << " Failed curl VectorZ by: " << std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorZ) << std::endl;
492  }
493  }
494 
495  // check curlcurl curlcurl of vector evaluation
496  if(std::abs(actual_curlcurl_vector[0] - GMLS_CurlCurl_DivFree_VectorX) > failure_tolerance) {
497  all_passed = false;
498  std::cout << i << " Failed curl curl VectorX by: " << std::abs(actual_curlcurl_vector[0] - GMLS_CurlCurl_DivFree_VectorX) << std::endl;
499  }
500  if (dimension>1) {
501  if(std::abs(actual_curlcurl_vector[1] - GMLS_CurlCurl_DivFree_VectorY) > failure_tolerance) {
502  all_passed = false;
503  std::cout << i << " Failed curl curl VectorY by: " << std::abs(actual_curlcurl_vector[1] - GMLS_CurlCurl_DivFree_VectorY) << std::endl;
504  }
505  }
506  if (dimension>2) {
507  if(std::abs(actual_curlcurl_vector[2] - GMLS_CurlCurl_DivFree_VectorZ) > failure_tolerance) {
508  all_passed = false;
509  std::cout << i << " Failed curl curl VectorZ by: " << std::abs(actual_curlcurl_vector[2] - GMLS_CurlCurl_DivFree_VectorZ) << std::endl;
510  }
511  }
512 
513  // check gradient of vector evaluation
514  if (dimension==3) {
515  if (std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) > failure_tolerance) {
516  all_passed = false;
517  std::cout << i << " Failed gradient_x VectorX by: " << std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) << std::endl;
518  }
519  if (std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) > failure_tolerance) {
520  all_passed = false;
521  std::cout << i << " Failed gradient_y VectorX by: " << std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) << std::endl;
522  }
523  if (std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorXZ) > failure_tolerance) {
524  all_passed = false;
525  std::cout << i << " Failed gradient_z VectorX by: " << std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorXZ) << std::endl;
526  }
527 
528  if (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYX) > failure_tolerance) {
529  all_passed = false;
530  std::cout << i << " Failed gradient_x VectorY by: " << std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYX) << std::endl;
531  }
532  if (std::abs(actual_gradient_vector[4] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) {
533  all_passed = false;
534  std::cout << i << " Failed gradient_y VectorY by: " << std::abs(actual_gradient_vector[4] - GMLS_Gradient_DivFree_VectorYY) << std::endl;
535  }
536  if (std::abs(actual_gradient_vector[5] - GMLS_Gradient_DivFree_VectorYZ) > failure_tolerance) {
537  all_passed = false;
538  std::cout << i << " Failed gradient_z VectorY by: " << std::abs(actual_gradient_vector[5] - GMLS_Gradient_DivFree_VectorYZ) << std::endl;
539  }
540 
541  if (std::abs(actual_gradient_vector[6] - GMLS_Gradient_DivFree_VectorZX) > failure_tolerance) {
542  all_passed = false;
543  std::cout << i << " Failed gradient_x VectorZ by: " << std::abs(actual_gradient_vector[6] - GMLS_Gradient_DivFree_VectorZX) << std::endl;
544  }
545  if (std::abs(actual_gradient_vector[7] - GMLS_Gradient_DivFree_VectorZY) > failure_tolerance) {
546  all_passed = false;
547  std::cout << i << " Failed gradient_y VectorZ by: " << std::abs(actual_gradient_vector[7] - GMLS_Gradient_DivFree_VectorZY) << std::endl;
548  }
549  if (std::abs(actual_gradient_vector[8] - GMLS_Gradient_DivFree_VectorZZ) > failure_tolerance) {
550  all_passed = false;
551  std::cout << i << " Failed gradient_z VectorZ by: " << std::abs(actual_gradient_vector[8] - GMLS_Gradient_DivFree_VectorZZ) << std::endl;
552  }
553  }
554 
555  if (dimension==2) {
556  if (std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) > failure_tolerance) {
557  all_passed = false;
558  std::cout << i << " Failed gradient_x VectorX by: " << std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) << std::endl;
559  }
560  if (std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) > failure_tolerance) {
561  all_passed = false;
562  std::cout << i << " Failed gradient_y VectorX by: " << std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) << std::endl;
563  }
564 
565  if (std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorYX) > failure_tolerance) {
566  all_passed = false;
567  std::cout << i << " Failed gradient_x VectorY by: " << std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorYX) << std::endl;
568  }
569  if (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) {
570  all_passed = false;
571  std::cout << i << " Failed gradient_y VectorY by: " << (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) << std::endl;
572  }
573  }
574  }
575 
576  //! [Check That Solutions Are Correct]
577  // popRegion hidden from tutorial
578  // stop timing comparison loop
579  Kokkos::Profiling::popRegion();
580  //! [Finalize Program]
581 
582 
583 } // end of code block to reduce scope, causing Kokkos View de-allocations
584 // otherwise, Views may be deallocating when we call Kokkos::finalize() later
585 
586 // finalize Kokkos and MPI (if available)
587 Kokkos::finalize();
588 #ifdef COMPADRE_USE_MPI
589 MPI_Finalize();
590 #endif
591 
592 // output to user that test passed or failed
593 if(all_passed) {
594  fprintf(stdout, "Passed test \n");
595  return 0;
596 } else {
597  fprintf(stdout, "Failed test \n");
598  return -1;
599 }
600 
601 } // main
602 
603 
604 //! [Finalize Program]
Divergence-free vector polynomial basis.
KOKKOS_INLINE_FUNCTION double divfreeTestSolution_span_basis(double x, double y, double z, int component, int dimension, int exact_order)
Point evaluation of the curl of a curl of a vector (results in a vector)
Point evaluation of the curl of a vector (results in a vector)
Lightweight Evaluator Helper This class is a lightweight wrapper for extracting and applying all rele...
Point evaluation of a vector (reconstructs entire vector at once, requiring a ReconstructionSpace hav...
PointCloudSearch< view_type > CreatePointCloudSearch(view_type src_view, const local_index_type dimensions=-1, const local_index_type max_leaf=-1)
CreatePointCloudSearch allows for the construction of an object of type PointCloudSearch with templat...
KOKKOS_INLINE_FUNCTION double curldivfreeTestSolution_span_basis(double x, double y, double z, int component, int dimension, int exact_order)
KOKKOS_INLINE_FUNCTION double curlcurldivfreeTestSolution_single_polynomial(double x, double y, double z, int component, int dimension)
int main(int argc, char *args[])
[Parse Command Line Arguments]
Definition: GMLS_Device.cpp:29
static KOKKOS_INLINE_FUNCTION int getNP(const int m, const int dimension=3, const ReconstructionSpace r_space=ReconstructionSpace::ScalarTaylorPolynomial)
Returns size of the basis for a given polynomial order and dimension General to dimension 1...
KOKKOS_INLINE_FUNCTION double divfreeTestSolution_single_polynomial(double x, double y, double z, int component, int dimension)
Generalized Moving Least Squares (GMLS)
Kokkos::View< output_data_type, output_array_layout, output_memory_space > applyAlphasToDataAllComponentsAllTargetSites(view_type_input_data sampling_data, TargetOperation lro, const SamplingFunctional sro_in=PointSample, bool scalar_as_vector_if_needed=true, const int evaluation_site_local_index=0) const
Transformation of data under GMLS.
KOKKOS_INLINE_FUNCTION double gradientdivfreeTestSolution_span_basis(double x, double y, double z, int input_component, int output_component, int dimension, int exact_order)
void setProblemData(view_type_1 neighbor_lists, view_type_2 source_coordinates, view_type_3 target_coordinates, view_type_4 epsilons)
Sets basic problem data (neighbor lists, source coordinates, and target coordinates) ...
Point evaluation of the gradient of a vector (results in a matrix, NOT CURRENTLY IMPLEMENTED) ...
constexpr SamplingFunctional VectorPointSample
Point evaluations of the entire vector source function.