Skip to content

Commit 01f336b

Browse files
committed
CLN: refactor C++ backend and grid operations
1 parent 65cbd32 commit 01f336b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1686
-942
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build:
1111
name: Python ${{ matrix.python[0] }} on ${{ matrix.os_arch[0] }}-${{ matrix.os_arch[1] }}
1212
runs-on: ${{ matrix.os_arch[0] }}
13-
timeout-minutes: 15
13+
timeout-minutes: 30
1414
strategy:
1515
fail-fast: false
1616
matrix:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
jobs:
1616
test:
1717
runs-on: ${{ matrix.os }}
18-
timeout-minutes: 15
18+
timeout-minutes: 25
1919
strategy:
2020
matrix:
2121
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
cmake_minimum_required(VERSION 3.15.3)
22
project(${SKBUILD_PROJECT_NAME} LANGUAGES C CXX)
33

4+
set(EIGEN_TEST_CXX11
5+
ON
6+
CACHE BOOL "" FORCE)
7+
set(EIGEN_CXX_STANDARD
8+
17
9+
CACHE STRING "C++ standard for Eigen" FORCE)
10+
411
set(CMAKE_C_STANDARD 99)
512
set(CMAKE_CXX_STANDARD 17)
13+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
14+
set(CMAKE_CXX_EXTENSIONS OFF)
615

716
if(NOT SKBUILD)
817
message(

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ test-command = [
116116
convention = "google"
117117
match = '(?!(test_|_)).*\.py'
118118

119+
# reminder if pytest on the command line:
120+
# -o log_cli=true -o log_cli_format="%(levelname)8s (%(relativeCreated)6.0fms) %(filename)44s [%(funcName)40s()] %(lineno)4d >> %(message)s" -o log_cli_level=debug
119121
[tool.pytest.ini_options]
120122
minversion = "6.0"
121123
addopts = "--verbose"

src/lib/CMakeLists.txt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
include_directories(include)
22
set(SRC "${CMAKE_CURRENT_LIST_DIR}/src")
33

4+
# Due to issues with WIN32 and Eigen installation, skip debug on Win32
5+
if(WIN32)
6+
set(Python_FIND_DEBUG FALSE)
7+
set(Python_FIND_RELEASE TRUE)
8+
endif()
9+
410
find_package(
511
Python
612
COMPONENTS Interpreter Development.Module NumPy
@@ -12,9 +18,7 @@ find_package(
1218
include(UseSWIG)
1319
find_package(pybind11 REQUIRED)
1420

15-
if(UNIX AND NOT APPLE)
16-
find_package(OpenMP REQUIRED)
17-
endif()
21+
find_package(OpenMP)
1822

1923
message(STATUS "Python executable : ${Python_EXECUTABLE}")
2024
message(STATUS "Python include dirs : ${Python_INCLUDE_DIRS}")
@@ -25,6 +29,7 @@ message(STATUS "pybind11 include path : ${pybind11_INCLUDE_DIRS}")
2529
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2630

2731
# Use FetchContent for fmt library
32+
2833
include(FetchContent)
2934
FetchContent_Declare(
3035
fmt
@@ -36,6 +41,24 @@ set(FMT_MASTER_PROJECT OFF)
3641
set(BUILD_SHARED_LIBS OFF)
3742
FetchContent_MakeAvailable(fmt)
3843

44+
# Add Eigen using FetchContent
45+
set(EIGEN_BUILD_DOC OFF)
46+
set(BUILD_TESTING OFF)
47+
set(EIGEN_BUILD_PKGCONFIG OFF)
48+
set(EIGEN_BUILD_FORTRAN
49+
OFF
50+
CACHE BOOL "Disable Fortran features in Eigen" FORCE)
51+
set(EIGEN_TEST_FORTRAN
52+
OFF
53+
CACHE BOOL "Disable Fortran tests in Eigen" FORCE)
54+
55+
FetchContent_Declare(
56+
eigen
57+
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
58+
GIT_TAG 3.4.0) # or whatever version you prefer
59+
60+
FetchContent_MakeAvailable(eigen)
61+
3962
# TODO: replace globbing with unique list, as globbing is bad practice
4063
file(GLOB SOURCES ${SRC}/*.c)
4164
add_library(xtgeo STATIC ${SOURCES})
@@ -66,6 +89,7 @@ pybind11_add_module(
6689
"${SRC}/grid3d/cell.cpp"
6790
"${SRC}/grid3d/cell_xyz.cpp"
6891
"${SRC}/grid3d/grid.cpp"
92+
"${SRC}/grid3d/grid_fence_extract.cpp"
6993
"${SRC}/grid3d/grid_xyz_in.cpp"
7094
"${SRC}/grid3d/grid_reorganize.cpp"
7195
"${SRC}/grid3d/grid_surf_oper.cpp"
@@ -76,13 +100,13 @@ pybind11_add_module(
76100
target_include_directories(_internal PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
77101
# Link OpenMP
78102

79-
if(UNIX
80-
AND NOT APPLE
81-
AND OpenMP_CXX_FOUND)
103+
if(OpenMP_CXX_FOUND)
82104
target_link_libraries(_internal PRIVATE OpenMP::OpenMP_CXX)
105+
target_compile_definitions(_internal PRIVATE XTGEO_USE_OPENMP)
83106
endif()
84107

85108
target_link_libraries(_internal PRIVATE fmt::fmt)
109+
target_include_directories(_internal PRIVATE ${eigen_SOURCE_DIR})
86110

87111
message(STATUS "Compiling swig bindings")
88112

src/lib/include/xtgeo/geometry.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ is_point_in_tetrahedron_legacy(const xyz::Point &point,
109109
inline double
110110
triangle_area(const xyz::Point &p1, const xyz::Point &p2, const xyz::Point &p3)
111111
{
112-
return 0.5 *
113-
std::abs(p1.x * (p2.y - p3.y) + p2.x * (p3.y - p1.y) + p3.x * (p1.y - p2.y));
112+
return 0.5 * std::abs(p1.x() * (p2.y() - p3.y()) + p2.x() * (p3.y() - p1.y()) +
113+
p3.x() * (p1.y() - p2.y()));
114114
}
115115

116116
/**
@@ -258,10 +258,10 @@ inline double
258258
hexahedron_dz(const HexahedronCorners &corners)
259259
{
260260
double dzsum = 0.0;
261-
dzsum += std::abs(corners.upper_sw.z - corners.lower_sw.z);
262-
dzsum += std::abs(corners.upper_se.z - corners.lower_se.z);
263-
dzsum += std::abs(corners.upper_nw.z - corners.lower_nw.z);
264-
dzsum += std::abs(corners.upper_ne.z - corners.lower_ne.z);
261+
dzsum += std::abs(corners.upper_sw.z() - corners.lower_sw.z());
262+
dzsum += std::abs(corners.upper_se.z() - corners.lower_se.z());
263+
dzsum += std::abs(corners.upper_nw.z() - corners.lower_nw.z());
264+
dzsum += std::abs(corners.upper_ne.z() - corners.lower_ne.z());
265265
return dzsum / 4.0;
266266
}
267267

0 commit comments

Comments
 (0)