24int main (
int argc,
char* args[])
27#ifdef COMPADRE_USE_MPI
28 MPI_Init(&argc, &args);
31bool all_passed =
true;
36 auto order = clp.
order;
43 const double failure_tolerance = 1e-9;
45 const int offset = 15;
49 std::cout << min_neighbors <<
" " << max_neighbors << std::endl;
50 std::uniform_int_distribution<int> gen_num_neighbors(min_neighbors, max_neighbors);
53 Kokkos::initialize(argc, args);
55 Kokkos::Profiling::pushRegion(
"Setup");
59 std::uniform_int_distribution<int> gen_neighbor_number(offset, N);
62 Kokkos::View<int**, Kokkos::HostSpace> neighbor_lists(
"neighbor lists", number_target_coords, max_neighbors+1);
63 Kokkos::View<double**, Kokkos::HostSpace> source_coords(
"neighbor coordinates", N, dimension);
64 Kokkos::View<double*, Kokkos::HostSpace> epsilon(
"h supports", number_target_coords);
66 for (
int i=0; i<number_target_coords; i++) {
71 for(
int i = 0; i < offset; i++){
72 for(
int j = 0; j < dimension; j++){
73 source_coords(i,j) = 0.1;
78 for(
int i = offset; i < N; i++){
79 double randx = (2.0*(double)rand() / (double) RAND_MAX - 1.0)*epsilon(0)/2.0;
80 double randy = (2.0*(double)rand() / (double) RAND_MAX - 1.0)*epsilon(0)/2.0;
81 double randz = (2.0*(double)rand() / (double) RAND_MAX - 1.0)*epsilon(0)/2.0;
82 source_coords(i,0) = randx;
83 if (dimension>1) source_coords(i,1) = randy;
84 if (dimension>2) source_coords(i,2) = randz;
87 const double target_epsilon = 0.1;
89 Kokkos::View<double**, Kokkos::HostSpace> target_coords (
"target coordinates", number_target_coords, dimension);
90 for(
int i = 0; i < number_target_coords; i++){
91 double randx = (2.0*(double)rand() / (double) RAND_MAX - 1.0)*target_epsilon/2.0;
92 double randy = (2.0*(double)rand() / (double) RAND_MAX - 1.0)*target_epsilon/2.0;
93 double randz = (2.0*(double)rand() / (double) RAND_MAX - 1.0)*target_epsilon/2.0;
94 target_coords(i,0) = randx;
95 if (dimension>1) target_coords(i,1) = randy;
96 if (dimension>2) target_coords(i,2) = randz;
100 for (
int i=0; i<number_target_coords; i++) {
103 int r = max_neighbors;
104 neighbor_lists(i,0) = r;
106 for(
int j=0; j<r; j++){
107 neighbor_lists(i,j+1) = offset + j + 1;
126 Kokkos::Profiling::popRegion();
129 GMLS my_GMLS(order, dimension,
130 solver_name.c_str(), problem_name.c_str(), constraint_name.c_str(),
132 my_GMLS.
setProblemData(neighbor_lists, source_coords, target_coords, epsilon);
135 std::vector<TargetOperation> lro(3);
145 double instantiation_time = timer.seconds();
146 std::cout <<
"Took " << instantiation_time <<
"s to complete instantiation." << std::endl;
148 Kokkos::Profiling::pushRegion(
"Creating Data");
152 Kokkos::View<double*, Kokkos::HostSpace> sampling_data(
"samples of true solution", source_coords.extent(0));
153 Kokkos::View<double**, Kokkos::HostSpace> gradient_sampling_data(
"samples of true gradient", source_coords.extent(0), dimension);
154 Kokkos::View<double**, Kokkos::LayoutLeft, Kokkos::HostSpace> divergence_sampling_data(
"samples of true solution for divergence test", source_coords.extent(0), dimension);
155 Kokkos::parallel_for(
"Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(0,source_coords.extent(0)), KOKKOS_LAMBDA(
const int i) {
156 double xval = source_coords(i,0);
157 double yval = (dimension>1) ? source_coords(i,1) : 0;
158 double zval = (dimension>2) ? source_coords(i,2) : 0;
159 sampling_data(i) =
trueSolution(xval, yval, zval, order, dimension);
160 double true_grad[3] = {0,0,0};
161 trueGradient(true_grad, xval, yval,zval, order, dimension);
162 for (
int j=0; j<dimension; ++j) {
164 gradient_sampling_data(i,j) = true_grad[j];
167 Kokkos::Profiling::popRegion();
171 for (
int i=0; i<number_target_coords; i++) {
173 Kokkos::Profiling::pushRegion(
"Apply Alphas to Data");
247 double GMLS_CurlX = 0.0;
248 double GMLS_CurlY = 0.0;
249 double GMLS_CurlZ = 0.0;
251 for (
int j=0; j<dimension; ++j) {
258 for (
int j=0; j<dimension; ++j) {
264 Kokkos::Profiling::popRegion();
296 Kokkos::Profiling::pushRegion(
"Comparison");
298 double xval = target_coords(i,0);
299 double yval = (dimension>1) ? target_coords(i,1) : 0;
300 double zval = (dimension>2) ? target_coords(i,2) : 0;
302 double actual_value =
trueSolution(xval, yval, zval, order, dimension);
303 double actual_Laplacian =
trueLaplacian(xval, yval, zval, order, dimension);
304 double actual_Gradient[3] = {0,0,0};
305 trueGradient(actual_Gradient, xval, yval, zval, order, dimension);
306 double actual_Divergence;
307 actual_Divergence =
trueLaplacian(xval, yval, zval, order, dimension);
309 double actual_CurlX = 0;
310 double actual_CurlY = 0;
311 double actual_CurlZ = 0;
325 if(GMLS_value!=GMLS_value || std::abs(actual_value - GMLS_value) > failure_tolerance) {
327 std::cout <<
"Failed Actual by: " << std::abs(actual_value - GMLS_value) << std::endl;
330 if(std::abs(actual_Laplacian - GMLS_Laplacian) > failure_tolerance) {
332 std::cout <<
"Failed Laplacian by: " << std::abs(actual_Laplacian - GMLS_Laplacian) << std::endl;
335 if(std::abs(actual_Gradient[0] - GMLS_GradX) > failure_tolerance) {
337 std::cout <<
"Failed GradX by: " << std::abs(actual_Gradient[0] - GMLS_GradX) << std::endl;
341 if(std::abs(actual_Gradient[1] - GMLS_GradY) > failure_tolerance) {
343 std::cout <<
"Failed GradY by: " << std::abs(actual_Gradient[1] - GMLS_GradY) << std::endl;
348 if(std::abs(actual_Gradient[2] - GMLS_GradZ) > failure_tolerance) {
350 std::cout <<
"Failed GradZ by: " << std::abs(actual_Gradient[2] - GMLS_GradZ) << std::endl;
354 if(std::abs(actual_Divergence - GMLS_Divergence) > failure_tolerance) {
356 std::cout <<
"Failed Divergence by: " << std::abs(actual_Divergence - GMLS_Divergence) << std::endl;
361 tmp_diff += std::abs(actual_CurlX - GMLS_CurlX) + std::abs(actual_CurlY - GMLS_CurlY);
363 tmp_diff += std::abs(actual_CurlZ - GMLS_CurlZ);
364 if(std::abs(tmp_diff) > failure_tolerance) {
366 std::cout <<
"Failed Curl by: " << std::abs(tmp_diff) << std::endl;
368 Kokkos::Profiling::popRegion();
374#ifdef COMPADRE_USE_MPI
379 fprintf(stdout,
"Passed test \n");
382 fprintf(stdout,
"Failed test \n");