Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid geometry extraction for Webviz #11265

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
0967e57
Draft definition of Webviz/RI proto file
sigurdp Feb 13, 2024
242cad4
Update after discussion with MSJ
sigurdp Feb 13, 2024
748ef32
Merge remote-tracking branch 'origin/sigurdp/webviz-grid-protos' into…
magnesj Feb 14, 2024
da01899
Use empty proto file to make baseline compile
magnesj Feb 14, 2024
a8e1c8e
Trigger dummy build
magnesj Feb 14, 2024
9eec4e6
Initial testing of GetGridSurface with mocked data
jorgenherje Feb 19, 2024
9d18605
Python code linting changes detected by black (#11211)
github-actions[bot] Feb 20, 2024
76f2607
Initial GetGridSurface with IJK-filter
jorgenherje Feb 22, 2024
157d64d
Merge remote-tracking branch 'origin/grid-geometry-extraction' into g…
jorgenherje Feb 22, 2024
c966938
Python code linting changes detected by black
jorgenherje Feb 22, 2024
cebc367
Minor adjustments
jorgenherje Feb 22, 2024
bf93623
Merge remote-tracking branch 'origin/grid-geometry-extraction' into g…
jorgenherje Feb 22, 2024
a4323c9
Rename python file
jorgenherje Feb 26, 2024
42a939b
Check for existing ijk-filter before apply
jorgenherje Feb 26, 2024
f9f4bc1
Refactor code
jorgenherje Feb 26, 2024
8d7986b
Adjust python script to add utm coords
jorgenherje Feb 27, 2024
e0118b5
Merge remote-tracking branch 'origin/dev' into grid-geometry-extraction
jorgenherje Feb 27, 2024
b74c0c5
Replace whitespace with "_" for release names
jorgenherje Feb 27, 2024
53af530
Adjust python example
jorgenherje Feb 27, 2024
091bd81
Initial testing of CutAlongPloyline - WIP
jorgenherje Feb 28, 2024
1bdc8e9
BACKUP Testing to create enclosing polygon from triangles per cell - WIP
jorgenherje Mar 5, 2024
de3a00a
Python code linting changes detected by black
jorgenherje Mar 5, 2024
548d747
Adjust according to build warnings/errors
jorgenherje Mar 6, 2024
d300869
Merge remote-tracking branch 'origin/python-black-patches-0vrv2q8' in…
jorgenherje Mar 6, 2024
8f50da0
Backup - WIP
jorgenherje Mar 6, 2024
6a10b6f
Set hard coded string for mock model, and fix Ubuntu build error
jorgenherje Mar 7, 2024
0ed0d81
Minor cleanup - WIP
jorgenherje Mar 8, 2024
491b0c3
Fix typo in proto
jorgenherje Mar 11, 2024
639f9d0
Fix memory leakage for GetGridSurface
jorgenherje Mar 11, 2024
f5dbee7
Fix memory leakage for CutAlongPolyline
jorgenherje Mar 11, 2024
4520fe1
Fix incorrect segment data
jorgenherje Mar 11, 2024
ae6131e
Fix missing fault faces in GetGridSurface() endpoint
jorgenherje Mar 13, 2024
7ca4bd7
Merge remote-tracking branch 'origin/dev' into grid-geometry-extraction
jorgenherje Mar 14, 2024
69c38df
Cache opened grid
jorgenherje Mar 14, 2024
9169ee2
Remove unused code
jorgenherje Mar 14, 2024
2207bf4
Remove logging from `instance.py`
jorgenherje Mar 15, 2024
3156953
Add std::flush to RiaStdOutLogger::writeMessageToLogger
jorgenherje Mar 15, 2024
88ef3a6
Add functionality to disable filter per dimension for IJK-filter
jorgenherje Mar 15, 2024
c2b41c1
Add elapsed time info for responses
jorgenherje Mar 19, 2024
d7c35fb
Remove generate of grid geometry for intersection endpoint
jorgenherje Mar 20, 2024
b9589b3
Have global z in vertexArray for getGridSurface endpoint
jorgenherje Mar 20, 2024
9b119e6
Add read out of OpenMP number of threads
jorgenherje Mar 20, 2024
f498c79
Fix incorrect IJK dimensions in response
jorgenherje Mar 21, 2024
4df9eab
Move get number of threads logic to RiaMain
jorgenherje Mar 21, 2024
985e2e2
Split generation of surface vertices and fault vertices for getGirdSu…
jorgenherje Mar 22, 2024
4d87fc5
Replace thread count in message box with ria logging info
jorgenherje Apr 4, 2024
614a9f1
Prevent duplicated nodes in vertex array of intersection response
jorgenherje Apr 4, 2024
d552c1b
Weld vertices in GetGridSurface endpoint
jorgenherje Apr 4, 2024
7b2a458
Minor adjustment
jorgenherje Apr 4, 2024
ecf9e67
Fix incorrect setting of num buckets
jorgenherje Apr 5, 2024
d4dddb0
Backup
jorgenherje Apr 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ResInsightWithCache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
matrix:
config:
- {
name: "Windows Latest MSVC",
name: "Windows_Latest_MSVC",
os: windows-2022,
cc: "cl",
cxx: "cl",
Expand All @@ -38,7 +38,7 @@ jobs:
publish-to-pypi: false,
}
- {
name: "Ubuntu 20.04 gcc",
name: "Ubuntu_20.04_gcc",
os: ubuntu-20.04,
cc: "gcc",
cxx: "g++",
Expand All @@ -51,7 +51,7 @@ jobs:
publish-to-pypi: true,
}
- {
name: "Ubuntu 22.04 clang-16",
name: "Ubuntu_22.04_clang-16",
os: ubuntu-22.04,
cc: "clang-16",
cxx: "clang++-16",
Expand Down
5 changes: 5 additions & 0 deletions ApplicationExeCode/RiaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
/////////////////////////////////////////////////////////////////////////////////

#include "RiaArgumentParser.h"
#include "RiaLogging.h"
#include "RiaMainTools.h"
#include "RiaOpenMPTools.h"
#include "RiaPreferences.h"

#ifdef ENABLE_GRPC
Expand Down Expand Up @@ -139,6 +141,9 @@ int main( int argc, char* argv[] )

RiaApplication::ApplicationStatus status = app->handleArguments( &progOpt );

int numOmpThreads = RiaOpenMPTools::numberOfThreads();
RiaLogging::info( QString( "OpenMP Num Threads: %1\n" ).arg( numOmpThreads ) );

if ( status == RiaApplication::ApplicationStatus::EXIT_COMPLETED )
{
// Make sure project is closed to avoid assert and crash in destruction of widgets
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/Application/Tools/RiaLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void RiuMessageLoggerBase::writeMessageWithPrefixToLogger( const char* prefix, c
//--------------------------------------------------------------------------------------------------
void RiaStdOutLogger::writeMessageToLogger( const std::string& str )
{
std::cout << str;
std::cout << str << std::flush;
}

//--------------------------------------------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions ApplicationLibCode/Application/Tools/RiaOpenMPTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,22 @@ int RiaOpenMPTools::currentThreadIndex()

return myThread;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaOpenMPTools::numberOfThreads()
{
int numberOfThreads = 1;

#ifdef USE_OPENMP

#pragma omp parallel
{
numberOfThreads = omp_get_num_threads();
}

#endif

return numberOfThreads;
}
1 change: 1 addition & 0 deletions ApplicationLibCode/Application/Tools/RiaOpenMPTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ namespace RiaOpenMPTools
{
int availableThreadCount();
int currentThreadIndex();
int numberOfThreads();
}; // namespace RiaOpenMPTools
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RivEclipseIntersectionGrid.h
${CMAKE_CURRENT_LIST_DIR}/RivFemIntersectionGrid.h
${CMAKE_CURRENT_LIST_DIR}/RivIntersectionGeometryGeneratorInterface.h
${CMAKE_CURRENT_LIST_DIR}/RivPolylineIntersectionGeometryGenerator.h
${CMAKE_CURRENT_LIST_DIR}/RivEnclosingPolygonGenerator.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand All @@ -24,6 +26,8 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RivSectionFlattener.cpp
${CMAKE_CURRENT_LIST_DIR}/RivEclipseIntersectionGrid.cpp
${CMAKE_CURRENT_LIST_DIR}/RivFemIntersectionGrid.cpp
${CMAKE_CURRENT_LIST_DIR}/RivPolylineIntersectionGeometryGenerator.cpp
${CMAKE_CURRENT_LIST_DIR}/RivEnclosingPolygonGenerator.cpp
)

list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ bool RivEclipseIntersectionGrid::useCell( size_t cellIndex ) const
{
const RigCell& cell = m_mainGrid->globalCellArray()[cellIndex];
if ( m_showInactiveCells )
{
return !cell.isInvalid() && ( cell.subGrid() == nullptr );
else
}
if ( m_activeCellInfo.p() != nullptr )
{
return m_activeCellInfo->isActive( cellIndex ) && ( cell.subGrid() == nullptr );
}
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#include "RivEnclosingPolygonGenerator.h"
#include "cvfMath.h"

#include <algorithm>
#include <map>

RivEnclosingPolygonGenerator::RivEnclosingPolygonGenerator()
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivEnclosingPolygonGenerator::constructEnclosingPolygon()
{
// Construct the enclosing polygon from the edges
//
// d ________ c
// | /|
// | / |
// | / |
// | / |
// | / |
// |/_____|
// a b
//
// The line segment ca/ac is the only edge that is not part of the enclosing polygon
// This line segment will occur twice in the list of edges as it is present in both triangles
// (a, b, c) and (a, c, d).
// The line segment ca/ac will be removed from the list of for the enclosing polygon
//
// Enclosing edges are defined as edges only occurring once in the list of edges
//

// Must have at least 3 edges to construct a polygon
CVF_ASSERT( isValidPolygon() );

// Map of edge key and number of occurrences
std::map<cvf::uint64, cvf::uint> edgeKeysAndCount;

// Extract boundary edge keys from all edge keys
for ( const auto& edgeKey : m_allEdgeKeys )
{
// If edge is already in the set, it occurs more than once and is not a boundary edge
// Assuming no degenerate triangles, i.e. triangle with two or more vertices at the same position
if ( edgeKeysAndCount.contains( edgeKey ) )
{
edgeKeysAndCount[edgeKey]++;
}
else
{
edgeKeysAndCount[edgeKey] = 1;
}
}

// At least a triangle is needed to construct a polygon
CVF_ASSERT( edgeKeysAndCount.size() >= 3 );

// Extract boundary edge keys from all edge keys and count
std::set<cvf::EdgeKey> boundaryEdges;
for ( const auto& [key, count] : edgeKeysAndCount )
{
if ( count == 1 )
{
boundaryEdges.insert( cvf::EdgeKey::fromkeyVal( key ) );
}
}

// Lambda function to check if index exists in a vector
auto indexExists = []( const std::vector<cvf::uint>& indices, cvf::uint index ) -> bool
{ return std::find( indices.cbegin(), indices.cend(), index ) != indices.cend(); };

// Construct the enclosing polygon from the boundary edges
cvf::EdgeKey currentEdge = *boundaryEdges.begin();
std::vector<cvf::uint> enclosingPolygonVertexIndices = { currentEdge.index1(), currentEdge.index2() };
cvf::uint nextVertexIndex = currentEdge.index2();
boundaryEdges.erase( currentEdge );
while ( !boundaryEdges.empty() )
{
// Find next edge in the boundary, i.e. edge containing the next vertex index to look for
currentEdge = findNextEdge( nextVertexIndex, boundaryEdges );
boundaryEdges.erase( currentEdge );
const auto start = currentEdge.index1();
const auto end = currentEdge.index2();
if ( start == cvf::UNDEFINED_UINT || end == cvf::UNDEFINED_UINT )
{
// Throw error?
break;
}

// The enclosing polygon is a closed loop, so the start and end vertices are always in the correct order
if ( !indexExists( enclosingPolygonVertexIndices, end ) )
{
nextVertexIndex = end;
enclosingPolygonVertexIndices.push_back( end );
}
else if ( !indexExists( enclosingPolygonVertexIndices, start ) )
{
nextVertexIndex = start;
enclosingPolygonVertexIndices.push_back( start );
}
}

m_polygonVertexIndices = enclosingPolygonVertexIndices;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::EdgeKey RivEnclosingPolygonGenerator::findNextEdge( cvf::uint vertexIndex, const std::set<cvf::EdgeKey>& boundaryEdges )
{
for ( auto& elm : boundaryEdges )
{
if ( elm.index1() == vertexIndex || elm.index2() == vertexIndex )
{
return elm;
}
}

// Return a dummy edge to indicate no next edge found
return cvf::EdgeKey( cvf::UNDEFINED_UINT, cvf::UNDEFINED_UINT );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::uint> RivEnclosingPolygonGenerator::getPolygonVertexIndices() const
{
return m_polygonVertexIndices;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RivEnclosingPolygonGenerator::isValidPolygon() const
{
return m_allEdgeKeys.size() >= size_t( 3 );
}

//--------------------------------------------------------------------------------------------------
/// Add triangle vertices to the polygon. The vertex indices are welded and controlled outside
/// of this class.
///
/// Assumes the vertices are given in counter-clockwise order
//--------------------------------------------------------------------------------------------------
void RivEnclosingPolygonGenerator::addTriangleVertexIndices( cvf::uint idxVx0, cvf::uint idxVx1, cvf::uint idxVx2 )
{
// Verify three unique vertices - i.e. no degenerate triangle
if ( idxVx0 == idxVx1 || idxVx0 == idxVx2 || idxVx1 == idxVx2 )
{
return;
}

// Add edges keys to list of all edges
m_allEdgeKeys.emplace_back( cvf::EdgeKey( idxVx0, idxVx1 ).toKeyVal() );
m_allEdgeKeys.emplace_back( cvf::EdgeKey( idxVx1, idxVx2 ).toKeyVal() );
m_allEdgeKeys.emplace_back( cvf::EdgeKey( idxVx2, idxVx0 ).toKeyVal() );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "cvfBase.h"
#include "cvfEdgeKey.h"

#include <set>
#include <vector>

/*
* Class for generating an enclosing polygon from a set of vertices.
*
* The class add triangle vertex indices and construct constructing the enclosing polygon from the indices.
* The vertices must be provided in counter clock-wise order.
*
* The vertex welding, and mapping of vertex indices to vertex 3D points, must be handled externally.
*/
class RivEnclosingPolygonGenerator
{
public:
RivEnclosingPolygonGenerator();

std::vector<cvf::uint> getPolygonVertexIndices() const;

bool isValidPolygon() const;

void addTriangleVertexIndices( cvf::uint idxVx0, cvf::uint idxVx1, cvf::uint idxVx2 );
void constructEnclosingPolygon();

private:
static cvf::EdgeKey findNextEdge( cvf::uint vertextIndex, const std::set<cvf::EdgeKey>& boundaryEdges );

private:
std::vector<cvf::int64> m_allEdgeKeys; // Create edge defined by vertex indices when adding triangle. Using cvf::EdgeKey::toKeyVal()
std::vector<cvf::uint> m_polygonVertexIndices; // List polygon vertex indices counter clock-wise
};
Loading
Loading