9 #include <Compadre_Config.h> 18 #ifdef COMPADRE_USE_MPI 22 #include <Kokkos_Timer.hpp> 23 #include <Kokkos_Core.hpp> 30 int main (
int argc,
char* args[]) {
33 #ifdef COMPADRE_USE_MPI 34 MPI_Init(&argc, &args);
41 bool all_passed =
true;
48 auto order = clp.
order;
55 bool keep_coefficients = number_of_batches==1;
59 const double failure_tolerance = 1e-9;
62 const double laplacian_failure_tolerance = 1e-9;
69 Kokkos::Profiling::pushRegion(
"Setup Point Data");
73 double h_spacing = 0.05;
74 int n_neg1_to_1 = 2*(1/h_spacing) + 1;
77 const int number_source_coords = std::pow(n_neg1_to_1, dimension);
80 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> source_coords_device(
"source coordinates",
81 number_source_coords, 3);
82 Kokkos::View<double**>::HostMirror source_coords = Kokkos::create_mirror_view(source_coords_device);
85 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> target_coords_device (
"target coordinates", number_target_coords, 3);
86 Kokkos::View<double**>::HostMirror target_coords = Kokkos::create_mirror_view(target_coords_device);
91 double this_coord[3] = {0,0,0};
92 for (
int i=-n_neg1_to_1/2; i<n_neg1_to_1/2+1; ++i) {
93 this_coord[0] = i*h_spacing;
94 for (
int j=-n_neg1_to_1/2; j<n_neg1_to_1/2+1; ++j) {
95 this_coord[1] = j*h_spacing;
96 for (
int k=-n_neg1_to_1/2; k<n_neg1_to_1/2+1; ++k) {
97 this_coord[2] = k*h_spacing;
99 source_coords(source_index,0) = this_coord[0];
100 source_coords(source_index,1) = this_coord[1];
101 source_coords(source_index,2) = this_coord[2];
106 source_coords(source_index,0) = this_coord[0];
107 source_coords(source_index,1) = this_coord[1];
108 source_coords(source_index,2) = 0;
113 source_coords(source_index,0) = this_coord[0];
114 source_coords(source_index,1) = 0;
115 source_coords(source_index,2) = 0;
121 for(
int i=0; i<number_target_coords; i++){
124 double rand_dir[3] = {0,0,0};
126 for (
int j=0; j<dimension; ++j) {
128 rand_dir[j] = ((double)rand() / (double) RAND_MAX) - 0.5;
132 for (
int j=0; j<dimension; ++j) {
133 target_coords(i,j) = rand_dir[j];
141 Kokkos::Profiling::popRegion();
142 Kokkos::Profiling::pushRegion(
"Creating Data");
148 Kokkos::deep_copy(source_coords_device, source_coords);
151 Kokkos::deep_copy(target_coords_device, target_coords);
154 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> sampling_data_device(
"samples of true solution",
155 source_coords_device.extent(0));
157 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> gradient_sampling_data_device(
"samples of true gradient",
158 source_coords_device.extent(0), dimension);
160 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> divergence_sampling_data_device
161 (
"samples of true solution for divergence test", source_coords_device.extent(0), dimension);
163 Kokkos::parallel_for(
"Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>
164 (0,source_coords.extent(0)), KOKKOS_LAMBDA(
const int i) {
167 double xval = source_coords_device(i,0);
168 double yval = (dimension>1) ? source_coords_device(i,1) : 0;
169 double zval = (dimension>2) ? source_coords_device(i,2) : 0;
172 sampling_data_device(i) =
trueSolution(xval, yval, zval, order, dimension);
175 double true_grad[3] = {0,0,0};
176 trueGradient(true_grad, xval, yval,zval, order, dimension);
178 for (
int j=0; j<dimension; ++j) {
179 gradient_sampling_data_device(i,j) = true_grad[j];
190 Kokkos::Profiling::popRegion();
191 Kokkos::Profiling::pushRegion(
"Neighbor Search");
200 double epsilon_multiplier = 1.4;
205 Kokkos::View<int*> neighbor_lists_device(
"neighbor lists",
207 Kokkos::View<int*>::HostMirror neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
210 Kokkos::View<int*> number_of_neighbors_list_device(
"number of neighbor lists",
211 number_target_coords);
212 Kokkos::View<int*>::HostMirror number_of_neighbors_list = Kokkos::create_mirror_view(number_of_neighbors_list_device);
215 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> epsilon_device(
"h supports", number_target_coords);
216 Kokkos::View<double*>::HostMirror epsilon = Kokkos::create_mirror_view(epsilon_device);
223 size_t storage_size = point_cloud_search.generateCRNeighborListsFromKNNSearch(
true , target_coords, neighbor_lists,
224 number_of_neighbors_list, epsilon, min_neighbors, epsilon_multiplier);
227 Kokkos::resize(neighbor_lists_device, storage_size);
228 neighbor_lists = Kokkos::create_mirror_view(neighbor_lists_device);
231 point_cloud_search.generateCRNeighborListsFromKNNSearch(
false , target_coords, neighbor_lists,
232 number_of_neighbors_list, epsilon, min_neighbors, epsilon_multiplier);
236 Kokkos::Profiling::popRegion();
247 Kokkos::deep_copy(neighbor_lists_device, neighbor_lists);
248 Kokkos::deep_copy(number_of_neighbors_list_device, number_of_neighbors_list);
249 Kokkos::deep_copy(epsilon_device, epsilon);
254 solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
274 my_GMLS.
setProblemData(neighbor_lists_device, number_of_neighbors_list_device, source_coords_device, target_coords_device, epsilon_device);
277 std::vector<TargetOperation> lro(5);
285 my_GMLS.addTargets(lro);
291 my_GMLS.setWeightingPower(2);
294 my_GMLS.generateAlphas(number_of_batches, keep_coefficients );
299 double instantiation_time = timer.seconds();
300 std::cout <<
"Took " << instantiation_time <<
"s to complete alphas generation." << std::endl;
302 Kokkos::Profiling::pushRegion(
"Apply Alphas to Data");
334 decltype(output_curl) scalar_coefficients;
335 if (number_of_batches==1)
336 scalar_coefficients =
338 (sampling_data_device);
343 Kokkos::Profiling::popRegion();
345 Kokkos::Profiling::pushRegion(
"Comparison");
351 for (
int i=0; i<number_target_coords; i++) {
354 double GMLS_value = output_value(i);
357 double GMLS_Laplacian = output_laplacian(i);
363 double GMLS_GradX = (number_of_batches==1) ? scalar_coefficients(i,1)*1./epsilon(i) : output_gradient(i,0);
366 double GMLS_GradY = (dimension>1) ? output_gradient(i,1) : 0;
369 double GMLS_GradZ = (dimension>2) ? output_gradient(i,2) : 0;
372 double GMLS_Divergence = output_divergence(i);
375 double GMLS_CurlX = (dimension>1) ? output_curl(i,0) : 0;
376 double GMLS_CurlY = (dimension>1) ? output_curl(i,1) : 0;
377 double GMLS_CurlZ = (dimension>2) ? output_curl(i,2) : 0;
381 double xval = target_coords(i,0);
382 double yval = (dimension>1) ? target_coords(i,1) : 0;
383 double zval = (dimension>2) ? target_coords(i,2) : 0;
386 double actual_value =
trueSolution(xval, yval, zval, order, dimension);
387 double actual_Laplacian =
trueLaplacian(xval, yval, zval, order, dimension);
389 double actual_Gradient[3] = {0,0,0};
390 trueGradient(actual_Gradient, xval, yval, zval, order, dimension);
392 double actual_Divergence;
393 actual_Divergence =
trueLaplacian(xval, yval, zval, order, dimension);
395 double actual_Curl[3] = {0,0,0};
406 if(GMLS_value!=GMLS_value || std::abs(actual_value - GMLS_value) > failure_tolerance) {
408 std::cout << i <<
" Failed Actual by: " << std::abs(actual_value - GMLS_value) << std::endl;
412 if(std::abs(actual_Laplacian - GMLS_Laplacian) > laplacian_failure_tolerance) {
414 std::cout << i <<
" Failed Laplacian by: " << std::abs(actual_Laplacian - GMLS_Laplacian) << std::endl;
418 if(std::abs(actual_Gradient[0] - GMLS_GradX) > failure_tolerance) {
420 std::cout << i <<
" Failed GradX by: " << std::abs(actual_Gradient[0] - GMLS_GradX) << std::endl;
422 if(std::abs(actual_Gradient[1] - GMLS_GradY) > failure_tolerance) {
424 std::cout << i <<
" Failed GradY by: " << std::abs(actual_Gradient[1] - GMLS_GradY) << std::endl;
428 if(std::abs(actual_Gradient[2] - GMLS_GradZ) > failure_tolerance) {
430 std::cout << i <<
" Failed GradZ by: " << std::abs(actual_Gradient[2] - GMLS_GradZ) << std::endl;
436 if(std::abs(actual_Divergence - GMLS_Divergence) > failure_tolerance) {
438 std::cout << i <<
" Failed Divergence by: " << std::abs(actual_Divergence - GMLS_Divergence) << std::endl;
445 tmp_diff += std::abs(actual_Curl[0] - GMLS_CurlX) + std::abs(actual_Curl[1] - GMLS_CurlY);
447 tmp_diff += std::abs(actual_Curl[2] - GMLS_CurlZ);
448 if(std::abs(tmp_diff) > failure_tolerance) {
450 std::cout << i <<
" Failed Curl by: " << std::abs(tmp_diff) << std::endl;
459 Kokkos::Profiling::popRegion();
468 #ifdef COMPADRE_USE_MPI 474 fprintf(stdout,
"Passed test \n");
477 fprintf(stdout,
"Failed test \n");
Point evaluation of the curl of a vector (results in a vector)
Class handling Kokkos command line arguments and returning parameters.
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...
int main(int argc, char *args[])
[Parse Command Line Arguments]
Point evaluation of a scalar.
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 void trueGradient(double *ans, double x, double y, double z, int order, int dimension)
Scalar basis reused as many times as there are components in the vector resulting in a much cheaper p...
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::View< output_data_type, output_array_layout, output_memory_space > applyFullPolynomialCoefficientsBasisToDataAllComponents(view_type_input_data sampling_data, bool scalar_as_vector_if_needed=true) const
Generation of polynomial reconstruction coefficients by applying to data in GMLS (allocates memory fo...
Point evaluation of the laplacian of a scalar (could be on a manifold or not)
Point evaluation of the divergence of a vector (results in a scalar)
Point evaluation of the gradient of a scalar.
KOKKOS_INLINE_FUNCTION double trueLaplacian(double x, double y, double z, int order, int dimension)
Generalized Moving Least Squares (GMLS)
KOKKOS_INLINE_FUNCTION double curlTestSolution(double x, double y, double z, int component, int dimension)
KOKKOS_INLINE_FUNCTION double divergenceTestSamples(double x, double y, double z, int component, int dimension)
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
KOKKOS_INLINE_FUNCTION double trueSolution(double x, double y, double z, int order, int dimension)
constexpr SamplingFunctional VectorPointSample
Point evaluations of the entire vector source function.