#3531 RigMainGrid : Several refactoring operations

Move impl to cpp
Remove obsolete includes
Whitespace fix
This commit is contained in:
Magne Sjaastad 2018-10-23 15:12:46 +02:00
parent 158222217a
commit d2972d144a
2 changed files with 161 additions and 106 deletions

View File

@ -23,14 +23,12 @@
#include "RiaDefines.h"
#include "RiaLogging.h"
#include "RigActiveCellInfo.h"
#include "RigFault.h"
#include "RigHexIntersectionTools.h"
#include "cvfBoundingBoxTree.h"
#include "cvfAssert.h"
#include "cvfBoundingBoxTree.h"
RigMainGrid::RigMainGrid(void)
RigMainGrid::RigMainGrid()
: RigGridBase(this)
{
m_displayModelOffset = cvf::Vec3d::ZERO;
@ -43,9 +41,38 @@ RigMainGrid::RigMainGrid(void)
m_flipYAxis = false;
}
RigMainGrid::~RigMainGrid() {}
RigMainGrid::~RigMainGrid(void)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d>& RigMainGrid::nodes()
{
return m_nodes;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<cvf::Vec3d>& RigMainGrid::nodes() const
{
return m_nodes;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RigCell>& RigMainGrid::globalCellArray()
{
return m_cells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<RigCell>& RigMainGrid::globalCellArray() const
{
return m_cells;
}
//--------------------------------------------------------------------------------------------------
@ -54,9 +81,11 @@ RigMainGrid::~RigMainGrid(void)
RigGridBase* RigMainGrid::gridAndGridLocalIdxFromGlobalCellIdx(size_t globalCellIdx, size_t* gridLocalCellIdx)
{
CVF_ASSERT(globalCellIdx < m_cells.size());
RigCell& cell = m_cells[globalCellIdx];
RigGridBase* hostGrid = cell.hostGrid();
CVF_ASSERT(hostGrid);
*gridLocalCellIdx = cell.gridLocalCellIndex();
return hostGrid;
}
@ -67,14 +96,15 @@ RigGridBase* RigMainGrid::gridAndGridLocalIdxFromGlobalCellIdx(size_t globalCell
const RigGridBase* RigMainGrid::gridAndGridLocalIdxFromGlobalCellIdx(size_t globalCellIdx, size_t* gridLocalCellIdx) const
{
CVF_ASSERT(globalCellIdx < m_cells.size());
const RigCell& cell = m_cells[globalCellIdx];
const RigGridBase* hostGrid = cell.hostGrid();
CVF_ASSERT(hostGrid);
*gridLocalCellIdx = cell.gridLocalCellIndex();
return hostGrid;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -160,7 +190,6 @@ void RigMainGrid::addLocalGrid(RigLocalGrid* localGrid)
m_localGrids.push_back(localGrid);
localGrid->setGridIndex(m_localGrids.size()); // Maingrid itself has grid index 0
if (m_gridIdToIndexMapping.size() <= static_cast<size_t>(localGrid->gridId()))
{
m_gridIdToIndexMapping.resize(localGrid->gridId() + 1, cvf::UNDEFINED_SIZE_T);
@ -169,6 +198,14 @@ void RigMainGrid::addLocalGrid(RigLocalGrid* localGrid)
m_gridIdToIndexMapping[localGrid->gridId()] = localGrid->gridIndex();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigMainGrid::gridCount() const
{
return m_localGrids.size() + 1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -185,7 +222,6 @@ void RigMainGrid::initAllSubGridsParentGridPointer()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -322,6 +358,14 @@ void RigMainGrid::setFaults(const cvf::Collection<RigFault>& faults)
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const cvf::Collection<RigFault>& RigMainGrid::faults()
{
return m_faults;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -342,9 +386,8 @@ bool RigMainGrid::hasFaultWithName(const QString& name) const
//--------------------------------------------------------------------------------------------------
void RigMainGrid::calculateFaults(const RigActiveCellInfo* activeCellInfo, bool forceCalculation)
{
if (!forceCalculation &&
hasFaultWithName(RiaDefines::undefinedGridFaultName())
&& hasFaultWithName(RiaDefines::undefinedGridFaultWithInactiveName()))
if (!forceCalculation && hasFaultWithName(RiaDefines::undefinedGridFaultName()) &&
hasFaultWithName(RiaDefines::undefinedGridFaultWithInactiveName()))
{
// RiaLogging::debug(QString("Calculate faults already run for grid."));
@ -385,7 +428,10 @@ void RigMainGrid::calculateFaults(const RigActiveCellInfo* activeCellInfo, bool
size_t neighborReservoirCellIdx;
size_t neighborGridCellIdx;
size_t i = 0, j = 0, k = 0;
size_t i = 0;
size_t j = 0;
size_t k = 0;
RigGridBase* hostGrid = nullptr;
bool firstNO_FAULTFaceForCell = true;
bool isCellActive = true;
@ -433,12 +479,15 @@ void RigMainGrid::calculateFaults(const RigActiveCellInfo* activeCellInfo, bool
std::array<size_t, 4> nbFaceIdxs;
m_cells[neighborReservoirCellIdx].faceIndices(StructGridInterface::oppositeFace(face), &nbFaceIdxs);
bool sharedFaceVertices = true;
if (sharedFaceVertices && vxs[faceIdxs[0]].pointDistance(vxs[nbFaceIdxs[0]]) > tolerance ) sharedFaceVertices = false;
if (sharedFaceVertices && vxs[faceIdxs[1]].pointDistance(vxs[nbFaceIdxs[3]]) > tolerance ) sharedFaceVertices = false;
if (sharedFaceVertices && vxs[faceIdxs[2]].pointDistance(vxs[nbFaceIdxs[2]]) > tolerance ) sharedFaceVertices = false;
if (sharedFaceVertices && vxs[faceIdxs[3]].pointDistance(vxs[nbFaceIdxs[1]]) > tolerance ) sharedFaceVertices = false;
if (sharedFaceVertices && vxs[faceIdxs[0]].pointDistance(vxs[nbFaceIdxs[0]]) > tolerance)
sharedFaceVertices = false;
if (sharedFaceVertices && vxs[faceIdxs[1]].pointDistance(vxs[nbFaceIdxs[3]]) > tolerance)
sharedFaceVertices = false;
if (sharedFaceVertices && vxs[faceIdxs[2]].pointDistance(vxs[nbFaceIdxs[2]]) > tolerance)
sharedFaceVertices = false;
if (sharedFaceVertices && vxs[faceIdxs[3]].pointDistance(vxs[nbFaceIdxs[1]]) > tolerance)
sharedFaceVertices = false;
if (sharedFaceVertices)
{
@ -468,7 +517,10 @@ void RigMainGrid::calculateFaults(const RigActiveCellInfo* activeCellInfo, bool
}
else
{
CVF_FAIL_MSG("Found fault with global neighbor index less than the native index. "); // Should never occur. because we flag the opposite face in the faultsPrCellAcc
CVF_FAIL_MSG(
"Found fault with global neighbor index less than the native index. "); // Should never occur. because we
// flag the opposite face in the
// faultsPrCellAcc
}
}
}
@ -504,7 +556,8 @@ void RigMainGrid::distributeNNCsToFaults()
lgrString = "Different Grid";
}
//cvf::Trace::show("NNC: No Fault for NNC C1: " + cvf::String((int)conn.m_c1GlobIdx) + " C2: " + cvf::String((int)conn.m_c2GlobIdx) + " Grid: " + lgrString);
// cvf::Trace::show("NNC: No Fault for NNC C1: " + cvf::String((int)conn.m_c1GlobIdx) + " C2: " +
// cvf::String((int)conn.m_c2GlobIdx) + " Grid: " + lgrString);
}
if (fIdx1 >= 0)
@ -529,7 +582,6 @@ void RigMainGrid::distributeNNCsToFaults()
//--------------------------------------------------------------------------------------------------
bool RigMainGrid::isFaceNormalsOutwards() const
{
for (int gcIdx = 0; gcIdx < static_cast<int>(m_cells.size()); ++gcIdx)
{
if (!m_cells[gcIdx].isInvalid())
@ -542,8 +594,8 @@ bool RigMainGrid::isFaceNormalsOutwards() const
double dummy, dummy2, typicalKSize;
characteristicCellSizes(&dummy, &dummy2, &typicalKSize);
if ( (faceCenter - cellCenter).length() > 0.2 * typicalIJCellSize
&& (faceNormal.length() > (0.2 * typicalIJCellSize * 0.2* typicalKSize)))
if ((faceCenter - cellCenter).length() > 0.2 * typicalIJCellSize &&
(faceNormal.length() > (0.2 * typicalIJCellSize * 0.2 * typicalKSize)))
{
// Cell is assumed ok to use, so calculate whether the normals are outwards or inwards
@ -565,7 +617,8 @@ bool RigMainGrid::isFaceNormalsOutwards() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RigFault* RigMainGrid::findFaultFromCellIndexAndCellFace(size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face) const
const RigFault* RigMainGrid::findFaultFromCellIndexAndCellFace(size_t reservoirCellIndex,
cvf::StructGridInterface::FaceType face) const
{
CVF_TIGHT_ASSERT(m_faultsPrCellAcc.notNull());
@ -659,9 +712,10 @@ cvf::BoundingBox RigMainGrid::boundingBox() const
{
if (m_boundingBox.isValid()) return m_boundingBox;
for (size_t i = 0; i < m_nodes.size(); ++i)
for (const auto& node : m_nodes)
{
m_boundingBox.add(m_nodes[i]);
m_boundingBox.add(node);
}
return m_boundingBox;
}

View File

@ -19,17 +19,18 @@
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RigGridBase.h"
#include <vector>
#include "RigCell.h"
#include "RigLocalGrid.h"
#include "cvfCollection.h"
#include "cvfBoundingBox.h"
#include "RifReaderInterface.h"
#include <QtGlobal>
#include "RigCell.h"
#include "RigGridBase.h"
#include "RigLocalGrid.h"
#include "RigNNCData.h"
#include "cvfBoundingBox.h"
#include "cvfCollection.h"
#include <vector>
class RigActiveCellInfo;
namespace cvf
@ -45,11 +46,11 @@ public:
~RigMainGrid() override;
public:
std::vector<cvf::Vec3d>& nodes() {return m_nodes;}
const std::vector<cvf::Vec3d>& nodes() const {return m_nodes;}
std::vector<cvf::Vec3d>& nodes();
const std::vector<cvf::Vec3d>& nodes() const;
std::vector<RigCell>& globalCellArray() {return m_cells;}
const std::vector<RigCell>& globalCellArray() const {return m_cells;}
std::vector<RigCell>& globalCellArray();
const std::vector<RigCell>& globalCellArray() const;
RigGridBase* gridAndGridLocalIdxFromGlobalCellIdx(size_t globalCellIdx, size_t* gridLocalCellIdx);
const RigGridBase* gridAndGridLocalIdxFromGlobalCellIdx(size_t globalCellIdx, size_t* gridLocalCellIdx) const;
@ -59,14 +60,14 @@ public:
size_t findReservoirCellIndexFromPoint(const cvf::Vec3d& point) const;
std::vector<size_t> findAllReservoirCellIndicesMatching2dPoint(const cvf::Vec2d& point2d) const;
void addLocalGrid(RigLocalGrid* localGrid);
size_t gridCount() const { return m_localGrids.size() + 1; }
size_t gridCount() const;
RigGridBase* gridByIndex(size_t localGridIndex);
const RigGridBase* gridByIndex(size_t localGridIndex) const;
RigGridBase* gridById(int localGridId);
RigNNCData* nncData();
void setFaults(const cvf::Collection<RigFault>& faults);
const cvf::Collection<RigFault>& faults() { return m_faults; }
const cvf::Collection<RigFault>& faults();
void calculateFaults(const RigActiveCellInfo* activeCellInfo, bool forceCalculation = false);
void distributeNNCsToFaults();
@ -77,7 +78,6 @@ public:
void computeCachedData();
void initAllSubGridsParentGridPointer();
// Overrides
cvf::Vec3d displayModelOffset() const override;
void setDisplayModelOffset(cvf::Vec3d offset);
@ -85,6 +85,7 @@ public:
void findIntersectingCells(const cvf::BoundingBox& inputBB, std::vector<size_t>* cellIndices) const;
cvf::BoundingBox boundingBox() const;
private:
void initAllSubCellsMainGridCellIndex();
void buildCellSearchTree();