9 #include <Compadre_Config.h> 
   16 #ifdef COMPADRE_USE_MPI 
   20 #include <Kokkos_Timer.hpp> 
   21 #include <Kokkos_Core.hpp> 
   23 using namespace Compadre;
 
   28 int main (
int argc, 
char* args[]) {
 
   31 #ifdef COMPADRE_USE_MPI 
   32 MPI_Init(&argc, &args);
 
   36 Kokkos::initialize(argc, args);
 
   39 bool all_passed = 
true;
 
   48     int constraint_type = 0; 
 
   50         int arg7toi = atoi(args[6]);
 
   52             constraint_type = arg7toi;
 
   62         int arg6toi = atoi(args[5]);
 
   64             problem_type = arg6toi;
 
   75         int arg5toi = atoi(args[4]);
 
   77             solver_type = arg5toi;
 
   85         int arg4toi = atoi(args[3]);
 
   93     int number_target_coords = 200; 
 
   95         int arg3toi = atoi(args[2]);
 
   97             number_target_coords = arg3toi;
 
  105         int arg2toi = atoi(args[1]);
 
  113     const double failure_tolerance = 1e-9;
 
  120     Kokkos::Profiling::pushRegion(
"Setup Point Data");
 
  124     double h_spacing = 0.05;
 
  125     int n_neg1_to_1 = 2*(1/h_spacing) + 1; 
 
  128     const int number_source_coords = std::pow(n_neg1_to_1, dimension);
 
  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);
 
  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);
 
  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;
 
  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];
 
  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;
 
  164             source_coords(source_index,0) = this_coord[0];
 
  165             source_coords(source_index,1) = 0;
 
  166             source_coords(source_index,2) = 0;
 
  175     std::mt19937 rng(50);
 
  177     std::uniform_int_distribution<int> gen_num_neighbours(0, source_index);
 
  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);
 
  188     Kokkos::Profiling::popRegion();
 
  189     Kokkos::Profiling::pushRegion(
"Creating Data");
 
  195     Kokkos::deep_copy(source_coords_device, source_coords);
 
  198     Kokkos::deep_copy(target_coords_device, target_coords);
 
  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);
 
  206     Kokkos::parallel_for(
"Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>
 
  207             (0,source_coords.extent(0)), KOKKOS_LAMBDA(
const int 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;
 
  214         for (
int j=0; j<dimension; ++j) {
 
  223     Kokkos::Profiling::popRegion();
 
  224     Kokkos::Profiling::pushRegion(
"Neighbor Search");
 
  236     double epsilon_multiplier = 2.2;
 
  237     int estimated_upper_bound_number_neighbors =
 
  238         point_cloud_search.getEstimatedNumberNeighborsUpperBound(min_neighbors, dimension, epsilon_multiplier);
 
  240     Kokkos::View<int**, Kokkos::DefaultExecutionSpace> neighbor_lists_device(
"neighbor lists",
 
  241             number_target_coords, estimated_upper_bound_number_neighbors); 
 
  242     Kokkos::View<int**>::HostMirror neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
 
  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);
 
  251     point_cloud_search.generate2DNeighborListsFromKNNSearch(
false , target_coords, neighbor_lists, 
 
  252             epsilon, min_neighbors, epsilon_multiplier);
 
  256     Kokkos::Profiling::popRegion();
 
  267     Kokkos::deep_copy(neighbor_lists_device, neighbor_lists);
 
  268     Kokkos::deep_copy(epsilon_device, epsilon);
 
  271     std::string solver_name;
 
  272     if (solver_type == 0) { 
 
  274     } 
else if (solver_type == 1) { 
 
  276     } 
else if (solver_type == 2) { 
 
  281     std::string problem_name;
 
  282     if (problem_type == 0) { 
 
  283         problem_name = 
"STANDARD";
 
  284     } 
else if (problem_type == 1) { 
 
  285         problem_name = 
"MANIFOLD";
 
  289     std::string constraint_name;
 
  290     if (constraint_type == 0) { 
 
  291         constraint_name = 
"NO_CONSTRAINT";
 
  292     } 
else if (constraint_type == 1) { 
 
  293         constraint_name = 
"NEUMANN_GRAD_SCALAR";
 
  302                                    solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
 
  319     vector_divfree_basis_gmls.
setProblemData(neighbor_lists_device, source_coords_device, target_coords_device, epsilon_device);
 
  322     std::vector<TargetOperation> lro(4);
 
  329     vector_divfree_basis_gmls.addTargets(lro);
 
  335     vector_divfree_basis_gmls.setWeightingPower(2);
 
  338     vector_divfree_basis_gmls.generateAlphas(15 );
 
  342     double instantiation_time = timer.seconds();
 
  343     std::cout << 
"Took " << instantiation_time << 
"s to complete alphas generation." << std::endl;
 
  345     Kokkos::Profiling::pushRegion(
"Apply Alphas to Data");
 
  359     Evaluator gmls_evaluator_vector(&vector_divfree_basis_gmls);
 
  373     Kokkos::Profiling::popRegion();
 
  375     Kokkos::Profiling::pushRegion(
"Comparison");
 
  380     for (
int i=0; i<number_target_coords; i++) {
 
  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;
 
  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;
 
  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;
 
  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;
 
  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;
 
  413         double actual_vector[3] = {0, 0, 0};
 
  425         double actual_curl_vector[3] = {0, 0, 0};
 
  435         double actual_curlcurl_vector[3] = {0, 0, 0};
 
  446         double actual_gradient_vector[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
 
  448             for (
int axes = 0; axes < 9; ++axes)
 
  452             for (
int axes = 0; axes < 4; ++axes) 
 
  457         if(std::abs(actual_vector[0] - GMLS_DivFree_VectorX) > failure_tolerance) {
 
  459             std::cout << i << 
" Failed VectorX by: " << std::abs(actual_vector[0] - GMLS_DivFree_VectorX) << std::endl;
 
  461                 if(std::abs(actual_vector[1] - GMLS_DivFree_VectorY) > failure_tolerance) {
 
  463                     std::cout << i << 
" Failed VectorY by: " << std::abs(actual_vector[1] - GMLS_DivFree_VectorY) << std::endl;
 
  467                 if(std::abs(actual_vector[2] - GMLS_DivFree_VectorZ) > failure_tolerance) {
 
  469                     std::cout << i << 
" Failed VectorZ by: " << std::abs(actual_vector[2] - GMLS_DivFree_VectorZ) << std::endl;
 
  476             if(std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) > failure_tolerance) {
 
  478                 std::cout << i << 
" Failed curl VectorX by: " << std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorX) << std::endl;
 
  480         } 
else if (dimension>2) {
 
  481             if(std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) > failure_tolerance) {
 
  483                 std::cout << i << 
" Failed curl VectorX by: " << std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) << std::endl;
 
  485             if(std::abs(actual_curl_vector[1] - GMLS_Curl_DivFree_VectorY) > failure_tolerance) {
 
  487                 std::cout << i << 
" Failed curl VectorY by: " << std::abs(actual_curl_vector[1] - GMLS_Curl_DivFree_VectorY) << std::endl;
 
  489             if(std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorZ) > failure_tolerance) {
 
  491                 std::cout << i << 
" Failed curl VectorZ by: " << std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorZ) << std::endl;
 
  496         if(std::abs(actual_curlcurl_vector[0] - GMLS_CurlCurl_DivFree_VectorX) > failure_tolerance) {
 
  498             std::cout << i << 
" Failed curl curl VectorX by: " << std::abs(actual_curlcurl_vector[0] - GMLS_CurlCurl_DivFree_VectorX) << std::endl;
 
  501             if(std::abs(actual_curlcurl_vector[1] - GMLS_CurlCurl_DivFree_VectorY) > failure_tolerance) {
 
  503                 std::cout << i << 
" Failed curl curl VectorY by: " << std::abs(actual_curlcurl_vector[1] - GMLS_CurlCurl_DivFree_VectorY) << std::endl;
 
  507             if(std::abs(actual_curlcurl_vector[2] - GMLS_CurlCurl_DivFree_VectorZ) > failure_tolerance) {
 
  509                 std::cout << i << 
" Failed curl curl VectorZ by: " << std::abs(actual_curlcurl_vector[2] - GMLS_CurlCurl_DivFree_VectorZ) << std::endl;
 
  515             if (std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) > failure_tolerance) {
 
  517                 std::cout << i << 
" Failed gradient_x VectorX by: " << std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) << std::endl;
 
  519             if (std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) > failure_tolerance) {
 
  521                 std::cout << i << 
" Failed gradient_y VectorX by: " << std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) << std::endl;
 
  523             if (std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorXZ) > failure_tolerance) {
 
  525                 std::cout << i << 
" Failed gradient_z VectorX by: " << std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorXZ) << std::endl;
 
  528             if (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYX) > failure_tolerance) {
 
  530                 std::cout << i << 
" Failed gradient_x VectorY by: " << std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYX) << std::endl;
 
  532             if (std::abs(actual_gradient_vector[4] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) {
 
  534                 std::cout << i << 
" Failed gradient_y VectorY by: " << std::abs(actual_gradient_vector[4] - GMLS_Gradient_DivFree_VectorYY) << std::endl;
 
  536             if (std::abs(actual_gradient_vector[5] - GMLS_Gradient_DivFree_VectorYZ) > failure_tolerance) {
 
  538                 std::cout << i << 
" Failed gradient_z VectorY by: " << std::abs(actual_gradient_vector[5] - GMLS_Gradient_DivFree_VectorYZ) << std::endl;
 
  541             if (std::abs(actual_gradient_vector[6] - GMLS_Gradient_DivFree_VectorZX) > failure_tolerance) {
 
  543                 std::cout << i << 
" Failed gradient_x VectorZ by: " << std::abs(actual_gradient_vector[6] - GMLS_Gradient_DivFree_VectorZX) << std::endl;
 
  545             if (std::abs(actual_gradient_vector[7] - GMLS_Gradient_DivFree_VectorZY) > failure_tolerance) {
 
  547                 std::cout << i << 
" Failed gradient_y VectorZ by: " << std::abs(actual_gradient_vector[7] - GMLS_Gradient_DivFree_VectorZY) << std::endl;
 
  549             if (std::abs(actual_gradient_vector[8] - GMLS_Gradient_DivFree_VectorZZ) > failure_tolerance) {
 
  551                 std::cout << i << 
" Failed gradient_z VectorZ by: " << std::abs(actual_gradient_vector[8] - GMLS_Gradient_DivFree_VectorZZ) << std::endl;
 
  556             if (std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) > failure_tolerance) {
 
  558                 std::cout << i << 
" Failed gradient_x VectorX by: " << std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) << std::endl;
 
  560             if (std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) > failure_tolerance) {
 
  562                 std::cout << i << 
" Failed gradient_y VectorX by: " << std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) << std::endl;
 
  565             if (std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorYX) > failure_tolerance) {
 
  567                 std::cout << i << 
" Failed gradient_x VectorY by: " << std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorYX) << std::endl;
 
  569             if (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) {
 
  571                 std::cout << i << 
" Failed gradient_y VectorY by: " << (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) << std::endl;
 
  579     Kokkos::Profiling::popRegion();
 
  588 #ifdef COMPADRE_USE_MPI 
  594     fprintf(stdout, 
"Passed test \n");
 
  597     fprintf(stdout, 
"Failed test \n");
 
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] 
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.