17 #include <Compadre_Config.h>
25 #ifdef COMPADRE_USE_MPI
29 #include <Kokkos_Timer.hpp>
30 #include <Kokkos_Core.hpp>
32 using namespace Compadre;
37 int main (
int argc,
char* args[]) {
40 #ifdef COMPADRE_USE_MPI
41 MPI_Init(&argc, &args);
45 Kokkos::initialize(argc, args);
52 auto order = clp.
order;
66 Kokkos::Profiling::pushRegion(
"Setup Point Data");
71 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> source_coords_device(
"source coordinates",
72 1.25*N_pts_on_sphere, 3);
73 Kokkos::View<double**>::HostMirror source_coords = Kokkos::create_mirror_view(source_coords_device);
78 int number_source_coords;
84 double a = 4*
PI*r*r/N_pts_on_sphere;
85 double d = std::sqrt(a);
86 int M_theta = std::round(
PI/d);
87 double d_theta =
PI/M_theta;
88 double d_phi = a/d_theta;
89 for (
int i=0; i<M_theta; ++i) {
90 double theta =
PI*(i + 0.5)/M_theta;
91 int M_phi = std::ceil(2*
PI*std::sin(theta)/d_phi);
92 for (
int j=0; j<M_phi; ++j) {
93 double phi = 2*
PI*j/M_phi;
94 source_coords(N_count, 0) = theta;
95 source_coords(N_count, 1) = phi;
100 for (
int i=0; i<N_count; ++i) {
101 double theta = source_coords(i,0);
102 double phi = source_coords(i,1);
103 source_coords(i,0) = r*std::sin(theta)*std::cos(phi);
104 source_coords(i,1) = r*std::sin(theta)*std::sin(phi);
105 source_coords(i,2) = r*cos(theta);
108 number_source_coords = N_count;
112 Kokkos::resize(source_coords, number_source_coords, 3);
113 Kokkos::resize(source_coords_device, number_source_coords, 3);
116 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> target_coords_device (
"target coordinates",
117 number_target_coords, 3);
118 Kokkos::View<double**>::HostMirror target_coords = Kokkos::create_mirror_view(target_coords_device);
121 bool enough_pts_found =
false;
125 double a = 4.0*
PI*r*r/((double)(1.0*number_target_coords));
126 double d = std::sqrt(a);
127 int M_theta = std::round(
PI/d);
128 double d_theta =
PI/((double)M_theta);
129 double d_phi = a/d_theta;
130 for (
int i=0; i<M_theta; ++i) {
131 double theta =
PI*(i + 0.5)/M_theta;
132 int M_phi = std::ceil(2*
PI*std::sin(theta)/d_phi);
133 for (
int j=0; j<M_phi; ++j) {
134 double phi = 2*
PI*j/M_phi;
135 target_coords(N_count, 0) = theta;
136 target_coords(N_count, 1) = phi;
138 if (N_count == number_target_coords) {
139 enough_pts_found =
true;
143 if (enough_pts_found)
break;
146 for (
int i=0; i<N_count; ++i) {
147 double theta = target_coords(i,0);
148 double phi = target_coords(i,1);
149 target_coords(i,0) = r*std::sin(theta)*std::cos(phi);
150 target_coords(i,1) = r*std::sin(theta)*std::sin(phi);
151 target_coords(i,2) = r*cos(theta);
162 Kokkos::Profiling::popRegion();
164 Kokkos::Profiling::pushRegion(
"Creating Data");
170 Kokkos::deep_copy(source_coords_device, source_coords);
173 Kokkos::deep_copy(target_coords_device, target_coords);
180 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> sampling_data_device(
"samples of true solution",
181 source_coords_device.extent(0));
183 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> ones_data_device(
"samples of ones",
184 source_coords_device.extent(0));
185 Kokkos::deep_copy(ones_data_device, 1.0);
188 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> sampling_vector_data_device(
"samples of vector true solution",
189 source_coords_device.extent(0), 3);
191 Kokkos::parallel_for(
"Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>
192 (0,source_coords.extent(0)), KOKKOS_LAMBDA(
const int i) {
195 double xval = source_coords_device(i,0);
196 double yval = (dimension>1) ? source_coords_device(i,1) : 0;
197 double zval = (dimension>2) ? source_coords_device(i,2) : 0;
202 for (
int j=0; j<3; ++j) {
203 double gradient[3] = {0,0,0};
205 sampling_vector_data_device(i,j) = gradient[j];
212 Kokkos::Profiling::popRegion();
213 Kokkos::Profiling::pushRegion(
"Neighbor Search");
217 double epsilon_multiplier = 1.9;
223 Kokkos::View<int*> neighbor_lists_device(
"neighbor lists",
225 Kokkos::View<int*>::HostMirror neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
228 Kokkos::View<int*> number_of_neighbors_list_device(
"number of neighbor lists",
229 number_target_coords);
230 Kokkos::View<int*>::HostMirror number_of_neighbors_list = Kokkos::create_mirror_view(number_of_neighbors_list_device);
233 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> epsilon_device(
"h supports", number_target_coords);
234 Kokkos::View<double*>::HostMirror epsilon = Kokkos::create_mirror_view(epsilon_device);
236 size_t storage_size = point_cloud_search.generateCRNeighborListsFromKNNSearch(
true , target_coords, neighbor_lists,
237 number_of_neighbors_list, epsilon, min_neighbors, epsilon_multiplier);
240 Kokkos::resize(neighbor_lists_device, storage_size);
241 neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
244 point_cloud_search.generateCRNeighborListsFromKNNSearch(
false , target_coords, neighbor_lists,
245 number_of_neighbors_list, epsilon, min_neighbors, epsilon_multiplier);
259 Kokkos::Profiling::popRegion();
270 Kokkos::deep_copy(neighbor_lists_device, neighbor_lists);
271 Kokkos::deep_copy(number_of_neighbors_list_device, number_of_neighbors_list);
272 Kokkos::deep_copy(epsilon_device, epsilon);
276 GMLS my_GMLS_scalar(order, dimension,
277 solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
294 my_GMLS_scalar.
setProblemData(neighbor_lists_device, number_of_neighbors_list_device, source_coords_device, target_coords_device, epsilon_device);
299 my_GMLS_scalar.setReferenceOutwardNormalDirection(target_coords_device,
true );
302 std::vector<TargetOperation> lro_scalar(4);
309 my_GMLS_scalar.addTargets(lro_scalar);
315 my_GMLS_scalar.setCurvatureWeightingParameter(2);
321 my_GMLS_scalar.setWeightingParameter(2);
324 my_GMLS_scalar.generateAlphas();
326 Kokkos::Profiling::pushRegion(
"Full Polynomial Basis GMLS Solution");
333 solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
336 my_GMLS_vector.
setProblemData(neighbor_lists_device, number_of_neighbors_list_device, source_coords_device, target_coords_device, epsilon_device);
337 std::vector<TargetOperation> lro_vector(2);
340 my_GMLS_vector.addTargets(lro_vector);
342 my_GMLS_vector.setCurvatureWeightingParameter(2);
344 my_GMLS_vector.setWeightingParameter(2);
345 my_GMLS_vector.generateAlphas();
346 Kokkos::Profiling::popRegion();
348 Kokkos::Profiling::pushRegion(
"Scalar Polynomial Basis Repeated to Form a Vector GMLS Solution");
373 solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
376 my_GMLS_vector_of_scalar_clones.
setProblemData(neighbor_lists_device, number_of_neighbors_list_device, source_coords_device, target_coords_device, epsilon_device);
377 std::vector<TargetOperation> lro_vector_of_scalar_clones(2);
380 my_GMLS_vector_of_scalar_clones.addTargets(lro_vector_of_scalar_clones);
382 my_GMLS_vector_of_scalar_clones.setCurvatureWeightingParameter(2);
384 my_GMLS_vector_of_scalar_clones.setWeightingParameter(2);
385 my_GMLS_vector_of_scalar_clones.generateAlphas();
386 Kokkos::Profiling::popRegion();
391 double instantiation_time = timer.seconds();
392 std::cout <<
"Took " << instantiation_time <<
"s to complete alphas generation." << std::endl;
394 Kokkos::Profiling::pushRegion(
"Apply Alphas to Data");
409 Evaluator scalar_gmls_evaluator(&my_GMLS_scalar);
410 Evaluator vector_gmls_evaluator(&my_GMLS_vector);
411 Evaluator vector_gmls_evaluator_of_scalar_clones(&my_GMLS_vector_of_scalar_clones);
431 auto output_vector_of_scalar_clones =
435 auto output_divergence_of_scalar_clones =
469 Kokkos::Profiling::popRegion();
471 Kokkos::Profiling::pushRegion(
"Comparison");
475 double tangent_bundle_error = 0;
476 double tangent_bundle_norm = 0;
477 double values_error = 0;
478 double values_norm = 0;
479 double laplacian_error = 0;
480 double laplacian_norm = 0;
481 double gradient_ambient_error = 0;
482 double gradient_ambient_norm = 0;
485 double vector_ambient_error = 0;
486 double vector_ambient_norm = 0;
487 double divergence_ambient_error = 0;
488 double divergence_ambient_norm = 0;
489 double vector_of_scalar_clones_ambient_error = 0;
490 double vector_of_scalar_clones_ambient_norm = 0;
491 double divergence_of_scalar_clones_ambient_error = 0;
492 double divergence_of_scalar_clones_ambient_norm = 0;
495 for (
int i=0; i<number_target_coords; i++) {
498 double GMLS_value = output_value(i);
499 double GMLS_gc = output_gc(i);
502 double GMLS_Laplacian = output_laplacian(i);
505 double xval = target_coords(i,0);
506 double yval = (dimension>1) ? target_coords(i,1) : 0;
507 double zval = (dimension>2) ? target_coords(i,2) : 0;
508 double coord[3] = {xval, yval, zval};
511 for (
unsigned int j=0; j<static_cast<unsigned int>(dimension-1); ++j) {
514 double tangent_inner_prod = 0;
515 for (
int k=0; k<dimension; ++k) {
516 tangent_inner_prod += coord[k] * my_GMLS_scalar.getTangentBundle(i, j, k);
518 tangent_bundle_error += tangent_inner_prod * tangent_inner_prod;
520 double normal_inner_prod = 0;
521 for (
int k=0; k<dimension; ++k) {
522 normal_inner_prod += coord[k] * my_GMLS_scalar.getTangentBundle(i, dimension-1, k);
525 double normal_error_to_sum = (normal_inner_prod > 0) ? normal_inner_prod - 1 : normal_inner_prod + 1;
526 tangent_bundle_error += normal_error_to_sum * normal_error_to_sum;
527 tangent_bundle_norm += 1;
532 double actual_Gradient_ambient[3] = {0,0,0};
536 values_error += (GMLS_value - actual_value)*(GMLS_value - actual_value);
537 values_norm += actual_value*actual_value;
539 laplacian_error += (GMLS_Laplacian - actual_Laplacian)*(GMLS_Laplacian - actual_Laplacian);
540 laplacian_norm += actual_Laplacian*actual_Laplacian;
542 double actual_gc = 1.0;
543 gc_error += (GMLS_gc - actual_gc)*(GMLS_gc - actual_gc);
544 gc_norm += actual_gc*actual_gc;
546 for (
int j=0; j<dimension; ++j) {
547 gradient_ambient_error += (output_gradient(i,j) - actual_Gradient_ambient[j])*(output_gradient(i,j) - actual_Gradient_ambient[j]);
548 gradient_ambient_norm += actual_Gradient_ambient[j]*actual_Gradient_ambient[j];
551 for (
int j=0; j<dimension; ++j) {
552 vector_ambient_error += (output_vector(i,j) - actual_Gradient_ambient[j])*(output_vector(i,j) - actual_Gradient_ambient[j]);
553 vector_ambient_norm += actual_Gradient_ambient[j]*actual_Gradient_ambient[j];
556 divergence_ambient_error += (output_divergence(i) - actual_Laplacian)*(output_divergence(i) - actual_Laplacian);
557 divergence_ambient_norm += actual_Laplacian*actual_Laplacian;
559 for (
int j=0; j<dimension; ++j) {
560 vector_of_scalar_clones_ambient_error += (output_vector_of_scalar_clones(i,j) - actual_Gradient_ambient[j])*(output_vector_of_scalar_clones(i,j) - actual_Gradient_ambient[j]);
561 vector_of_scalar_clones_ambient_norm += actual_Gradient_ambient[j]*actual_Gradient_ambient[j];
564 divergence_of_scalar_clones_ambient_error += (output_divergence_of_scalar_clones(i) - actual_Laplacian)*(output_divergence_of_scalar_clones(i) - actual_Laplacian);
565 divergence_of_scalar_clones_ambient_norm += actual_Laplacian*actual_Laplacian;
569 tangent_bundle_error /= number_target_coords;
570 tangent_bundle_error = std::sqrt(tangent_bundle_error);
571 tangent_bundle_norm /= number_target_coords;
572 tangent_bundle_norm = std::sqrt(tangent_bundle_norm);
574 values_error /= number_target_coords;
575 values_error = std::sqrt(values_error);
576 values_norm /= number_target_coords;
577 values_norm = std::sqrt(values_norm);
579 laplacian_error /= number_target_coords;
580 laplacian_error = std::sqrt(laplacian_error);
581 laplacian_norm /= number_target_coords;
582 laplacian_norm = std::sqrt(laplacian_norm);
584 gradient_ambient_error /= number_target_coords;
585 gradient_ambient_error = std::sqrt(gradient_ambient_error);
586 gradient_ambient_norm /= number_target_coords;
587 gradient_ambient_norm = std::sqrt(gradient_ambient_norm);
589 gc_error /= number_target_coords;
590 gc_error = std::sqrt(gc_error);
591 gc_norm /= number_target_coords;
592 gc_norm = std::sqrt(gc_norm);
594 vector_ambient_error /= number_target_coords;
595 vector_ambient_error = std::sqrt(vector_ambient_error);
596 vector_ambient_norm /= number_target_coords;
597 vector_ambient_norm = std::sqrt(vector_ambient_norm);
599 divergence_ambient_error /= number_target_coords;
600 divergence_ambient_error = std::sqrt(divergence_ambient_error);
601 divergence_ambient_norm /= number_target_coords;
602 divergence_ambient_norm = std::sqrt(divergence_ambient_norm);
604 vector_of_scalar_clones_ambient_error /= number_target_coords;
605 vector_of_scalar_clones_ambient_error = std::sqrt(vector_of_scalar_clones_ambient_error);
606 vector_of_scalar_clones_ambient_norm /= number_target_coords;
607 vector_of_scalar_clones_ambient_norm = std::sqrt(vector_of_scalar_clones_ambient_norm);
609 divergence_of_scalar_clones_ambient_error /= number_target_coords;
610 divergence_of_scalar_clones_ambient_error = std::sqrt(divergence_of_scalar_clones_ambient_error);
611 divergence_of_scalar_clones_ambient_norm /= number_target_coords;
612 divergence_of_scalar_clones_ambient_norm = std::sqrt(divergence_of_scalar_clones_ambient_norm);
614 printf(
"Tangent Bundle Error: %g\n", tangent_bundle_error / tangent_bundle_norm);
615 printf(
"Point Value Error: %g\n", values_error / values_norm);
616 printf(
"Laplace-Beltrami Error: %g\n", laplacian_error / laplacian_norm);
617 printf(
"Gaussian Curvature Error: %g\n", gc_error / gc_norm);
618 printf(
"Surface Gradient (Ambient) Error: %g\n", gradient_ambient_error / gradient_ambient_norm);
619 printf(
"Surface Vector (VectorBasis) Error: %g\n", vector_ambient_error / vector_ambient_norm);
620 printf(
"Surface Divergence (VectorBasis) Error: %g\n", divergence_ambient_error / divergence_ambient_norm);
621 printf(
"Surface Vector (ScalarClones) Error: %g\n",
622 vector_of_scalar_clones_ambient_error / vector_of_scalar_clones_ambient_norm);
623 printf(
"Surface Divergence (ScalarClones) Error: %g\n",
624 divergence_of_scalar_clones_ambient_error / divergence_of_scalar_clones_ambient_norm);
628 Kokkos::Profiling::popRegion();
637 #ifdef COMPADRE_USE_MPI
Point evaluation of Gaussian curvature.
KOKKOS_INLINE_FUNCTION double sphere_harmonic54(double x, double y, double z)
Point evaluation of a scalar.
Scalar basis reused as many times as there are components in the vector resulting in a much cheaper p...
Lightweight Evaluator Helper This class is a lightweight wrapper for extracting and applying all rele...
constexpr SamplingFunctional ManifoldVectorPointSample
Point evaluations of the entire vector source function (but on a manifold, so it includes a transform...
Point evaluation of the gradient of a scalar.
Point evaluation of the laplacian of a scalar (could be on a manifold or not)
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...
int main(int argc, char **argv)
Vector polynomial basis having # of components _dimensions, or (_dimensions-1) in the case of manifol...
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...
import subprocess import os import re import math import sys import argparse d d d
Point evaluation of the divergence of a vector (results in a scalar)
KOKKOS_INLINE_FUNCTION void gradient_sphereHarmonic54_ambient(double *gradient, double x, double y, double z)
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 (allocates memory for output)
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) ...
KOKKOS_INLINE_FUNCTION double laplace_beltrami_sphere_harmonic54(double x, double y, double z)
std::string constraint_name
Point evaluation of a vector (reconstructs entire vector at once, requiring a ReconstructionSpace hav...