Skip to content

Commit 272bcbb

Browse files
committed
ENH: add method get_property_between_surfaces() for Grid class
1 parent e450ea7 commit 272bcbb

File tree

14 files changed

+589
-178
lines changed

14 files changed

+589
-178
lines changed

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ignore_missing_imports = True
55
strict_equality = True
66
warn_redundant_casts = True
77
warn_unused_configs = True
8-
warn_unused_ignores = True
8+
warn_unused_ignores = False
99

1010
exclude = tests|docs|examples|bin
1111

src/lib/include/xtgeo/grid3d.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <pybind11/pybind11.h> // should be included first according to pybind11 docs
44
#include <pybind11/numpy.h>
55
#include <cstddef>
6+
#include <cstdint>
67
#include <optional>
78
#include <tuple>
89

@@ -63,6 +64,30 @@ get_depth_in_cell(const double x,
6364
const std::array<double, 24> &corners,
6465
int option);
6566

67+
py::array_t<int8_t>
68+
grid_assign_value_between_surfaces(const size_t ncol,
69+
const size_t nrow,
70+
const size_t nlay,
71+
const py::array_t<double> &xmid,
72+
const py::array_t<double> &ymid,
73+
const py::array_t<double> &zmid,
74+
const size_t top_ncol,
75+
const size_t top_nrow,
76+
const double top_xori,
77+
const double top_yori,
78+
const double top_xinc,
79+
const double top_yinc,
80+
const double top_rotation,
81+
const py::array_t<double> &top_values,
82+
const size_t bot_ncol,
83+
const size_t bot_nrow,
84+
const double bot_xori,
85+
const double bot_yori,
86+
const double bot_xinc,
87+
const double bot_yinc,
88+
const double bot_rotation,
89+
const py::array_t<double> &bot_values);
90+
6691
inline void
6792
init(py::module &m)
6893
{
@@ -83,6 +108,9 @@ init(py::module &m)
83108
"Determine if a XY point is inside a cell, top or base.");
84109
m_grid3d.def("get_depth_in_cell", &get_depth_in_cell,
85110
"Determine the interpolated cell face Z from XY, top or base.");
111+
m_grid3d.def("grid_assign_value_between_surfaces",
112+
&grid_assign_value_between_surfaces,
113+
"Make a property that is one if cell center is between two surfaces.");
86114
}
87115

88116
} // namespace xtgeo::grid3d

src/lib/include/xtgeo/regsurf.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ get_xy_from_ij(const size_t i,
3030
const size_t nrow,
3131
const double angle_deg);
3232

33+
double
34+
get_z_from_xy(const double x,
35+
const double y,
36+
const double xori,
37+
const double yori,
38+
const double xinc,
39+
const double yinc,
40+
const size_t ncol,
41+
const size_t nrow,
42+
const double angle_deg,
43+
const py::array_t<double> &values);
44+
3345
std::tuple<int, int, int, int>
3446
find_cell_range(const double xmin,
3547
const double xmax,
@@ -80,6 +92,8 @@ init(py::module &m)
8092
"Get the outer corners of a regular surface.");
8193
m_regsurf.def("get_xy_from_ij", &get_xy_from_ij,
8294
"Get the XY coordinates from the grid indices.");
95+
m_regsurf.def("get_z_from_xy", &get_z_from_xy,
96+
"Get the Z value in a regsurf from a x y point.");
8397
m_regsurf.def("find_cell_range", &find_cell_range,
8498
"Find the range of regular surface 2D nodes within a box.");
8599
m_regsurf.def("sample_grid3d_layer", &sample_grid3d_layer,

src/lib/include/xtgeo/xtgeo.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,26 +1059,6 @@ extern "C"
10591059
long n_swig_np_dbl_inplace_v1, // ntot,
10601060
metric m);
10611061

1062-
void grdcp3d_calc_xyz(long ncol,
1063-
long nrow,
1064-
long nlay,
1065-
1066-
double *swig_np_dbl_in_v1, // *coordsv,
1067-
long n_swig_np_dbl_in_v1, // ncoord,
1068-
float *swig_np_flt_in_v1, // *zcornsv,
1069-
long n_swig_np_flt_in_v1, // nzcorn,
1070-
int *swig_np_int_in_v1, // *actnumsv,
1071-
long n_swig_np_int_in_v1, // nactnum,
1072-
1073-
int option,
1074-
1075-
double *swig_np_dbl_aout_v1, // xarr
1076-
long n_swig_np_dbl_aout_v1,
1077-
double *swig_np_dbl_aout_v2, // yarr
1078-
long n_swig_np_dbl_aout_v2,
1079-
double *swig_np_dbl_aout_v3, // zarr
1080-
long n_swig_np_dbl_aout_v3);
1081-
10821062
void grd3d_conv_roxapi_grid(int nx,
10831063
int ny,
10841064
int nz,
@@ -1394,20 +1374,6 @@ extern "C"
13941374
long n_swig_np_int_inplace_v1 // nactnum
13951375
);
13961376

