Reorganized data so ijk are the first three indexes in the receiving Octave arrays.

Fixed a typo
p4#: 21708
This commit is contained in:
Magne Sjaastad 2013-05-24 08:48:36 +02:00
parent f556171bec
commit e5b1921bdf
13 changed files with 186 additions and 123 deletions

View File

@ -362,20 +362,44 @@ public:
socketStream << cellCountJ;
socketStream << cellCountK;
quint64 byteCount = cellCount * 3 * sizeof(double);
size_t doubleValueCount = cellCount * 3;
quint64 byteCount = doubleValueCount * sizeof(double);
socketStream << byteCount;
std::vector<double> cellCenterValues(cellCount * 3);
// This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is
// defined by the ordering of the receiving NDArray
//
// See riGetCellCenters
//
// dim_vector dv;
// dv.resize(4);
// dv(0) = cellCountI;
// dv(1) = cellCountJ;
// dv(2) = cellCountK;
// dv(3) = 3;
for (size_t localGridCellIdx = 0; localGridCellIdx < rigGrid->cellCount(); localGridCellIdx++)
std::vector<double> cellCenterValues(doubleValueCount);
cvf::Vec3d cornerVerts[8];
quint64 coordCount = 0;
for (size_t coordIdx = 0; coordIdx < 3; coordIdx++)
{
cvf::Vec3d center = rigGrid->cell(localGridCellIdx).center();
for (size_t k = 0; k < cellCountK; k++)
{
for (size_t j = 0; j < cellCountJ; j++)
{
for (size_t i = 0; i < cellCountI; i++)
{
size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k);
cvf::Vec3d center = rigGrid->cell(localCellIdx).center();
cellCenterValues[localGridCellIdx * 3 + 0] = center.x();
cellCenterValues[localGridCellIdx * 3 + 1] = center.y();
cellCenterValues[localGridCellIdx * 3 + 2] = center.z();
cellCenterValues[coordCount++] = center[coordIdx];
}
}
}
}
CVF_ASSERT(coordCount == doubleValueCount);
server->currentClient()->write((const char *)cellCenterValues.data(), byteCount);
return true;
@ -443,29 +467,51 @@ public:
RigGridBase* rigGrid = rimCase->reservoirData()->grid(argGridIndex);
std::vector<double> cellCenterValues(rigGrid->cellCount() * 3);
size_t cellCenterIndex = 0;
for (size_t localGridCellIdx = 0; localGridCellIdx < rigGrid->cellCount(); localGridCellIdx++)
quint64 cellCountI = (quint64)rigGrid->cellCountI();
quint64 cellCountJ = (quint64)rigGrid->cellCountJ();
quint64 cellCountK = (quint64)rigGrid->cellCountK();
size_t activeCellCount = 0;
actCellInfo->gridActiveCellCounts(argGridIndex, activeCellCount);
size_t doubleValueCount = activeCellCount * 3;
// This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is
// defined by the ordering of the receiving NDArray
//
// See riGetActiveCellCenters
//
// dim_vector dv;
// dv.resize(2);
// dv(0) = coordCount;
// dv(1) = 3;
std::vector<double> cellCenterValues(doubleValueCount);
quint64 coordCount = 0;
for (size_t coordIdx = 0; coordIdx < 3; coordIdx++)
{
size_t globalCellIdx = rigGrid->globalGridCellIndex(localGridCellIdx);
if (!actCellInfo->isActive(globalCellIdx)) continue;
for (size_t k = 0; k < cellCountK; k++)
{
for (size_t j = 0; j < cellCountJ; j++)
{
for (size_t i = 0; i < cellCountI; i++)
{
size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k);
size_t globalCellIdx = rigGrid->globalGridCellIndex(localCellIdx);
RigCell& c = rigGrid->cell(localGridCellIdx);
cvf::Vec3d center = c.center();
if (!actCellInfo->isActive(globalCellIdx)) continue;
cellCenterValues[cellCenterIndex * 3 + 0] = center.x();
cellCenterValues[cellCenterIndex * 3 + 1] = center.y();
cellCenterValues[cellCenterIndex * 3 + 2] = center.z();
cvf::Vec3d center = rigGrid->cell(localCellIdx).center();
cellCenterIndex++;
cellCenterValues[coordCount++] = center[coordIdx];
}
}
}
}
quint64 activeCellCount = cellCenterIndex;
cellCenterValues.resize(cellCenterIndex * 3);
CVF_ASSERT(coordCount == doubleValueCount);
socketStream << activeCellCount;
quint64 byteCount = activeCellCount * 3 * sizeof(double);
socketStream << (quint64)activeCellCount;
quint64 byteCount = doubleValueCount * sizeof(double);
socketStream << byteCount;
server->currentClient()->write((const char *)cellCenterValues.data(), byteCount);
@ -524,21 +570,39 @@ public:
socketStream << cellCountK;
socketStream << byteCount;
// This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is
// defined by the ordering of the receiving NDArray
//
// See riGetCellCorners
//
// dim_vector dv;
// dv.resize(5);
// dv(0) = cellCountI;
// dv(1) = cellCountJ;
// dv(2) = cellCountK;
// dv(3) = 8;
// dv(4) = 3;
std::vector<double> cellCornerValues(doubleValueCount);
cvf::Vec3d cornerVerts[8];
quint64 coordCount = 0;
for (size_t localGridCellIdx = 0; localGridCellIdx < rigGrid->cellCount(); localGridCellIdx++)
for (size_t coordIdx = 0; coordIdx < 3; coordIdx++)
{
rigGrid->cellCornerVertices(localGridCellIdx, cornerVerts);
for (size_t j = 0; j < 8; j++)
for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++)
{
cellCornerValues[coordCount * 3 + 0] = cornerVerts[j].x();
cellCornerValues[coordCount * 3 + 1] = cornerVerts[j].y();
cellCornerValues[coordCount * 3 + 2] = cornerVerts[j].z();
for (size_t k = 0; k < cellCountK; k++)
{
for (size_t j = 0; j < cellCountJ; j++)
{
for (size_t i = 0; i < cellCountI; i++)
{
size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k);
rigGrid->cellCornerVertices(localCellIdx, cornerVerts);
coordCount++;
cellCornerValues[coordCount++] = cornerVerts[cornerIdx][coordIdx];
}
}
}
}
}
@ -606,36 +670,59 @@ public:
}
RigActiveCellInfo* actCellInfo = rimCase->reservoirData()->activeCellInfo(porosityModelEnum);
RigGridBase* rigGrid = rimCase->reservoirData()->grid(argGridIndex);
std::vector<double> cellCornerCoords(rigGrid->cellCount() * 3 * 8);
quint64 cellCountI = (quint64)rigGrid->cellCountI();
quint64 cellCountJ = (quint64)rigGrid->cellCountJ();
quint64 cellCountK = (quint64)rigGrid->cellCountK();
size_t activeCellCount = 0;
actCellInfo->gridActiveCellCounts(argGridIndex, activeCellCount);
size_t doubleValueCount = activeCellCount * 3 * 8;
// This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is
// defined by the ordering of the receiving NDArray
//
// See riGetCellCorners
//
// dim_vector dv;
// dv.resize(3);
// dv(0) = coordCount;
// dv(1) = 8;
// dv(2) = 3;
std::vector<double> cellCornerValues(doubleValueCount);
cvf::Vec3d cornerVerts[8];
quint64 coordCount = 0;
for (size_t localGridCellIdx = 0; localGridCellIdx < rigGrid->cellCount(); localGridCellIdx++)
for (size_t coordIdx = 0; coordIdx < 3; coordIdx++)
{
size_t globalCellIdx = rigGrid->globalGridCellIndex(localGridCellIdx);
if (!actCellInfo->isActive(globalCellIdx)) continue;
rigGrid->cellCornerVertices(localGridCellIdx, cornerVerts);
for (size_t j = 0; j < 8; j++)
for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++)
{
cellCornerCoords[coordCount * 3 + 0] = cornerVerts[j].x();
cellCornerCoords[coordCount * 3 + 1] = cornerVerts[j].y();
cellCornerCoords[coordCount * 3 + 2] = cornerVerts[j].z();
for (size_t k = 0; k < cellCountK; k++)
{
for (size_t j = 0; j < cellCountJ; j++)
{
for (size_t i = 0; i < cellCountI; i++)
{
size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k);
size_t globalCellIdx = rigGrid->globalGridCellIndex(localCellIdx);
coordCount++;
if (!actCellInfo->isActive(globalCellIdx)) continue;
rigGrid->cellCornerVertices(localCellIdx, cornerVerts);
cellCornerValues[coordCount++] = cornerVerts[cornerIdx][coordIdx];
}
}
}
}
}
cellCornerCoords.resize(coordCount * 3);
socketStream << coordCount;
quint64 byteCount = coordCount * 3 * sizeof(double);
socketStream << (quint64)activeCellCount;
quint64 byteCount = doubleValueCount * sizeof(double);
socketStream << byteCount;
server->currentClient()->write((const char *)cellCornerCoords.data(), byteCount);
server->currentClient()->write((const char *)cellCornerValues.data(), byteCount);
return true;
}

