37int main (
int argc,
char* args[]) {
40#ifdef COMPADRE_USE_MPI
41MPI_Init(&argc, &args);
45Kokkos::initialize(argc, args);
48bool all_passed =
true;
55 auto order = clp.
order;
62 bool keep_coefficients = number_of_batches==1;
67 const double failure_tolerance = 1e-9;
70 const double laplacian_failure_tolerance = 1e-9;
77 Kokkos::Profiling::pushRegion(
"Setup Point Data");
81 double h_spacing = 0.05;
82 int n_neg1_to_1 = 2*(1/h_spacing) + 1;
85 const int number_source_coords = std::pow(n_neg1_to_1, dimension);
88 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> source_coords_device(
"source coordinates",
89 number_source_coords, 3);
90 Kokkos::View<double**>::host_mirror_type source_coords = Kokkos::create_mirror_view(source_coords_device);
93 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> target_coords_device (
"target coordinates", number_target_coords, 3);
94 Kokkos::View<double**>::host_mirror_type target_coords = Kokkos::create_mirror_view(target_coords_device);
99 double this_coord[3] = {0,0,0};
100 for (
int i=-n_neg1_to_1/2; i<n_neg1_to_1/2+1; ++i) {
101 this_coord[0] = i*h_spacing;
102 for (
int j=-n_neg1_to_1/2; j<n_neg1_to_1/2+1; ++j) {
103 this_coord[1] = j*h_spacing;
104 for (
int k=-n_neg1_to_1/2; k<n_neg1_to_1/2+1; ++k) {
105 this_coord[2] = k*h_spacing;
107 source_coords(source_index,0) = this_coord[0];
108 source_coords(source_index,1) = this_coord[1];
109 source_coords(source_index,2) = this_coord[2];
114 source_coords(source_index,0) = this_coord[0];
115 source_coords(source_index,1) = this_coord[1];
116 source_coords(source_index,2) = 0;
121 source_coords(source_index,0) = this_coord[0];
122 source_coords(source_index,1) = 0;
123 source_coords(source_index,2) = 0;
129 for(
int i=0; i<number_target_coords; i++){
132 double rand_dir[3] = {0,0,0};
134 for (
int j=0; j<dimension; ++j) {
136 rand_dir[j] = ((double)rand() / (double) RAND_MAX) - 0.5;
140 for (
int j=0; j<dimension; ++j) {
141 target_coords(i,j) = rand_dir[j];
149 Kokkos::Profiling::popRegion();
150 Kokkos::Profiling::pushRegion(
"Creating Data");
156 Kokkos::deep_copy(source_coords_device, source_coords);
159 Kokkos::deep_copy(target_coords_device, target_coords);
162 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> sampling_data_device(
"samples of true solution",
163 source_coords_device.extent(0));
165 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> gradient_sampling_data_device(
"samples of true gradient",
166 source_coords_device.extent(0), dimension);
168 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> divergence_sampling_data_device
169 (
"samples of true solution for divergence test", source_coords_device.extent(0), dimension);
171 Kokkos::parallel_for(
"Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>
172 (0,source_coords.extent(0)), KOKKOS_LAMBDA(
const int i) {
175 double xval = source_coords_device(i,0);
176 double yval = (dimension>1) ? source_coords_device(i,1) : 0;
177 double zval = (dimension>2) ? source_coords_device(i,2) : 0;
180 sampling_data_device(i) =
trueSolution(xval, yval, zval, order, dimension);
183 double true_grad[3] = {0,0,0};
184 trueGradient(true_grad, xval, yval,zval, order, dimension);
186 for (
int j=0; j<dimension; ++j) {
187 gradient_sampling_data_device(i,j) = true_grad[j];
198 Kokkos::Profiling::popRegion();
199 Kokkos::Profiling::pushRegion(
"Neighbor Search");
208 double epsilon_multiplier = 1.4;
213 Kokkos::View<int*> neighbor_lists_device(
"neighbor lists",
215 Kokkos::View<int*>::host_mirror_type neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
218 Kokkos::View<int*> number_of_neighbors_list_device(
"number of neighbor lists",
219 number_target_coords);
220 Kokkos::View<int*>::host_mirror_type number_of_neighbors_list = Kokkos::create_mirror_view(number_of_neighbors_list_device);
223 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> epsilon_device(
"h supports", number_target_coords);
224 Kokkos::View<double*>::host_mirror_type epsilon = Kokkos::create_mirror_view(epsilon_device);
231 size_t storage_size = point_cloud_search.generateCRNeighborListsFromKNNSearch(
true , target_coords, neighbor_lists,
232 number_of_neighbors_list, epsilon, min_neighbors, epsilon_multiplier);
235 Kokkos::resize(neighbor_lists_device, storage_size);
236 neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
239 point_cloud_search.generateCRNeighborListsFromKNNSearch(
false , target_coords, neighbor_lists,
240 number_of_neighbors_list, epsilon, min_neighbors, epsilon_multiplier);
244 Kokkos::Profiling::popRegion();
255 Kokkos::deep_copy(neighbor_lists_device, neighbor_lists);
256 Kokkos::deep_copy(number_of_neighbors_list_device, number_of_neighbors_list);
257 Kokkos::deep_copy(epsilon_device, epsilon);
262 solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
282 my_GMLS.
setProblemData(neighbor_lists_device, number_of_neighbors_list_device, source_coords_device, target_coords_device, epsilon_device);
285 std::vector<TargetOperation> lro(5);
307 double instantiation_time = timer.seconds();
308 std::cout <<
"Took " << instantiation_time <<
"s to complete alphas generation." << std::endl;
310 Kokkos::Profiling::pushRegion(
"Apply Alphas to Data");
342 decltype(output_curl) scalar_coefficients;
343 if (number_of_batches==1)
344 scalar_coefficients =
346 (sampling_data_device);
351 Kokkos::Profiling::popRegion();
353 Kokkos::Profiling::pushRegion(
"Comparison");
359 for (
int i=0; i<number_target_coords; i++) {
362 double GMLS_value = output_value(i);
365 double GMLS_Laplacian = output_laplacian(i);
371 double GMLS_GradX = (number_of_batches==1) ? scalar_coefficients(i,1)*1./epsilon(i) : output_gradient(i,0);
374 double GMLS_GradY = (dimension>1) ? output_gradient(i,1) : 0;
377 double GMLS_GradZ = (dimension>2) ? output_gradient(i,2) : 0;
380 double GMLS_Divergence = output_divergence(i);
383 double GMLS_CurlX = (dimension>1) ? output_curl(i,0) : 0;
384 double GMLS_CurlY = (dimension>1) ? output_curl(i,1) : 0;
385 double GMLS_CurlZ = (dimension>2) ? output_curl(i,2) : 0;
389 double xval = target_coords(i,0);
390 double yval = (dimension>1) ? target_coords(i,1) : 0;
391 double zval = (dimension>2) ? target_coords(i,2) : 0;
394 double actual_value =
trueSolution(xval, yval, zval, order, dimension);
395 double actual_Laplacian =
trueLaplacian(xval, yval, zval, order, dimension);
397 double actual_Gradient[3] = {0,0,0};
398 trueGradient(actual_Gradient, xval, yval, zval, order, dimension);
400 double actual_Divergence;
401 actual_Divergence =
trueLaplacian(xval, yval, zval, order, dimension);
403 double actual_Curl[3] = {0,0,0};
414 if(GMLS_value!=GMLS_value || std::abs(actual_value - GMLS_value) > failure_tolerance) {
416 std::cout << i <<
" Failed Actual by: " << std::abs(actual_value - GMLS_value) << std::endl;
420 if(std::abs(actual_Laplacian - GMLS_Laplacian) > laplacian_failure_tolerance) {
422 std::cout << i <<
" Failed Laplacian by: " << std::abs(actual_Laplacian - GMLS_Laplacian) << std::endl;
426 if(std::abs(actual_Gradient[0] - GMLS_GradX) > failure_tolerance) {
428 std::cout << i <<
" Failed GradX by: " << std::abs(actual_Gradient[0] - GMLS_GradX) << std::endl;
430 if(std::abs(actual_Gradient[1] - GMLS_GradY) > failure_tolerance) {
432 std::cout << i <<
" Failed GradY by: " << std::abs(actual_Gradient[1] - GMLS_GradY) << std::endl;
436 if(std::abs(actual_Gradient[2] - GMLS_GradZ) > failure_tolerance) {
438 std::cout << i <<
" Failed GradZ by: " << std::abs(actual_Gradient[2] - GMLS_GradZ) << std::endl;
444 if(std::abs(actual_Divergence - GMLS_Divergence) > failure_tolerance) {
446 std::cout << i <<
" Failed Divergence by: " << std::abs(actual_Divergence - GMLS_Divergence) << std::endl;
453 tmp_diff += std::abs(actual_Curl[0] - GMLS_CurlX) + std::abs(actual_Curl[1] - GMLS_CurlY);
455 tmp_diff += std::abs(actual_Curl[2] - GMLS_CurlZ);
456 if(std::abs(tmp_diff) > failure_tolerance) {
458 std::cout << i <<
" Failed Curl by: " << std::abs(tmp_diff) << std::endl;
467 Kokkos::Profiling::popRegion();
476#ifdef COMPADRE_USE_MPI
482 fprintf(stdout,
"Passed test \n");
485 fprintf(stdout,
"Failed test \n");