Skip to content

Commit 2414328

Browse files
committed
bug fix in getVectors
1 parent 232e0ea commit 2414328

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

src/mntVectorInterp.cpp

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ int mnt_vectorinterp_new(VectorInterp_t** self) {
1111
(*self)->grid = NULL;
1212
(*self)->locator = NULL;
1313
(*self)->ownsLocator = false;
14+
(*self)->calledFindPoints = false;
1415
return 0;
1516
}
1617

@@ -40,27 +41,38 @@ int mnt_vectorinterp_setLocator(VectorInterp_t** self, vmtCellLocator* locator)
4041

4142
extern "C"
4243
int mnt_vectorinterp_buildLocator(VectorInterp_t** self, int numCellsPerBucket, double periodX) {
44+
45+
if (!(*self)->grid) {
46+
std::cerr << "ERROR: must call setGrid before invoking buildLocator\n";
47+
return -1;
48+
}
49+
4350
(*self)->ownsLocator = true;
4451
(*self)->locator = vmtCellLocator::New();
4552
(*self)->locator->SetDataSet((*self)->grid->grid);
4653
(*self)->locator->SetNumberOfCellsPerBucket(numCellsPerBucket);
4754
(*self)->locator->BuildLocator();
4855
(*self)->locator->setPeriodicityLengthX(periodX);
56+
4957
return 0;
5058
}
5159

5260
extern "C"
5361
int mnt_vectorinterp_findPoints(VectorInterp_t** self, std::size_t numPoints,
5462
const double targetPoints[], double tol2) {
5563

64+
if (!(*self)->locator) {
65+
std::cerr << "ERROR: must call either setLocator or buildLocator before invoking findPoints\n";
66+
return -1;
67+
}
68+
5669
vtkGenericCell *cell = NULL;
5770
double weights[8];
5871
int numFailures = 0;
5972
double pcoords[3];
6073

6174
(*self)->cellIds.resize(numPoints);
62-
(*self)->xsi.resize(numPoints);
63-
(*self)->eta.resize(numPoints);
75+
(*self)->pcoords.resize(numPoints);
6476

6577
for (std::size_t i = 0; i < numPoints; ++i) {
6678

@@ -76,24 +88,44 @@ int mnt_vectorinterp_findPoints(VectorInterp_t** self, std::size_t numPoints,
7688
continue;
7789
}
7890

79-
// store the parametric coordinates of the target point
80-
(*self)->xsi[i] = pcoords[0];
81-
(*self)->eta[i] = pcoords[1];
91+
// store the parametric coordinates of the target point
92+
for (std::size_t j = 0; j < 3; ++j) {
93+
(*self)->pcoords[i][j] = pcoords[j];
94+
}
8295

8396
}
97+
98+
(*self)->calledFindPoints = true;
99+
84100
return numFailures;
85101
}
86102

87103
extern "C"
88104
int mnt_vectorinterp_getVectors(VectorInterp_t** self,
89105
const double data[], double vectors[]) {
90106

107+
if (!(*self)->calledFindPoints) {
108+
std::cerr << "ERROR: must call findPoints before getting the vector\n";
109+
return -1;
110+
}
111+
if (!(*self)->grid) {
112+
std::cerr << "ERROR: must set the grid\n";
113+
return -2;
114+
}
115+
116+
if ((*self)->pcoords.size() == 0) {
117+
std::cerr << "Warning: there is no target point in the domain\n";
118+
return 2;
119+
}
120+
91121
int numFailures = 0;
92122
Vec3 v0, v1, v2, v3, gradXsi, gradEta;
93123

94-
for (std::size_t i = 0; i < (*self)->cellIds.size(); ++i) {
124+
for (std::size_t iTargetId = 0;
125+
iTargetId < (*self)->cellIds.size();
126+
++iTargetId) {
95127

96-
vtkIdType cellId = (*self)->cellIds[i];
128+
vtkIdType cellId = (*self)->cellIds[iTargetId];
97129

98130
if (cellId < 0) {
99131
numFailures++;
@@ -102,8 +134,8 @@ int mnt_vectorinterp_getVectors(VectorInterp_t** self,
102134
}
103135

104136
// parametric coordinates of the target point
105-
double xsi = (*self)->xsi[i];
106-
double eta = (*self)->eta[i];
137+
double xsi = (*self)->pcoords[iTargetId][0];
138+
double eta = (*self)->pcoords[iTargetId][1];
107139
double isx = 1.0 - xsi;
108140
double ate = 1.0 - eta;
109141

@@ -136,14 +168,14 @@ int mnt_vectorinterp_getVectors(VectorInterp_t** self,
136168
gradEta[2] = 0.0;
137169

138170
// interpolate
139-
double data0 = data[cellId + 0];
140-
double data1 = data[cellId + 1];
141-
double data2 = data[cellId + 2];
142-
double data3 = data[cellId + 3];
171+
double data0 = data[cellId*4 + 0];
172+
double data1 = data[cellId*4 + 1];
173+
double data2 = data[cellId*4 + 2];
174+
double data3 = data[cellId*4 + 3];
143175
for (std::size_t j = 0; j < 3; ++j) {
144176
// fill in the vector
145-
vectors[i*3 + j] = (data0*ate + data2*eta)*gradXsi[j] +
146-
(data3*isx + data1*xsi)*gradEta[j];
177+
vectors[iTargetId*3 + j] = (data0*ate + data2*eta)*gradXsi[j] +
178+
(data3*isx + data1*xsi)*gradEta[j];
147179
}
148180

149181
}

src/mntVectorInterp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ struct VectorInterp_t {
1616

1717
// parametric coordinates for the quad, one per
1818
// target point
19-
std::vector<double> xsi;
20-
std::vector<double> eta;
19+
std::vector<Vec3> pcoords;
2120

2221
// cell locator, either a borrowed pointer or
2322
// or owned by the class
2423
vmtCellLocator* locator;
24+
2525
bool ownsLocator;
26+
bool calledFindPoints;
2627
};
2728

2829
/**

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.14.4
1+
1.14.6

0 commit comments

Comments
 (0)