View File

@ -37,7 +37,7 @@ void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, qu
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}
@ -50,19 +50,19 @@ void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, qu
socketStream >> activeCellCount;
socketStream >> byteCount;
dim_vector dv (1, 1);
dv(0) = 3;
dv(1) = activeCellCount;
cellCenterValues.resize(dv);
if (!(byteCount && activeCellCount))
{
error ("Could not find the requested data in ResInsight");
return;
}
// Wait for available data for each column, then read data for each column
dim_vector dv;
dv.resize(2);
dv(0) = activeCellCount;
dv(1) = 3;
cellCenterValues.resize(dv);
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(timeout))

View File

@ -37,32 +37,32 @@ void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, qu
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}
// Read timestep count and blocksize
quint64 coordCount;
quint64 activeCellCount;
quint64 byteCount;
socketStream >> coordCount;
socketStream >> activeCellCount;
socketStream >> byteCount;
dim_vector dv (1, 1);
dv(0) = 3;
dv(1) = coordCount;
cellCornerValues.resize(dv);
if (!(byteCount && coordCount))
if (!(byteCount && activeCellCount))
{
error ("Could not find the requested data in ResInsight");
return;
}
// Wait for available data for each column, then read data for each column
dim_vector dv;
dv.resize(3);
dv(0) = activeCellCount;
dv(1) = 8;
dv(2) = 3;
cellCornerValues.resize(dv);
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(timeout))
@ -80,7 +80,7 @@ void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, qu
if (byteCount != bytesRead)
{
error("Could not read binary double data properly from socket");
octave_stdout << "Active cell count: " << coordCount << std::endl;
octave_stdout << "Active cell count: " << activeCellCount << std::endl;
}
return;

