9 #include <Compadre_Config.h> 15 #ifdef COMPADRE_USE_MPI 19 #include <Kokkos_Timer.hpp> 20 #include <Kokkos_Core.hpp> 24 int main (
int argc,
char* args[])
27 #ifdef COMPADRE_USE_MPI 28 MPI_Init(&argc, &args);
31 bool 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);
133 my_GMLS.setWeightingPower(10);
135 std::vector<TargetOperation> lro(5);
141 my_GMLS.addTargets(lro);
142 my_GMLS.generateAlphas();
144 double instantiation_time = timer.seconds();
145 std::cout <<
"Took " << instantiation_time <<
"s to complete instantiation." << std::endl;
147 Kokkos::Profiling::pushRegion(
"Creating Data");
151 Kokkos::View<double*, Kokkos::HostSpace> sampling_data(
"samples of true solution", source_coords.extent(0));
152 Kokkos::View<double**, Kokkos::HostSpace> gradient_sampling_data(
"samples of true gradient", source_coords.extent(0), dimension);
153 Kokkos::View<double**, Kokkos::LayoutLeft, Kokkos::HostSpace> divergence_sampling_data(
"samples of true solution for divergence test", source_coords.extent(0), dimension);
154 Kokkos::parallel_for(
"Sampling Manufactured Solutions", Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(0,source_coords.extent(0)), KOKKOS_LAMBDA(
const int i) {
155 double xval = source_coords(i,0);
156 double yval = (dimension>1) ? source_coords(i,1) : 0;
157 double zval = (dimension>2) ? source_coords(i,2) : 0;
158 sampling_data(i) =
trueSolution(xval, yval, zval, order, dimension);
159 double true_grad[3] = {0,0,0};
160 trueGradient(true_grad, xval, yval,zval, order, dimension);
161 for (
int j=0; j<dimension; ++j) {
163 gradient_sampling_data(i,j) = true_grad[j];
166 Kokkos::Profiling::popRegion();
170 for (
int i=0; i<number_target_coords; i++) {
172 Kokkos::Profiling::pushRegion(
"Apply Alphas to Data");
246 double GMLS_CurlX = 0.0;
247 double GMLS_CurlY = 0.0;
248 double GMLS_CurlZ = 0.0;
250 for (
int j=0; j<dimension; ++j) {
257 for (
int j=0; j<dimension; ++j) {
263 Kokkos::Profiling::popRegion();
295 Kokkos::Profiling::pushRegion(
"Comparison");
297 double xval = target_coords(i,0);
298 double yval = (dimension>1) ? target_coords(i,1) : 0;
299 double zval = (dimension>2) ? target_coords(i,2) : 0;
301 double actual_value =
trueSolution(xval, yval, zval, order, dimension);
302 double actual_Laplacian =
trueLaplacian(xval, yval, zval, order, dimension);
303 double actual_Gradient[3] = {0,0,0};
304 trueGradient(actual_Gradient, xval, yval, zval, order, dimension);
305 double actual_Divergence;
306 actual_Divergence =
trueLaplacian(xval, yval, zval, order, dimension);
308 double actual_CurlX = 0;
309 double actual_CurlY = 0;
310 double actual_CurlZ = 0;
324 if(GMLS_value!=GMLS_value || std::abs(actual_value - GMLS_value) > failure_tolerance) {
326 std::cout <<
"Failed Actual by: " << std::abs(actual_value - GMLS_value) << std::endl;
329 if(std::abs(actual_Laplacian - GMLS_Laplacian) > failure_tolerance) {
331 std::cout <<
"Failed Laplacian by: " << std::abs(actual_Laplacian - GMLS_Laplacian) << std::endl;
334 if(std::abs(actual_Gradient[0] - GMLS_GradX) > failure_tolerance) {
336 std::cout <<
"Failed GradX by: " << std::abs(actual_Gradient[0] - GMLS_GradX) << std::endl;
340 if(std::abs(actual_Gradient[1] - GMLS_GradY) > failure_tolerance) {
342 std::cout <<
"Failed GradY by: " << std::abs(actual_Gradient[1] - GMLS_GradY) << std::endl;
347 if(std::abs(actual_Gradient[2] - GMLS_GradZ) > failure_tolerance) {
349 std::cout <<
"Failed GradZ by: " << std::abs(actual_Gradient[2] - GMLS_GradZ) << std::endl;
353 if(std::abs(actual_Divergence - GMLS_Divergence) > failure_tolerance) {
355 std::cout <<
"Failed Divergence by: " << std::abs(actual_Divergence - GMLS_Divergence) << std::endl;
360 tmp_diff += std::abs(actual_CurlX - GMLS_CurlX) + std::abs(actual_CurlY - GMLS_CurlY);
362 tmp_diff += std::abs(actual_CurlZ - GMLS_CurlZ);
363 if(std::abs(tmp_diff) > failure_tolerance) {
365 std::cout <<
"Failed Curl by: " << std::abs(tmp_diff) << std::endl;
367 Kokkos::Profiling::popRegion();
373 #ifdef COMPADRE_USE_MPI 378 fprintf(stdout,
"Passed test \n");
381 fprintf(stdout,
"Failed test \n");
int main(int argc, char *args[])
Manifold GMLS Example.
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 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)
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)
double applyAlphasToDataSingleComponentSingleTargetSite(view_type_data sampling_input_data, const int column_of_input, TargetOperation lro, const int target_index, const int evaluation_site_local_index, const int output_component_axis_1, const int output_component_axis_2, const int input_component_axis_1, const int input_component_axis_2, bool scalar_as_vector_if_needed=true) const
Dot product of alphas with sampling data, FOR A SINGLE target_index, where sampling data is in a 1D/2...
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)