-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSplineKokkos2DBase.cpp
More file actions
105 lines (93 loc) · 3.58 KB
/
Copy pathtestSplineKokkos2DBase.cpp
File metadata and controls
105 lines (93 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Constructor test for new representation of Kokkos spline
// We will be comparing this against the serial version
#include "BSpline.h"
#include "BSplineKokkos2D.h"
#include "curveReader.h"
#include "splineInterpolation.h"
#include <Kokkos_Core.hpp>
#include <cassert>
#include <fstream>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
// For checking if the content of the splines are correct
using ExecutionSpace = Kokkos::DefaultExecutionSpace;
using MemSpace = ExecutionSpace::memory_space;
int main(int argc, char *argv[]) {
// We check how many arguments are given
int retVal = 0;
if (argc != 3) {
std::cerr << "Input arguments: <input csv file> <expected curve length>"
<< std::endl;
std::cerr << "input csv need these columns: ";
std::cerr
<< "coordinate x, coordinate y, coordinate z,isOnCurve,angle,isMdlVtx"
<< std::endl;
return 1;
}
Kokkos::initialize(argc, argv);
{
const double EPSILON = 1e-12;
std::string inputCSV = argv[1];
int extensionPos = inputCSV.rfind(".");
int slashPos = inputCSV.rfind("/");
std::string fileNameNoExt = inputCSV.substr(slashPos + 1, extensionPos);
double expectedCurveLength = std::stod(argv[2]);
auto curve = CurveReader::readCurveInfo(inputCSV);
// Construct BSpline2d object
SplineInterp::BSpline2d serialBSP;
if (curve.x.size() == 2) {
serialBSP = SplineInterp::attach_piecewise_linear_curve(curve.x, curve.y);
} else {
serialBSP = SplineInterp::fitCubicSplineToPoints(curve.x, curve.y);
}
std::vector<double> ctrlPtsX, ctrlPtsY, knots, weight;
int order;
serialBSP.x.getpara(order, ctrlPtsX, knots, weight);
serialBSP.y.getpara(order, ctrlPtsY, knots, weight);
BSplineKokkos2D<ExecutionSpace> kokkosBSP(order, ctrlPtsX, ctrlPtsY, knots);
auto intView = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(),
kokkosBSP.getOrder());
// Testing the order initialization
double diff = std::fabs(order - intView(0));
if (diff > EPSILON) {
std::cout << "Order difference : " << diff << std::endl;
std::cout << "Serial: " << order << " Kokkos: " << intView(0)
<< std::endl;
retVal = 1;
}
auto double2DView = Kokkos::create_mirror_view_and_copy(
Kokkos::HostSpace(), kokkosBSP.getCtrlPts());
// Testing ctrlPts initialization
double xDiff, yDiff;
for (int i = 0; i < ctrlPtsX.size(); i++) {
xDiff = std::fabs(ctrlPtsX[i] - double2DView(i, 0));
yDiff = std::fabs(ctrlPtsY[i] - double2DView(i, 1));
if (xDiff > EPSILON || yDiff > EPSILON) {
std::cout << "CtrlPts difference: x = " << xDiff << " y = " << yDiff
<< std::endl;
std::cout << "Serial: " << ctrlPtsX[i] << ", " << ctrlPtsY[i]
<< std::endl;
std::cout << "Kokkos: " << double2DView(i, 0) << ", "
<< double2DView(i, 1) << std::endl;
retVal = 1;
}
}
// Test knots initialization
auto doubleView = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(),
kokkosBSP.getKnots());
for (int i = 0; i < knots.size(); i++) {
diff = std::fabs(knots[i] - doubleView(i));
if (diff > EPSILON) {
std::cout << "Knots difference: " << diff << std::endl;
std::cout << "Serial: " << knots[i] << std::endl;
std::cout << "Kokkos: " << doubleView(i) << std::endl;
retVal = 1;
}
}
}
Kokkos::finalize();
return retVal;
}