View File

@ -37,7 +37,7 @@ void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, qu
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}

View File

@ -42,7 +42,7 @@ void getActiveCellProperty(Matrix& propertyFrames, const QString &serverName, qu
{
if (!socket.waitForReadyRead(Timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}

View File

@ -37,7 +37,7 @@ void getCases(std::vector<qint64>& caseIds, std::vector<QString>& caseNames, std
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}

View File

@ -37,13 +37,11 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}
// Read timestep count and blocksize
quint64 cellCountI;
quint64 cellCountJ;
quint64 cellCountK;
@ -56,25 +54,20 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16
socketStream >> cellCountK;
socketStream >> byteCount;
// Create a 4D matrix, with the a column with the tree double value coords running as fastest index, then I, J, K
// Octave script to access coords
// coords = riGetCellCenters
// coords(:,i, j, k) # Will return the coords for given ijk location
dim_vector dv;
dv.resize(4);
dv(0) = 3;
dv(1) = cellCountI;
dv(2) = cellCountJ;
dv(3) = cellCountK;
cellCenterValues.resize(dv);
if (!(byteCount && cellCount))
{
error ("Could not find the requested data in ResInsight");
return;
}
// Wait for available data for each column, then read data for each column
dim_vector dv;
dv.resize(4);
dv(0) = cellCountI;
dv(1) = cellCountJ;
dv(2) = cellCountK;
dv(3) = 3;
cellCenterValues.resize(dv);
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(timeout))
@ -85,14 +78,13 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16
OCTAVE_QUIT;
}
octave_idx_type valueCount = cellCenterValues.length();
octave_stdout << " riGetCellCenters : I = " << cellCountI <<" J = " << cellCountJ << " K = " << cellCountK << std::endl;
octave_stdout << " riGetCellCenters : numDoubles = " << valueCount << std::endl;
//octave_stdout << " riGetCellCenters : I = " << cellCountI <<" J = " << cellCountJ << " K = " << cellCountK << std::endl;
//octave_stdout << " riGetCellCenters : numDoubles = " << valueCount << std::endl;
double* internalMatrixData = cellCenterValues.fortran_vec();
#if 0
octave_idx_type valueCount = cellCenterValues.length();
double val;
for (octave_idx_type i = 0; i < valueCount; i++)
{

View File

@ -37,13 +37,11 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}
// Read timestep count and blocksize
quint64 cellCountI;
quint64 cellCountJ;
quint64 cellCountK;
@ -56,30 +54,22 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
socketStream >> cellCountK;
socketStream >> byteCount;
// Create a 4D matrix, with the a column with the tree double value coords running as fastest index, then I, J, K
// Octave script to access coords
// coords = riGetCellCenters
// coords(:,i, j, k) # Will return the coords for given ijk location
dim_vector dv;
dv.resize(5);
dv(0) = 3;
dv(1) = 8;
dv(2) = cellCountI;
dv(3) = cellCountJ;
dv(4) = cellCountK;
cellCornerValues.resize(dv);
// octave_stdout << "GetCellCorners - coord count: " << coordCount << ", byteCount: " << byteCount << std::endl;
if (!(byteCount && cellCount))
{
error ("Could not find the requested data in ResInsight");
return;
}
octave_stdout << "GetCellCorners - before wait for data" << std::endl;
dim_vector dv;
dv.resize(5);
dv(0) = cellCountI;
dv(1) = cellCountJ;
dv(2) = cellCountK;
dv(3) = 8;
dv(4) = 3;
cellCornerValues.resize(dv);
// Wait for available data for each column, then read data for each column
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(timeout))
@ -90,14 +80,8 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
OCTAVE_QUIT;
}
octave_idx_type valueCount = cellCornerValues.length();
octave_stdout << "GetCellCorners - after wait for data" << std::endl;
double* internalMatrixData = cellCornerValues.fortran_vec();
#if 0
double val;
for (octave_idx_type i = 0; i < valueCount; i++)

View File

@ -37,7 +37,7 @@ void getCurrentCase(qint64& caseId, QString& caseName, QString& caseType, qint64
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}

View File

@ -36,7 +36,7 @@ void getMainGridDimensions(int32NDArray& gridDimensions, const QString &hostName
{
if (!socket.waitForReadyRead(Timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}

View File

@ -37,7 +37,7 @@ void getSelectedCases(std::vector<qint64>& caseIds, std::vector<QString>& caseNa
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}

View File

@ -45,7 +45,7 @@ void getTimeStepDates( std::vector<qint32>& yearValues,
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}

View File

@ -39,7 +39,7 @@ void getTimeStepDates( std::vector<double>& decimalDays,
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}