Skip to content

Commit 64886a6

Browse files
Example : Adds checks to ensure K gaps are only processed when there are enough K layers
1 parent f56dd04 commit 64886a6

1 file changed

Lines changed: 32 additions & 21 deletions

File tree

example/example.cpp

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,19 +3139,21 @@ void deserializeGridHyperslabbingInterfaceSequence(const COMMON_NS::DataObjectRe
31393139

31403140
ijkGrid->loadSplitInformation();
31413141

3142-
if (ijkGrid->getKGapsCount() > 0) {
3142+
const uint64_t kGapsCount = ijkGrid->getKGapsCount();
3143+
const size_t kCellCount = ijkGrid->getKCellCount();
3144+
if (kGapsCount > 0 && kCellCount > 1) {
31433145

31443146
// here, we read a grid interface by interface. Each interface is read
31453147
// in i then j direction
31463148
cout << "INTERFACE BY INTERFACE" << std::endl;
31473149

3148-
std::unique_ptr<bool[]> gapAfterLayer(new bool[ijkGrid->getKCellCount() - 1]);
3150+
std::unique_ptr<bool[]> gapAfterLayer(new bool[kCellCount - 1]);
31493151
ijkGrid->getKGaps(gapAfterLayer.get());
31503152

31513153
unsigned int kLayer = 0;
31523154
unsigned int cornerShift = 0;
31533155

3154-
for (unsigned int kInterface = 0; kInterface < ijkGrid->getKCellCount() + 1 + ijkGrid->getKGapsCount(); kInterface++) {
3156+
for (unsigned int kInterface = 0; kInterface < kCellCount + 1 + kGapsCount; kInterface++) {
31553157
cout << "INTERFACE: " << kInterface << std::endl;
31563158

31573159
std::unique_ptr<double[]> interfaceXyzPoints(new double[ijkGrid->getXyzPointCountOfKInterface() * 3]);
@@ -3191,7 +3193,7 @@ void deserializeGridHyperslabbingInterfaceSequence(const COMMON_NS::DataObjectRe
31913193
}
31923194
}
31933195

3194-
if (cornerShift == 4 || (!gapAfterLayer[kLayer] && kInterface != ijkGrid->getKCellCount() + ijkGrid->getKGapsCount() - 1)) {
3196+
if (cornerShift == 4 || (!gapAfterLayer[kLayer] && kInterface != kCellCount + kGapsCount - 1)) {
31953197
kLayer++;
31963198
cornerShift = 0;
31973199
}
@@ -3207,7 +3209,7 @@ void deserializeGridHyperslabbingInterfaceSequence(const COMMON_NS::DataObjectRe
32073209

32083210
int kInterface = 0;
32093211

3210-
for (unsigned int kLayer = 0; kLayer < ijkGrid->getKCellCount(); kLayer++)
3212+
for (unsigned int kLayer = 0; kLayer < kCellCount; kLayer++)
32113213
{
32123214
cout << "LAYER: " << kLayer << std::endl;
32133215

@@ -3286,12 +3288,15 @@ void deserializeGridHyperslabbingInterfaceSequence(const COMMON_NS::DataObjectRe
32863288
kInterface = gapAfterLayer[kLayer] ? kInterface + 2 : kInterface + 1;
32873289
}
32883290
}
3291+
else if (kGapsCount > 0) {
3292+
std::cout << "Not enough K Layer (" << kCellCount << ") to have K Gaps (" << kGapsCount << ")" << std::endl;
3293+
}
32893294
else { // no K gap
32903295
// here, we read a grid interface by interface. Each interface is read
32913296
// in i then j direction
32923297
cout << "INTERFACE BY INTERFACE" << std::endl;
32933298

3294-
for (unsigned int kInterface = 0; kInterface < ijkGrid->getKCellCount(); kInterface++) {
3299+
for (unsigned int kInterface = 0; kInterface < kCellCount; kInterface++) {
32953300
cout << "INTERFACE: " << kInterface << std::endl;
32963301

32973302
std::unique_ptr<double[]> interfaceXyzPoints(new double[ijkGrid->getXyzPointCountOfKInterface() * 3]);
@@ -3338,44 +3343,44 @@ void deserializeGridHyperslabbingInterfaceSequence(const COMMON_NS::DataObjectRe
33383343
}
33393344

33403345
// last interface differs from the other because of getXyzPointIndexFromCellCorner usage
3341-
cout << "INTERFACE: " << ijkGrid->getKCellCount() << std::endl;
3346+
cout << "INTERFACE: " << kCellCount << std::endl;
33423347

33433348
std::unique_ptr<double[]> interfaceXyzPoints(new double[ijkGrid->getXyzPointCountOfKInterface() * 3]);
3344-
ijkGrid->getXyzPointsOfKInterface(ijkGrid->getKCellCount(), interfaceXyzPoints.get());
3349+
ijkGrid->getXyzPointsOfKInterface(kCellCount, interfaceXyzPoints.get());
33453350

33463351
for (unsigned int i = 0; i < ijkGrid->getICellCount(); i++)
33473352
{
33483353
for (unsigned int j = 0; j < ijkGrid->getJCellCount(); j++)
33493354
{
3350-
cout << "CELL (" << i << ", " << j << ", " << ijkGrid->getKCellCount() - 1 << ")" << std::endl;
3355+
cout << "CELL (" << i << ", " << j << ", " << kCellCount - 1 << ")" << std::endl;
33513356

33523357
uint64_t xyzPointIndex;
33533358
double x, y, z;
3354-
uint64_t indexShift = ijkGrid->getKCellCount() * ijkGrid->getXyzPointCountOfKInterface() * 3;
3359+
uint64_t indexShift = kCellCount * ijkGrid->getXyzPointCountOfKInterface() * 3;
33553360

33563361
// Corner (0, 0, 1)
3357-
xyzPointIndex = ijkGrid->getXyzPointIndexFromCellCorner(i, j, ijkGrid->getKCellCount() - 1, 4) * 3 - indexShift;
3362+
xyzPointIndex = ijkGrid->getXyzPointIndexFromCellCorner(i, j, kCellCount - 1, 4) * 3 - indexShift;
33583363
x = interfaceXyzPoints[xyzPointIndex];
33593364
y = interfaceXyzPoints[xyzPointIndex + 1];
33603365
z = interfaceXyzPoints[xyzPointIndex + 2];
33613366
cout << "CORNER (0, 0, 1): " << x << " " << y << " " << z << std::endl;
33623367

33633368
// Corner (1, 0, 1)
3364-
xyzPointIndex = ijkGrid->getXyzPointIndexFromCellCorner(i, j, ijkGrid->getKCellCount() - 1, 5) * 3 - indexShift;
3369+
xyzPointIndex = ijkGrid->getXyzPointIndexFromCellCorner(i, j, kCellCount - 1, 5) * 3 - indexShift;
33653370
x = interfaceXyzPoints[xyzPointIndex];
33663371
y = interfaceXyzPoints[xyzPointIndex + 1];
33673372
z = interfaceXyzPoints[xyzPointIndex + 2];
33683373
cout << "CORNER (1, 0, 1): " << x << " " << y << " " << z << std::endl;
33693374

33703375
// Corner (1, 1, 1)
3371-
xyzPointIndex = ijkGrid->getXyzPointIndexFromCellCorner(i, j, ijkGrid->getKCellCount() - 1, 6) * 3 - indexShift;
3376+
xyzPointIndex = ijkGrid->getXyzPointIndexFromCellCorner(i, j, kCellCount - 1, 6) * 3 - indexShift;
33723377
x = interfaceXyzPoints[xyzPointIndex];
33733378
y = interfaceXyzPoints[xyzPointIndex + 1];
33743379
z = interfaceXyzPoints[xyzPointIndex + 2];
33753380
cout << "CORNER (1, 1, 1): " << x << " " << y << " " << z << std::endl;
33763381

33773382
// Corner (0, 1, 1)
3378-
xyzPointIndex = ijkGrid->getXyzPointIndexFromCellCorner(i, j, ijkGrid->getKCellCount() - 1, 7) * 3 - indexShift;
3383+
xyzPointIndex = ijkGrid->getXyzPointIndexFromCellCorner(i, j, kCellCount - 1, 7) * 3 - indexShift;
33793384
x = interfaceXyzPoints[xyzPointIndex];
33803385
y = interfaceXyzPoints[xyzPointIndex + 1];
33813386
z = interfaceXyzPoints[xyzPointIndex + 2];
@@ -3388,7 +3393,7 @@ void deserializeGridHyperslabbingInterfaceSequence(const COMMON_NS::DataObjectRe
33883393
cout << "--------------------------------------------------" << std::endl;
33893394
cout << "LAYER BY LAYER" << std::endl;
33903395

3391-
for (unsigned int kInterface = 0; kInterface < ijkGrid->getKCellCount(); kInterface++)
3396+
for (unsigned int kInterface = 0; kInterface < kCellCount; kInterface++)
33923397
{
33933398
cout << "LAYER: " << kInterface << std::endl;
33943399

@@ -4820,13 +4825,19 @@ void deserializeIjkGrid(const COMMON_NS::DataObjectRepository & repo)
48204825
auto kGapCount = ijkGrid->getKGapsCount();
48214826
std::cout << " K Gap Count" << kGapCount << std::endl;
48224827
if (kGapCount > 0) {
4823-
std::unique_ptr<bool[]> kGapAfterLayer(new bool[ijkGrid->getKCellCount() - 1]);
4824-
for (size_t kIndex = 0; kIndex < ijkGrid->getKCellCount() - 1; ++kIndex) {
4825-
std::cout << "There is ";
4826-
if (!kGapAfterLayer[kIndex]) {
4827-
std::cout << "NOT ";
4828+
const size_t kCellCount = ijkGrid->getKCellCount();
4829+
if (kCellCount > 1) {
4830+
std::unique_ptr<bool[]> kGapAfterLayer(new bool[ijkGrid->getKCellCount() - 1]);
4831+
for (size_t kIndex = 0; kIndex < ijkGrid->getKCellCount() - 1; ++kIndex) {
4832+
std::cout << "There is ";
4833+
if (!kGapAfterLayer[kIndex]) {
4834+
std::cout << "NOT ";
4835+
}
4836+
std::cout << "a K gap after K layer " << kIndex << std::endl;
48284837
}
4829-
std::cout << "a K gap after K layer " << kIndex << std::endl;
4838+
}
4839+
else {
4840+
std::cout << "Not enough K Layer (" << kCellCount << ") to have K Gaps" << std::endl;
48304841
}
48314842
}
48324843

0 commit comments

Comments
 (0)