16#include <Compadre_Config.h>
24#ifdef COMPADRE_USE_MPI
28#include <Kokkos_Timer.hpp>
29#include <Kokkos_Core.hpp>
36int main (
int argc,
char* args[]) {
39#ifdef COMPADRE_USE_MPI
40MPI_Init(&argc, &args);
44Kokkos::initialize(argc, args);
47bool all_passed =
true;
54 auto order = clp.
order;
63 const double failure_tolerance = 1e-9;
66 const double laplacian_failure_tolerance = 1e-9;
76 double h_spacing = 0.05;
77 int n_neg1_to_1 = 2*(1/h_spacing) + 1;
80 const int number_source_coords = std::pow(n_neg1_to_1, dimension);
83 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> source_coords_device(
"source coordinates",
84 number_source_coords, 3);
85 Kokkos::View<double**>::HostMirror source_coords = Kokkos::create_mirror_view(source_coords_device);
88 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> target_coords_device (
"target coordinates", number_target_coords, 3);
89 Kokkos::View<double**>::HostMirror target_coords = Kokkos::create_mirror_view(target_coords_device);
94 double this_coord[3] = {0,0,0};
95 for (
int i=-n_neg1_to_1/2; i<n_neg1_to_1/2+1; ++i) {
96 this_coord[0] = i*h_spacing;
97 for (
int j=-n_neg1_to_1/2; j<n_neg1_to_1/2+1; ++j) {
98 this_coord[1] = j*h_spacing;
99 for (
int k=-n_neg1_to_1/2; k<n_neg1_to_1/2+1; ++k) {
100 this_coord[2] = k*h_spacing;
102 source_coords(source_index,0) = this_coord[0];
103 source_coords(source_index,1) = this_coord[1];
104 source_coords(source_index,2) = this_coord[2];
109 source_coords(source_index,0) = this_coord[0];
110 source_coords(source_index,1) = this_coord[1];
111 source_coords(source_index,2) = 0;
116 source_coords(source_index,0) = this_coord[0];
117 source_coords(source_index,1) = 0;
118 source_coords(source_index,2) = 0;
124 for(
int i=0; i<number_target_coords; i++){
127 double rand_dir[3] = {0,0,0};
129 for (
int j=0; j<dimension; ++j) {
131 rand_dir[j] = ((double)rand() / (double) RAND_MAX) - 0.5;
135 for (
int j=0; j<dimension; ++j) {
136 target_coords(i,j) = rand_dir[j];
149 Kokkos::deep_copy(source_coords_device, source_coords);
152 Kokkos::deep_copy(target_coords_device, target_coords);
155 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> sampling_data_device(
"samples of true solution",
156 source_coords_device.extent(0));
158 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> gradient_sampling_data_device(
"samples of true gradient",
159 source_coords_device.extent(0), dimension);
161 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> divergence_sampling_data_device
162 (
"samples of true solution for divergence test", source_coords_device.extent(0), dimension);
164 Kokkos::parallel_for(
"Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>
165 (0,source_coords.extent(0)), KOKKOS_LAMBDA(
const int i) {
168 double xval = source_coords_device(i,0);
169 double yval = (dimension>1) ? source_coords_device(i,1) : 0;
170 double zval = (dimension>2) ? source_coords_device(i,2) : 0;
173 sampling_data_device(i) =
trueSolution(xval, yval, zval, order, dimension);
176 double true_grad[3] = {0,0,0};
177 trueGradient(true_grad, xval, yval,zval, order, dimension);
179 for (
int j=0; j<dimension; ++j) {
180 gradient_sampling_data_device(i,j) = true_grad[j];
197 solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
201 std::vector<TargetOperation> lro(5);
209 my_GMLS.addTargets(lro);
212 my_GMLS.setWeightingType(WeightingFunctionType::Power);
215 my_GMLS.setWeightingParameter(2);
218 my_GMLS.setSourceSites(source_coords_device);
226 for (
int i=0; i<number_target_coords; i++) {
245 Kokkos::View<double**, Kokkos::DefaultExecutionSpace> single_target_coords_device (
"single target coordinates", 1, 3);
246 Kokkos::View<double**>::HostMirror single_target_coords = Kokkos::create_mirror_view(single_target_coords_device);
247 for (
int j=0; j<3; ++j) {
248 single_target_coords(0,j) = target_coords(i,j);
251 Kokkos::deep_copy(single_target_coords_device, single_target_coords);
258 double epsilon_multiplier = 1.5;
259 int estimated_upper_bound_number_neighbors =
260 point_cloud_search.getEstimatedNumberNeighborsUpperBound(min_neighbors, dimension, epsilon_multiplier);
262 Kokkos::View<int**, Kokkos::DefaultExecutionSpace> single_neighbor_lists_device(
"neighbor lists",
263 1, estimated_upper_bound_number_neighbors);
264 Kokkos::View<int**>::HostMirror single_neighbor_lists = Kokkos::create_mirror_view(single_neighbor_lists_device);
267 Kokkos::View<double*, Kokkos::DefaultExecutionSpace> single_epsilon_device(
"h supports", 1);
268 Kokkos::View<double*>::HostMirror single_epsilon = Kokkos::create_mirror_view(single_epsilon_device);
273 point_cloud_search.generate2DNeighborListsFromKNNSearch(
false , single_target_coords,
274 single_neighbor_lists, single_epsilon, min_neighbors, epsilon_multiplier);
283 Kokkos::deep_copy(single_neighbor_lists_device, single_neighbor_lists);
284 Kokkos::deep_copy(single_epsilon_device, single_epsilon);
288 my_GMLS.setNeighborLists(single_neighbor_lists_device);
289 my_GMLS.setTargetSites(single_target_coords_device);
290 my_GMLS.setWindowSizes(single_epsilon_device);
294 my_GMLS.generateAlphas(1,
true );
299 double instantiation_time = timer.seconds();
300 std::cout <<
"Took " << instantiation_time <<
"s to complete alphas generation." << std::endl;
335 (sampling_data_device);
345 double GMLS_value = output_value(0);
348 double GMLS_Laplacian = output_laplacian(0);
354 double GMLS_GradX = scalar_coefficients(0,1)*1./single_epsilon(0);
358 double GMLS_GradY = (dimension>1) ? output_gradient(0,1) : 0;
361 double GMLS_GradZ = (dimension>2) ? output_gradient(0,2) : 0;
364 double GMLS_Divergence = output_divergence(0);
367 double GMLS_CurlX = (dimension>1) ? output_curl(0,0) : 0;
368 double GMLS_CurlY = (dimension>1) ? output_curl(0,1) : 0;
369 double GMLS_CurlZ = (dimension>2) ? output_curl(0,2) : 0;
373 double xval = target_coords(i,0);
374 double yval = (dimension>1) ? target_coords(i,1) : 0;
375 double zval = (dimension>2) ? target_coords(i,2) : 0;
378 double actual_value =
trueSolution(xval, yval, zval, order, dimension);
379 double actual_Laplacian =
trueLaplacian(xval, yval, zval, order, dimension);
381 double actual_Gradient[3] = {0,0,0};
382 trueGradient(actual_Gradient, xval, yval, zval, order, dimension);
384 double actual_Divergence;
385 actual_Divergence =
trueLaplacian(xval, yval, zval, order, dimension);
387 double actual_Curl[3] = {0,0,0};
398 if(GMLS_value!=GMLS_value || std::abs(actual_value - GMLS_value) > failure_tolerance) {
400 std::cout << i <<
" Failed Actual by: " << std::abs(actual_value - GMLS_value) << std::endl;
404 if(std::abs(actual_Laplacian - GMLS_Laplacian) > laplacian_failure_tolerance) {
406 std::cout << i <<
" Failed Laplacian by: " << std::abs(actual_Laplacian - GMLS_Laplacian) << std::endl;
410 if(std::abs(actual_Gradient[0] - GMLS_GradX) > failure_tolerance) {
412 std::cout << i <<
" Failed GradX by: " << std::abs(actual_Gradient[0] - GMLS_GradX) << std::endl;
414 if(std::abs(actual_Gradient[1] - GMLS_GradY) > failure_tolerance) {
416 std::cout << i <<
" Failed GradY by: " << std::abs(actual_Gradient[1] - GMLS_GradY) << std::endl;
420 if(std::abs(actual_Gradient[2] - GMLS_GradZ) > failure_tolerance) {
422 std::cout << i <<
" Failed GradZ by: " << std::abs(actual_Gradient[2] - GMLS_GradZ) << std::endl;
428 if(std::abs(actual_Divergence - GMLS_Divergence) > failure_tolerance) {
430 std::cout << i <<
" Failed Divergence by: " << std::abs(actual_Divergence - GMLS_Divergence) << std::endl;
437 tmp_diff += std::abs(actual_Curl[0] - GMLS_CurlX) + std::abs(actual_Curl[1] - GMLS_CurlY);
439 tmp_diff += std::abs(actual_Curl[2] - GMLS_CurlZ);
440 if(std::abs(tmp_diff) > failure_tolerance) {
442 std::cout << i <<
" Failed Curl by: " << std::abs(tmp_diff) << std::endl;
458#ifdef COMPADRE_USE_MPI
464 fprintf(stdout,
"Passed test \n");
467 fprintf(stdout,
"Failed test \n");
int main(int argc, char *args[])
[Parse Command Line Arguments]
KOKKOS_INLINE_FUNCTION double trueSolution(double x, double y, double z, int order, int dimension)
KOKKOS_INLINE_FUNCTION void trueGradient(double *ans, double x, double y, double z, int order, int dimension)
KOKKOS_INLINE_FUNCTION double divergenceTestSamples(double x, double y, double z, int component, int dimension)
KOKKOS_INLINE_FUNCTION double curlTestSolution(double x, double y, double z, int component, int dimension)
KOKKOS_INLINE_FUNCTION double trueLaplacian(double x, double y, double z, int order, int dimension)
Lightweight Evaluator Helper This class is a lightweight wrapper for extracting and applying all rele...
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...
Generalized Moving Least Squares (GMLS)
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....
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...
@ LaplacianOfScalarPointEvaluation
Point evaluation of the laplacian of a scalar (could be on a manifold or not)
@ GradientOfScalarPointEvaluation
Point evaluation of the gradient of a scalar.
@ CurlOfVectorPointEvaluation
Point evaluation of the curl of a vector (results in a vector)
@ DivergenceOfVectorPointEvaluation
Point evaluation of the divergence of a vector (results in a scalar)
@ ScalarPointEvaluation
Point evaluation of a scalar.
constexpr SamplingFunctional VectorPointSample
Point evaluations of the entire vector source function.
@ VectorOfScalarClonesTaylorPolynomial
Scalar basis reused as many times as there are components in the vector resulting in a much cheaper p...
std::string constraint_name