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);
48 bool all_passed =
true;
55 auto order = clp.
order;
64 const double failure_tolerance = 1e-9;
71 Kokkos::Profiling::pushRegion(
"Setup Point Data");
75 double h_spacing = 0.05;
76 int n_neg1_to_1 = 2*(1/h_spacing) + 1;
79 const int number_source_coords = std::pow(n_neg1_to_1, dimension);
82 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> source_coords_device(
"source coordinates",
83 number_source_coords, 3);
84 Kokkos::View<double**>::HostMirror source_coords = Kokkos::create_mirror_view(source_coords_device);
87 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> target_coords_device (
"target coordinates", number_target_coords, 3);
88 Kokkos::View<double**>::HostMirror target_coords = Kokkos::create_mirror_view(target_coords_device);
93 double this_coord[3] = {0,0,0};
94 for (
int i=-n_neg1_to_1/2; i<n_neg1_to_1/2+1; ++i) {
95 this_coord[0] = i*h_spacing;
96 for (
int j=-n_neg1_to_1/2; j<n_neg1_to_1/2+1; ++j) {
97 this_coord[1] = j*h_spacing;
98 for (
int k=-n_neg1_to_1/2; k<n_neg1_to_1/2+1; ++k) {
99 this_coord[2] = k*h_spacing;
101 source_coords(source_index,0) = this_coord[0];
102 source_coords(source_index,1) = this_coord[1];
103 source_coords(source_index,2) = this_coord[2];
108 source_coords(source_index,0) = this_coord[0];
109 source_coords(source_index,1) = this_coord[1];
110 source_coords(source_index,2) = 0;
115 source_coords(source_index,0) = this_coord[0];
116 source_coords(source_index,1) = 0;
117 source_coords(source_index,2) = 0;
126 std::mt19937 rng(50);
128 std::uniform_int_distribution<int> gen_num_neighbours(0, source_index);
130 for (
int i=0; i<number_target_coords; ++i) {
131 const int source_site_to_copy = gen_num_neighbours(rng);
132 for (
int j=0; j<3; j++) {
133 target_coords(i, j) = source_coords(source_site_to_copy, j);
139 Kokkos::Profiling::popRegion();
140 Kokkos::Profiling::pushRegion(
"Creating Data");
146 Kokkos::deep_copy(source_coords_device, source_coords);
149 Kokkos::deep_copy(target_coords_device, target_coords);
152 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> vector_sampling_span_basis_data_device(
"samples of true vector solution",
153 source_coords_device.extent(0), dimension);
154 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> vector_sampling_single_polynomial_data_device(
"samples of true vector solution",
155 source_coords_device.extent(0), dimension);
157 Kokkos::parallel_for(
"Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>
158 (0,source_coords.extent(0)), KOKKOS_LAMBDA(
const int i) {
160 double xval = source_coords_device(i,0);
161 double yval = (dimension>1) ? source_coords_device(i,1) : 0;
162 double zval = (dimension>2) ? source_coords_device(i,2) : 0;
165 for (
int j=0; j<dimension; ++j) {
174 Kokkos::Profiling::popRegion();
175 Kokkos::Profiling::pushRegion(
"Neighbor Search");
187 double epsilon_multiplier = 2.2;
188 int estimated_upper_bound_number_neighbors =
189 point_cloud_search.getEstimatedNumberNeighborsUpperBound(min_neighbors, dimension, epsilon_multiplier);
191 Kokkos::View<int**, Kokkos::DefaultExecutionSpace> neighbor_lists_device(
"neighbor lists",
192 number_target_coords, estimated_upper_bound_number_neighbors);
193 Kokkos::View<int**>::HostMirror neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
196 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> epsilon_device(
"h supports", number_target_coords);
197 Kokkos::View<double*>::HostMirror epsilon = Kokkos::create_mirror_view(epsilon_device);
202 point_cloud_search.generate2DNeighborListsFromKNNSearch(
false , target_coords, neighbor_lists,
203 epsilon, min_neighbors, epsilon_multiplier);
207 Kokkos::Profiling::popRegion();
218 Kokkos::deep_copy(neighbor_lists_device, neighbor_lists);
219 Kokkos::deep_copy(epsilon_device, epsilon);
227 solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
244 vector_divfree_basis_gmls.
setProblemData(neighbor_lists_device, source_coords_device, target_coords_device, epsilon_device);
247 std::vector<TargetOperation> lro(4);
254 vector_divfree_basis_gmls.addTargets(lro);
260 vector_divfree_basis_gmls.setWeightingParameter(2);
263 vector_divfree_basis_gmls.generateAlphas(15 );
267 double instantiation_time = timer.seconds();
268 std::cout <<
"Took " << instantiation_time <<
"s to complete alphas generation." << std::endl;
270 Kokkos::Profiling::pushRegion(
"Apply Alphas to Data");
284 Evaluator gmls_evaluator_vector(&vector_divfree_basis_gmls);
298 Kokkos::Profiling::popRegion();
300 Kokkos::Profiling::pushRegion(
"Comparison");
305 for (
int i=0; i<number_target_coords; i++) {
307 double GMLS_DivFree_VectorX = output_vector_evaluation(i, 0);
308 double GMLS_DivFree_VectorY = (dimension>1) ? output_vector_evaluation(i, 1) : 0;
309 double GMLS_DivFree_VectorZ = (dimension>2) ? output_vector_evaluation(i, 2) : 0;
312 double GMLS_Curl_DivFree_VectorX = output_curl_vector_evaluation(i, 0);
313 double GMLS_Curl_DivFree_VectorY = (dimension>2) ? output_curl_vector_evaluation(i, 1) : 0;
314 double GMLS_Curl_DivFree_VectorZ = (dimension>2) ? output_curl_vector_evaluation(i, 2) : 0;
317 double GMLS_CurlCurl_DivFree_VectorX = output_curlcurl_vector_evaluation(i, 0);
318 double GMLS_CurlCurl_DivFree_VectorY = (dimension>1) ? output_curlcurl_vector_evaluation(i, 1) : 0;
319 double GMLS_CurlCurl_DivFree_VectorZ = (dimension>2) ? output_curlcurl_vector_evaluation(i, 2) : 0;
322 double GMLS_Gradient_DivFree_VectorXX = output_gradient_vector_evaluation(i, 0);
323 double GMLS_Gradient_DivFree_VectorXY = output_gradient_vector_evaluation(i, 1);
324 double GMLS_Gradient_DivFree_VectorXZ = (dimension==3) ? output_gradient_vector_evaluation(i, 2) : 0.0;
325 double GMLS_Gradient_DivFree_VectorYX = (dimension==3) ? output_gradient_vector_evaluation(i, 3) : output_gradient_vector_evaluation(i, 2);
326 double GMLS_Gradient_DivFree_VectorYY = (dimension==3) ? output_gradient_vector_evaluation(i, 4) : output_gradient_vector_evaluation(i, 3);
327 double GMLS_Gradient_DivFree_VectorYZ = (dimension==3) ? output_gradient_vector_evaluation(i, 5) : 0.0;
328 double GMLS_Gradient_DivFree_VectorZX = (dimension==3) ? output_gradient_vector_evaluation(i, 6) : 0.0;
329 double GMLS_Gradient_DivFree_VectorZY = (dimension==3) ? output_gradient_vector_evaluation(i, 7) : 0.0;
330 double GMLS_Gradient_DivFree_VectorZZ = (dimension==3) ? output_gradient_vector_evaluation(i, 8) : 0.0;
333 double xval = target_coords(i,0);
334 double yval = (dimension>1) ? target_coords(i,1) : 0;
335 double zval = (dimension>2) ? target_coords(i,2) : 0;
338 double actual_vector[3] = {0, 0, 0};
350 double actual_curl_vector[3] = {0, 0, 0};
360 double actual_curlcurl_vector[3] = {0, 0, 0};
371 double actual_gradient_vector[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
373 for (
int axes = 0; axes < 9; ++axes)
377 for (
int axes = 0; axes < 4; ++axes)
382 if(std::abs(actual_vector[0] - GMLS_DivFree_VectorX) > failure_tolerance) {
384 std::cout << i <<
" Failed VectorX by: " << std::abs(actual_vector[0] - GMLS_DivFree_VectorX) << std::endl;
386 if(std::abs(actual_vector[1] - GMLS_DivFree_VectorY) > failure_tolerance) {
388 std::cout << i <<
" Failed VectorY by: " << std::abs(actual_vector[1] - GMLS_DivFree_VectorY) << std::endl;
392 if(std::abs(actual_vector[2] - GMLS_DivFree_VectorZ) > failure_tolerance) {
394 std::cout << i <<
" Failed VectorZ by: " << std::abs(actual_vector[2] - GMLS_DivFree_VectorZ) << std::endl;
401 if(std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) > failure_tolerance) {
403 std::cout << i <<
" Failed curl VectorX by: " << std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorX) << std::endl;
405 }
else if (dimension>2) {
406 if(std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) > failure_tolerance) {
408 std::cout << i <<
" Failed curl VectorX by: " << std::abs(actual_curl_vector[0] - GMLS_Curl_DivFree_VectorX) << std::endl;
410 if(std::abs(actual_curl_vector[1] - GMLS_Curl_DivFree_VectorY) > failure_tolerance) {
412 std::cout << i <<
" Failed curl VectorY by: " << std::abs(actual_curl_vector[1] - GMLS_Curl_DivFree_VectorY) << std::endl;
414 if(std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorZ) > failure_tolerance) {
416 std::cout << i <<
" Failed curl VectorZ by: " << std::abs(actual_curl_vector[2] - GMLS_Curl_DivFree_VectorZ) << std::endl;
421 if(std::abs(actual_curlcurl_vector[0] - GMLS_CurlCurl_DivFree_VectorX) > failure_tolerance) {
423 std::cout << i <<
" Failed curl curl VectorX by: " << std::abs(actual_curlcurl_vector[0] - GMLS_CurlCurl_DivFree_VectorX) << std::endl;
426 if(std::abs(actual_curlcurl_vector[1] - GMLS_CurlCurl_DivFree_VectorY) > failure_tolerance) {
428 std::cout << i <<
" Failed curl curl VectorY by: " << std::abs(actual_curlcurl_vector[1] - GMLS_CurlCurl_DivFree_VectorY) << std::endl;
432 if(std::abs(actual_curlcurl_vector[2] - GMLS_CurlCurl_DivFree_VectorZ) > failure_tolerance) {
434 std::cout << i <<
" Failed curl curl VectorZ by: " << std::abs(actual_curlcurl_vector[2] - GMLS_CurlCurl_DivFree_VectorZ) << std::endl;
440 if (std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) > failure_tolerance) {
442 std::cout << i <<
" Failed gradient_x VectorX by: " << std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) << std::endl;
444 if (std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) > failure_tolerance) {
446 std::cout << i <<
" Failed gradient_y VectorX by: " << std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) << std::endl;
448 if (std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorXZ) > failure_tolerance) {
450 std::cout << i <<
" Failed gradient_z VectorX by: " << std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorXZ) << std::endl;
453 if (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYX) > failure_tolerance) {
455 std::cout << i <<
" Failed gradient_x VectorY by: " << std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYX) << std::endl;
457 if (std::abs(actual_gradient_vector[4] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) {
459 std::cout << i <<
" Failed gradient_y VectorY by: " << std::abs(actual_gradient_vector[4] - GMLS_Gradient_DivFree_VectorYY) << std::endl;
461 if (std::abs(actual_gradient_vector[5] - GMLS_Gradient_DivFree_VectorYZ) > failure_tolerance) {
463 std::cout << i <<
" Failed gradient_z VectorY by: " << std::abs(actual_gradient_vector[5] - GMLS_Gradient_DivFree_VectorYZ) << std::endl;
466 if (std::abs(actual_gradient_vector[6] - GMLS_Gradient_DivFree_VectorZX) > failure_tolerance) {
468 std::cout << i <<
" Failed gradient_x VectorZ by: " << std::abs(actual_gradient_vector[6] - GMLS_Gradient_DivFree_VectorZX) << std::endl;
470 if (std::abs(actual_gradient_vector[7] - GMLS_Gradient_DivFree_VectorZY) > failure_tolerance) {
472 std::cout << i <<
" Failed gradient_y VectorZ by: " << std::abs(actual_gradient_vector[7] - GMLS_Gradient_DivFree_VectorZY) << std::endl;
474 if (std::abs(actual_gradient_vector[8] - GMLS_Gradient_DivFree_VectorZZ) > failure_tolerance) {
476 std::cout << i <<
" Failed gradient_z VectorZ by: " << std::abs(actual_gradient_vector[8] - GMLS_Gradient_DivFree_VectorZZ) << std::endl;
481 if (std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) > failure_tolerance) {
483 std::cout << i <<
" Failed gradient_x VectorX by: " << std::abs(actual_gradient_vector[0] - GMLS_Gradient_DivFree_VectorXX) << std::endl;
485 if (std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) > failure_tolerance) {
487 std::cout << i <<
" Failed gradient_y VectorX by: " << std::abs(actual_gradient_vector[1] - GMLS_Gradient_DivFree_VectorXY) << std::endl;
490 if (std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorYX) > failure_tolerance) {
492 std::cout << i <<
" Failed gradient_x VectorY by: " << std::abs(actual_gradient_vector[2] - GMLS_Gradient_DivFree_VectorYX) << std::endl;
494 if (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) {
496 std::cout << i <<
" Failed gradient_y VectorY by: " << (std::abs(actual_gradient_vector[3] - GMLS_Gradient_DivFree_VectorYY) > failure_tolerance) << std::endl;
504 Kokkos::Profiling::popRegion();
513 #ifdef COMPADRE_USE_MPI
519 fprintf(stdout,
"Passed test \n");
522 fprintf(stdout,
"Failed test \n");
KOKKOS_INLINE_FUNCTION double divfreeTestSolution_span_basis(double x, double y, double z, int component, int dimension, int exact_order)
Lightweight Evaluator Helper This class is a lightweight wrapper for extracting and applying all rele...
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)
int main(int argc, char **argv)
Point evaluation of the curl of a vector (results in a vector)
KOKKOS_INLINE_FUNCTION double curlcurldivfreeTestSolution_single_polynomial(double x, double y, double z, int component, int dimension)
Point evaluation of the curl of a curl of a vector (results in a vector)
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)
Divergence-free vector polynomial basis.
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)
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) ...
std::string constraint_name
constexpr SamplingFunctional VectorPointSample
Point evaluations of the entire vector source function.
Point evaluation of the gradient of a vector (results in a matrix, NOT CURRENTLY IMPLEMENTED) ...
Point evaluation of a vector (reconstructs entire vector at once, requiring a ReconstructionSpace hav...