Skip to content

Commit

Permalink
Fix memory leakage for GetGridSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenherje committed Mar 11, 2024
1 parent 491b0c3 commit 639f9d0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
rips_instance = Instance.find()
grid_geometry_extraction_stub = GridGeometryExtractionStub(rips_instance.channel)

grid_file_name = "MOCKED_TEST_GRID"
# grid_file_name = (
# "D:\\Git\\resinsight-tutorials\\model-data\\norne\\NORNE_ATW2013_RFTPLT_V2.EGRID"
# )

ijk_index_filter = GridGeometryExtraction__pb2.IJKIndexFilter(
iMin=0, iMax=1, jMin=1, jMax=3, kMin=3, kMax=3
# grid_file_name = "MOCKED_TEST_GRID"
grid_file_name = (
"D:\\Git\\resinsight-tutorials\\model-data\\norne\\NORNE_ATW2013_RFTPLT_V2.EGRID"
)
# ijk_index_filter = None

# ijk_index_filter = GridGeometryExtraction__pb2.IJKIndexFilter(
# iMin=0, iMax=1, jMin=1, jMax=3, kMin=3, kMax=3
# )
ijk_index_filter = None

get_grid_surface_request = GridGeometryExtraction__pb2.GetGridSurfaceRequest(
gridFilename=grid_file_name,
Expand Down
25 changes: 15 additions & 10 deletions GrpcInterface/RiaGrpcGridGeometryExtractionService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
#include "qfileinfo.h"
#include "qstring.h"

RiaGrpcGridGeometryExtractionService::RiaGrpcGridGeometryExtractionService()
: m_faceVisibilityFilter( nullptr )
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -86,15 +91,15 @@ grpc::Status RiaGrpcGridGeometryExtractionService::GetGridSurface( grpc::ServerC
m_eclipseView->createGridGeometryParts();

// Initialize grid geometry generator
const bool useOpenMP = false;
auto* gridGeometryGenerator = new cvf::StructGridGeometryGenerator( m_eclipseView->mainGrid(), useOpenMP );
status = initializeGridGeometryGeneratorWithEclipseViewCellVisibility( gridGeometryGenerator );
const bool useOpenMP = false;
auto gridGeometryGenerator = cvf::StructGridGeometryGenerator( m_eclipseView->mainGrid(), useOpenMP ); // cvf::ref?
status = initializeGridGeometryGeneratorWithEclipseViewCellVisibility( gridGeometryGenerator );
if ( status.error_code() != grpc::StatusCode::OK )
{
return status;
}

auto* gridSurfaceVertices = gridGeometryGenerator->getOrCreateVertices();
auto* gridSurfaceVertices = gridGeometryGenerator.getOrCreateVertices();
if ( gridSurfaceVertices == nullptr )
{
return grpc::Status( grpc::StatusCode::NOT_FOUND, "No grid vertices found" );
Expand All @@ -121,9 +126,9 @@ grpc::Status RiaGrpcGridGeometryExtractionService::GetGridSurface( grpc::ServerC

// Source cell indices from main grid part manager
std::vector<size_t> sourceCellIndicesArray = std::vector<size_t>();
if ( gridGeometryGenerator->quadToCellFaceMapper() != nullptr )
if ( gridGeometryGenerator.quadToCellFaceMapper() != nullptr )
{
sourceCellIndicesArray = gridGeometryGenerator->quadToCellFaceMapper()->quadToCellIndicesArray();
sourceCellIndicesArray = gridGeometryGenerator.quadToCellFaceMapper()->quadToCellIndicesArray();
}
if ( sourceCellIndicesArray.empty() )
{
Expand Down Expand Up @@ -366,7 +371,7 @@ grpc::Status RiaGrpcGridGeometryExtractionService::applyIJKCellFilterToEclipseCa
///
//--------------------------------------------------------------------------------------------------
grpc::Status RiaGrpcGridGeometryExtractionService::initializeGridGeometryGeneratorWithEclipseViewCellVisibility(
cvf::StructGridGeometryGenerator* generator )
cvf::StructGridGeometryGenerator& generator )
{
if ( m_eclipseView == nullptr )
{
Expand All @@ -385,10 +390,10 @@ grpc::Status RiaGrpcGridGeometryExtractionService::initializeGridGeometryGenerat
m_eclipseView->calculateCurrentTotalCellVisibility( cellVisibilities, firstTimeStep );

// Face visibility filter
auto* faceVisibilityFilter = new RigGridCellFaceVisibilityFilter( mainGrid );
m_faceVisibilityFilter = RigGridCellFaceVisibilityFilter( mainGrid );

generator->setCellVisibility( cellVisibilities );
generator->addFaceVisibilityFilter( faceVisibilityFilter );
generator.setCellVisibility( cellVisibilities ); // Ownership transferred
generator.addFaceVisibilityFilter( &m_faceVisibilityFilter );

return grpc::Status::OK;
}
Expand Down
7 changes: 6 additions & 1 deletion GrpcInterface/RiaGrpcGridGeometryExtractionService.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "GridGeometryExtraction.grpc.pb.h"
#include "RiaApplication.h"
#include "RiaGrpcServiceInterface.h"
#include "RigGridBase.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RivGridPartMgr.h"
Expand Down Expand Up @@ -48,6 +49,8 @@ class RiaGrpcGridGeometryExtractionService final : public rips::GridGeometryExtr
public RiaGrpcServiceInterface
{
public:
RiaGrpcGridGeometryExtractionService();

grpc::Status GetGridSurface( grpc::ServerContext* context,
const rips::GetGridSurfaceRequest* request,
rips::GetGridSurfaceResponse* response ) override;
Expand All @@ -66,9 +69,11 @@ class RiaGrpcGridGeometryExtractionService final : public rips::GridGeometryExtr
grpc::Status applyIJKCellFilterToEclipseCase( const rips::IJKIndexFilter& filter );
grpc::Status initializeApplicationAndEclipseCaseAndEclipseViewFromAbsoluteFilePath( const std::string filePath );

grpc::Status initializeGridGeometryGeneratorWithEclipseViewCellVisibility( cvf::StructGridGeometryGenerator* generator );
grpc::Status initializeGridGeometryGeneratorWithEclipseViewCellVisibility( cvf::StructGridGeometryGenerator& generator );

RiaApplication* m_application = nullptr;
RimEclipseCase* m_eclipseCase = nullptr;
RimEclipseView* m_eclipseView = nullptr;

RigGridCellFaceVisibilityFilter m_faceVisibilityFilter;
};

0 comments on commit 639f9d0

Please sign in to comment.