Skip to content

Commit

Permalink
Split generation of surface vertices and fault vertices for getGirdSu…
Browse files Browse the repository at this point in the history
…rface
  • Loading branch information
jorgenherje committed Mar 22, 2024
1 parent 4df9eab commit 985e2e2
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 30 deletions.
2 changes: 1 addition & 1 deletion ApplicationLibCode/ModelVisualization/RivGridPartMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ RivGridPartMgr::RivGridPartMgr( RivCellSetEnum cellSetType, RimEclipseCase* ecli
: m_surfaceGenerator( grid, RiaRegressionTestRunner::instance()->useOpenMPForGeometryCreation() )
, m_gridIdx( gridIdx )
, m_grid( grid )
, m_surfaceFaceFilter( grid, false )
, m_surfaceFaceFilter( grid )
, m_opacityLevel( 1.0f )
, m_defaultColor( cvf::Color3::WHITE )
, m_eclipseCase( eclipseCase )
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ bool RigGridCellFaceVisibilityFilter::isFaceVisible( size_t
const RigFault* fault = m_grid->mainGrid()->findFaultFromCellIndexAndCellFace( nativeResvCellIndex, face );
if ( fault )
{
return m_includeFaultFaces;
return false;
}

// If the neighbour cell is invisible, we need to draw the face
Expand Down
4 changes: 1 addition & 3 deletions ApplicationLibCode/ReservoirDataModel/RigGridBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ class RigGridBase : public cvf::StructGridInterface
class RigGridCellFaceVisibilityFilter : public cvf::CellFaceVisibilityFilter
{
public:
explicit RigGridCellFaceVisibilityFilter( const RigGridBase* const grid, bool includeFaultFaces )
explicit RigGridCellFaceVisibilityFilter( const RigGridBase* const grid )
: m_grid( grid )
, m_includeFaultFaces( includeFaultFaces )
{
}

bool isFaceVisible( size_t i, size_t j, size_t k, cvf::StructGridInterface::FaceType face, const cvf::UByteArray* cellVisibility ) const override;

private:
const RigGridBase* const m_grid;
const bool m_includeFaultFaces;
};
2 changes: 2 additions & 0 deletions GrpcInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set(SOURCE_GROUP_HEADER_FILES
RiaGrpcPdmObjectService.h
RiaGrpcApplicationInterface.h
RiaGrpcGridGeometryExtractionService.h
RiaGrpcGridGeometryExtractionServiceHelper.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand All @@ -67,6 +68,7 @@ set(SOURCE_GROUP_SOURCE_FILES
RiaGrpcPdmObjectService.cpp
RiaGrpcApplicationInterface.cpp
RiaGrpcGridGeometryExtractionService.cpp
RiaGrpcGridGeometryExtractionServiceHelper.cpp
)

# Find Protobuf installation Looks for protobuf-config.cmake file installed by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
norne_case_single_segment_poly_line_gap_utm_xy = [460877, 7.3236e06, 459279, 7.32477e06]


fence_poly_line_utm_xy = norne_case_fence_poly_line_utm_xy
# fence_poly_line_utm_xy = norne_case_fence_poly_line_utm_xy
fence_poly_line_utm_xy = norne_case_single_segment_poly_line_gap_utm_xy

cut_along_polyline_request = GridGeometryExtraction__pb2.CutAlongPolylineRequest(
gridFilename=grid_file_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

fence_poly_line_utm_xy = norne_case_fence_poly_line_utm_xy

num_calls = 20
num_calls = 1000
sleep_time_s = 0.5

for i in range(num_calls):
Expand All @@ -56,6 +56,8 @@
GridGeometryExtraction__pb2.CutAlongPolylineResponse
) = grid_geometry_extraction_stub.CutAlongPolyline(cut_along_polyline_request)

time.sleep(sleep_time_s)
# fence_mesh_sections = cut_along_polyline_response.fenceMeshSections
# print(f"Number of fence mesh sections: {len(fence_mesh_sections)}")
# time.sleep(sleep_time_s)

print("Done!")
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import numpy as np

import plotly.graph_objects as go

from rips.instance import *
from rips.generated.GridGeometryExtraction_pb2_grpc import *
from rips.generated.GridGeometryExtraction_pb2 import *

# from ..instance import *
# from ..generated.GridGeometryExtraction_pb2_grpc import *
# from ..generated.GridGeometryExtraction_pb2 import *

rips_instance = Instance.find()
grid_geometry_extraction_stub = GridGeometryExtractionStub(rips_instance.channel)

grid_file_name = (
"D:/Git/resinsight-tutorials/model-data/norne/NORNE_ATW2013_RFTPLT_V2.EGRID"
)
# grid_file_name = "MOCKED_TEST_GRID"
# grid_file_name = "D:/ResInsight/GRID__SNORRE_BASECASEGRID.roff"

ijk_index_filter = GridGeometryExtraction__pb2.IJKIndexFilter(
iMin=-1, iMax=-1, jMin=-1, jMax=-1, kMin=1, kMax=12
)
ijk_index_filter = None

get_grid_surface_request = GridGeometryExtraction__pb2.GetGridSurfaceRequest(
gridFilename=grid_file_name,
ijkIndexFilter=ijk_index_filter,
cellIndexFilter=None,
propertyFilter=None,
)
get_grid_surface_response: GridGeometryExtraction__pb2.GetGridSurfaceResponse = (
grid_geometry_extraction_stub.GetGridSurface(get_grid_surface_request)
)

total_time_elapsed = get_grid_surface_response.timeElapsedInfo.totalTimeElapsedMs
named_events_and_time_elapsed = (
get_grid_surface_response.timeElapsedInfo.namedEventsAndTimeElapsedMs
)

vertex_array = get_grid_surface_response.vertexArray
quad_indices_array = get_grid_surface_response.quadIndicesArr
origin_utm_xy = get_grid_surface_response.originUtmXy
source_cell_indices_arr = get_grid_surface_response.sourceCellIndicesArr
grid_dimensions = get_grid_surface_response.gridDimensions

num_vertex_coords = 3 # [x, y, z]
num_vertices_per_quad = 4 # [v1, v2, v3, v4]
num_quads = len(vertex_array) / (num_vertex_coords * num_vertices_per_quad)


print(f"Number of quads: {num_quads}")
print(f"Source cell indices array length: {len(source_cell_indices_arr)}")
print(f"Origin UTM coordinates [x, y]: [{origin_utm_xy.x}, {origin_utm_xy.y}]")
print(
f"Grid dimensions [I, J, K]: [{grid_dimensions.i}, {grid_dimensions.j}, {grid_dimensions.k}]"
)
print(f"Total time elapsed: {total_time_elapsed} ms")
# print(f"Time elapsed per event [ms]: {named_events_and_time_elapsed}")
for message, time_elapsed in named_events_and_time_elapsed.items():
print(f"{message}: {time_elapsed}")
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
"D:/Git/resinsight-tutorials/model-data/norne/NORNE_ATW2013_RFTPLT_V2.EGRID"
)
# grid_file_name = "MOCKED_TEST_GRID"
# grid_file_name = "D:/ResInsight/GRID__SNORRE_BASECASEGRID.roff"

ijk_index_filter = GridGeometryExtraction__pb2.IJKIndexFilter(
iMin=-1, iMax=-1, jMin=-1, jMax=-1, kMin=-1, kMax=-1
iMin=15, iMax=30, jMin=30, jMax=90, kMin=1, kMax=12
)
# ijk_index_filter = None
ijk_index_filter = None

get_grid_surface_request = GridGeometryExtraction__pb2.GetGridSurfaceRequest(
gridFilename=grid_file_name,
Expand Down
92 changes: 77 additions & 15 deletions GrpcInterface/RiaGrpcGridGeometryExtractionService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
#include "RigGeoMechCaseData.h"
#include "RigGridBase.h"
#include "RigMainGrid.h"
#include "RigNNCData.h"
#include "RimCase.h"
#include "RimCellFilterCollection.h"
#include "RimCellRangeFilter.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimFaultInViewCollection.h"
#include "RimGeoMechCase.h"
#include "RimGridView.h"
#include "RimProject.h"
Expand Down Expand Up @@ -112,6 +114,7 @@ grpc::Status RiaGrpcGridGeometryExtractionService::GetGridSurface( grpc::ServerC
return grpc::Status( grpc::StatusCode::NOT_FOUND, "No eclipse view found" );
}
eclipseView->setShowInactiveCells( true );
eclipseView->faultCollection()->setActive( false ); // TODO: Check if this is correct??

// Apply ijk-filtering - assuming 0-indexing from gRPC
if ( request->has_ijkindexfilter() )
Expand All @@ -125,30 +128,44 @@ grpc::Status RiaGrpcGridGeometryExtractionService::GetGridSurface( grpc::ServerC

// Configure eclipse view
// - Ensure static geometry parts created for grid part manager in view
// - Initialize grid geometry generator
// - To include inactive cells and activate requested filter for view
auto createGridGeometryPartsTimeCount = ElapsedTimeCount();
eclipseView->createGridGeometryParts();
m_elapsedTimeInfo.elapsedTimePerEventMs["CreateGridGeometryParts"] =
static_cast<std::uint32_t>( createGridGeometryPartsTimeCount.elapsedMsCount() );

const bool useOpenMP = false;
auto gridGeometryGenerator = cvf::StructGridGeometryGenerator( eclipseView->mainGrid(), useOpenMP );
status = initializeGridGeometryGeneratorWithEclipseViewCellVisibility( gridGeometryGenerator, eclipseView );
// Set visibility
const bool useOpenMP = false;
auto surfaceGridGeometryGenerator = cvf::StructGridGeometryGenerator( eclipseView->mainGrid(), useOpenMP );
auto faultGridGeometryGenerator = cvf::StructGridGeometryGenerator( eclipseView->mainGrid(), useOpenMP );
status = initializeGridGeometryGeneratorWithEclipseViewCellVisibility( surfaceGridGeometryGenerator,
faultGridGeometryGenerator,
eclipseView );
if ( status.error_code() != grpc::StatusCode::OK )
{
return status;
}

// Create grid surface vertices
auto createVerticesTimeCount = ElapsedTimeCount();
auto* gridSurfaceVertices = gridGeometryGenerator.getOrCreateVertices();
auto* gridSurfaceVertices = surfaceGridGeometryGenerator.getOrCreateVertices();
if ( gridSurfaceVertices == nullptr )
{
return grpc::Status( grpc::StatusCode::NOT_FOUND, "No grid vertices found" );
return grpc::Status( grpc::StatusCode::NOT_FOUND, "No grid surface vertices found" );
}
m_elapsedTimeInfo.elapsedTimePerEventMs["CreateGridSurfaceVertices"] =
static_cast<std::uint32_t>( createVerticesTimeCount.elapsedMsCount() );

// Create grid fault vertices
auto createFaultVerticesTimeCount = ElapsedTimeCount();
auto* gridFaultVertices = faultGridGeometryGenerator.getOrCreateVertices();
if ( gridFaultVertices == nullptr )
{
return grpc::Status( grpc::StatusCode::NOT_FOUND, "No grid fault vertices found" );
}
m_elapsedTimeInfo.elapsedTimePerEventMs["CreateGridFaultVertices"] =
static_cast<std::uint32_t>( createFaultVerticesTimeCount.elapsedMsCount() );

// Retrieve the UTM offset
const auto mainGridModelOffset = m_eclipseCase->mainGrid()->displayModelOffset();

Expand All @@ -165,6 +182,18 @@ grpc::Status RiaGrpcGridGeometryExtractionService::GetGridSurface( grpc::ServerC
response->add_quadindicesarr( static_cast<google::protobuf::uint32>( i ) );
}

const auto indexOffset = gridSurfaceVertices->size();
for ( size_t i = 0; i < gridFaultVertices->size(); ++i )
{
const auto& vertex = gridFaultVertices->get( i );
response->add_vertexarray( vertex.x() );
response->add_vertexarray( vertex.y() );
response->add_vertexarray( vertex.z() + zAxisOffset );

auto index = indexOffset + i;
response->add_quadindicesarr( static_cast<google::protobuf::uint32>( index ) );
}

// Origin is the UTM offset
rips::Vec2d* originUtmXy = new rips::Vec2d;
originUtmXy->set_x( mainGridModelOffset.x() );
Expand All @@ -173,9 +202,19 @@ 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 ( surfaceGridGeometryGenerator.quadToCellFaceMapper() != nullptr )
{
sourceCellIndicesArray = gridGeometryGenerator.quadToCellFaceMapper()->quadToCellIndicesArray();
for ( const auto& elm : surfaceGridGeometryGenerator.quadToCellFaceMapper()->quadToCellIndicesArray() )
{
sourceCellIndicesArray.push_back( elm );
}
}
if ( faultGridGeometryGenerator.quadToCellFaceMapper() != nullptr )
{
for ( const auto& elm : faultGridGeometryGenerator.quadToCellFaceMapper()->quadToCellIndicesArray() )
{
sourceCellIndicesArray.push_back( elm );
}
}
if ( sourceCellIndicesArray.empty() )
{
Expand Down Expand Up @@ -524,7 +563,8 @@ grpc::Status RiaGrpcGridGeometryExtractionService::applyIJKCellFilterToEclipseVi
///
//--------------------------------------------------------------------------------------------------
grpc::Status RiaGrpcGridGeometryExtractionService::initializeGridGeometryGeneratorWithEclipseViewCellVisibility(
cvf::StructGridGeometryGenerator& generator,
cvf::StructGridGeometryGenerator& surfaceGeometryGenerator,
cvf::StructGridGeometryGenerator& faultGeometryGenerator,
RimEclipseView* view )
{
if ( view == nullptr )
Expand All @@ -541,15 +581,19 @@ grpc::Status RiaGrpcGridGeometryExtractionService::initializeGridGeometryGenerat
// Cell visibilities
const int firstTimeStep = 0;
auto* cellVisibilities = new cvf::UByteArray( mainGrid->cellCount() );
view->calculateCurrentTotalCellVisibility( cellVisibilities, firstTimeStep );
view->calculateCurrentTotalCellVisibility( cellVisibilities, firstTimeStep ); // TODO: Check if this is correct way
// to get cell visibilities

// Face visibility filter
const bool includeFaultFaces = true;
m_faceVisibilityFilter = std::make_unique<RigGridCellFaceVisibilityFilter>(
RigGridCellFaceVisibilityFilter( mainGrid, includeFaultFaces ) );
m_surfaceFaceVisibilityFilter =
std::make_unique<RigGridCellFaceVisibilityFilter>( RigGridCellFaceVisibilityFilter( mainGrid ) );
surfaceGeometryGenerator.setCellVisibility( cellVisibilities ); // Ownership transferred
surfaceGeometryGenerator.addFaceVisibilityFilter( m_surfaceFaceVisibilityFilter.get() );

generator.setCellVisibility( cellVisibilities ); // Ownership transferred
generator.addFaceVisibilityFilter( m_faceVisibilityFilter.get() );
m_faultFaceVisibilityFilter =
std::make_unique<RigGridCellFaultFaceVisibilityFilter>( RigGridCellFaultFaceVisibilityFilter( mainGrid ) );
faultGeometryGenerator.setCellVisibility( cellVisibilities ); // Ownership transferred
faultGeometryGenerator.addFaceVisibilityFilter( m_faultFaceVisibilityFilter.get() );

return grpc::Status::OK;
}
Expand Down Expand Up @@ -637,6 +681,24 @@ grpc::Status
return grpc::Status( grpc::StatusCode::INVALID_ARGUMENT, "More than one grid case found for project" );
}
m_eclipseCase = eclipseCases.front();

// Set nncData for main grid
// TODO: Do not perform if calling intersection endpoint only
if ( m_eclipseCase && m_eclipseCase->eclipseCaseData() && m_eclipseCase->eclipseCaseData()->mainGrid() &&
m_eclipseCase->eclipseCaseData()->mainGrid()->nncData() )
{
auto createNncDataForGrid = ElapsedTimeCount();
const bool includeInactiveCells = true;
m_eclipseCase->eclipseCaseData()
->mainGrid()
->nncData()
->setSourceDataForProcessing( m_eclipseCase->eclipseCaseData()->mainGrid(),
m_eclipseCase->eclipseCaseData()->activeCellInfo(
RiaDefines::PorosityModelType::MATRIX_MODEL ),
includeInactiveCells );
m_elapsedTimeInfo.elapsedTimePerEventMs["CreateNncDataForGrid"] =
static_cast<std::uint32_t>( createNncDataForGrid.elapsedMsCount() );
}
}

if ( m_eclipseCase == nullptr )
Expand Down
14 changes: 9 additions & 5 deletions GrpcInterface/RiaGrpcGridGeometryExtractionService.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "GridGeometryExtraction.grpc.pb.h"
#include "RiaApplication.h"
#include "RiaGrpcGridGeometryExtractionServiceHelper.h"
#include "RiaGrpcServiceInterface.h"
#include "RigGridBase.h"
#include "RimEclipseCase.h"
Expand Down Expand Up @@ -71,12 +72,15 @@ class RiaGrpcGridGeometryExtractionService final : public rips::GridGeometryExtr
grpc::Status applyIJKCellFilterToEclipseView( const rips::IJKIndexFilter& filter, RimEclipseView* view );
grpc::Status initializeApplicationAndEclipseCaseFromAbsoluteFilePath( const std::string filePath );

grpc::Status initializeGridGeometryGeneratorWithEclipseViewCellVisibility( cvf::StructGridGeometryGenerator& generator,
RimEclipseView* view );
grpc::Status initializeGridGeometryGeneratorWithEclipseViewCellVisibility(
cvf::StructGridGeometryGenerator& surfaceGeometryGenerator,
cvf::StructGridGeometryGenerator& faultGeometryGenerator,
RimEclipseView* view );

RiaApplication* m_application = nullptr;
RimEclipseCase* m_eclipseCase = nullptr;
std::unique_ptr<RigGridCellFaceVisibilityFilter> m_faceVisibilityFilter = nullptr;
RiaApplication* m_application = nullptr;
RimEclipseCase* m_eclipseCase = nullptr;
std::unique_ptr<RigGridCellFaceVisibilityFilter> m_surfaceFaceVisibilityFilter = nullptr;
std::unique_ptr<RigGridCellFaultFaceVisibilityFilter> m_faultFaceVisibilityFilter = nullptr;

struct ElapsedTimeInfo
{
Expand Down
Loading

0 comments on commit 985e2e2

Please sign in to comment.