1397-
void grdcp3d_midpoint(long i,
1398-
long j,
1399-
long k,
1400-
long ncol,
1401-
long nrow,
1402-
long nlay,
1403-
double *coordsv,
1404-
long ncoord,
1405-
float *zcornsv,
1406-
long nzcorn,
1407-
double *x,
1408-
double *y,
1409-
double *z);
1410-
14111377
void grd3d_midpoint(int i,
14121378
int j,
14131379
int k,

src/lib/src/grdcp3d_calc_xyz.c

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/lib/src/grdcp3d_midpoint.c

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/lib/src/grid3d/grid.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,60 @@ grid_cell_volumes(const size_t ncol,
5555
return cellvols;
5656
}
5757

58+
/*
59+
* Get cell centers for a grid.
60+
*
61+
* @param ncol Grid dimensions ncol/nx
62+
* @param nrow Grid dimensions nrow/ny
63+
* @param nlay Grid dimensions nlay/nz
64+
* @param coordsv Grid Z coordinates vector
65+
* @param zcornsv Grid Z corners vector
66+
* @param actumsv Active cells vector
67+
* @param asmasked Process grid cells as masked (return NaN for inactive cells)
68+
* @return Arrays with the X, Y, Z coordinates of the cell centers
69+
*/
70+
std::tuple<py::array_t<double>, py::array_t<double>, py::array_t<double>>
71+
grid_cell_centers(const size_t ncol,
72+
const size_t nrow,
73+
const size_t nlay,
74+
const py::array_t<double> &coordsv,
75+
const py::array_t<float> &zcornsv,
76+
const py::array_t<int> &actnumsv,
77+
const bool asmasked = false)
78+
{
79+
pybind11::array_t<double> xmid({ ncol, nrow, nlay });
80+
pybind11::array_t<double> ymid({ ncol, nrow, nlay });
81+
pybind11::array_t<double> zmid({ ncol, nrow, nlay });
82+
auto xmid_ = xmid.mutable_unchecked<3>();
83+
auto ymid_ = ymid.mutable_unchecked<3>();
84+
auto zmid_ = zmid.mutable_unchecked<3>();
85+
auto actnumsv_ = actnumsv.unchecked<3>();
86+
87+
for (size_t i = 0; i < ncol; i++) {
88+
for (size_t j = 0; j < nrow; j++) {
89+
for (size_t k = 0; k < nlay; k++) {
90+
size_t idx = i * nrow * nlay + j * nlay + k;
91+
if (asmasked && actnumsv_(i, j, k) == 0) {
92+
xmid_(i, j, k) = std::numeric_limits<double>::quiet_NaN();
93+
ymid_(i, j, k) = std::numeric_limits<double>::quiet_NaN();
94+
zmid_(i, j, k) = std::numeric_limits<double>::quiet_NaN();
95+
continue;
96+
}
97+
auto cr =
98+
grid3d::cell_corners(i, j, k, ncol, nrow, nlay, coordsv, zcornsv);
99+
100+
xmid_(i, j, k) = 0.125 * (cr[0] + cr[3] + cr[6] + cr[9] + cr[12] +
101+
cr[15] + cr[18] + cr[21]);
102+
ymid_(i, j, k) = 0.125 * (cr[1] + cr[4] + cr[7] + cr[10] + cr[13] +
103+
cr[16] + cr[19] + cr[22]);
104+
zmid_(i, j, k) = 0.125 * (cr[2] + cr[5] + cr[8] + cr[11] + cr[14] +
105+
cr[17] + cr[20] + cr[23]);
106+
}
107+
}
108+
}
109+
return std::make_tuple(xmid, ymid, zmid);
110+
}
111+
58112
/*
59113
* Compute cell height above ffl (free fluid level), as input to water saturation. Will
60114
* return hbot, htop, hmid (bottom of cell, top of cell, midpoint), but compute method

0 commit comments

Comments
 (0)