resfo-utilities 0.0.2__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of resfo-utilities might be problematic. Click here for more details.

Files changed (40) hide show
  1. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.github/workflows/testing.yml +2 -2
  2. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.github/workflows/typing.yml +1 -1
  3. resfo_utilities-0.0.3/LICENSE.md +166 -0
  4. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/PKG-INFO +7 -6
  5. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/README.md +2 -2
  6. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/docs/source/glossary.rst +3 -3
  7. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/pyproject.toml +2 -2
  8. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/src/resfo_utilities/_cornerpoint_grid.py +110 -53
  9. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/src/resfo_utilities.egg-info/PKG-INFO +7 -6
  10. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/src/resfo_utilities.egg-info/SOURCES.txt +1 -0
  11. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/src/resfo_utilities.egg-info/requires.txt +2 -3
  12. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/performance/test_find_cell_performance.py +4 -4
  13. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/unit/test_cornerpoint_grid.py +95 -4
  14. resfo_utilities-0.0.3/uv.lock +1139 -0
  15. resfo_utilities-0.0.2/uv.lock +0 -1674
  16. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  17. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.github/dependabot.yml +0 -0
  18. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.github/mypy-matcher.json +0 -0
  19. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.github/workflows/publish_to_pypi.yml +0 -0
  20. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.gitignore +0 -0
  21. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.mypy.ini +0 -0
  22. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.pre-commit-config.yaml +0 -0
  23. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/.readthedocs.yaml +0 -0
  24. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/CONTRIBUTING.md +0 -0
  25. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/SECURITY.md +0 -0
  26. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/docs/requirements.txt +0 -0
  27. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/docs/source/api_reference.rst +0 -0
  28. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/docs/source/conf.py +0 -0
  29. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/docs/source/index.rst +0 -0
  30. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/setup.cfg +0 -0
  31. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/src/resfo_utilities/__init__.py +0 -0
  32. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/src/resfo_utilities.egg-info/dependency_links.txt +0 -0
  33. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/src/resfo_utilities.egg-info/top_level.txt +0 -0
  34. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/__init__.py +0 -0
  35. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/conftest.py +0 -0
  36. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/integration/__init__.py +0 -0
  37. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/integration/conftest.py +0 -0
  38. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/integration/test_grid.py +0 -0
  39. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/performance/__init__.py +0 -0
  40. {resfo_utilities-0.0.2 → resfo_utilities-0.0.3}/tests/unit/__init__.py +0 -0
@@ -22,11 +22,11 @@ jobs:
22
22
  python-version: ["3.11", "3.12", "3.13"]
23
23
 
24
24
  steps:
25
- - uses: actions/checkout@v4
25
+ - uses: actions/checkout@v5
26
26
  - uses: actions/setup-python@v6
27
27
  with:
28
28
  python-version: ${{ matrix.python-version }}
29
- - uses: astral-sh/setup-uv@v6
29
+ - uses: astral-sh/setup-uv@v7
30
30
  with:
31
31
  enable-cache: true
32
32
  python-version: ${{ matrix.python-version }}
@@ -29,7 +29,7 @@ jobs:
29
29
  python-version: "3.13"
30
30
 
31
31
  - name: Install uv
32
- uses: astral-sh/setup-uv@v6
32
+ uses: astral-sh/setup-uv@v7
33
33
  with:
34
34
  enable-cache: true
35
35
  python-version: "3.13"
@@ -0,0 +1,166 @@
1
+
2
+ GNU LESSER GENERAL PUBLIC LICENSE
3
+ Version 3, 29 June 2007
4
+
5
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+
10
+ This version of the GNU Lesser General Public License incorporates
11
+ the terms and conditions of version 3 of the GNU General Public
12
+ License, supplemented by the additional permissions listed below.
13
+
14
+ 0. Additional Definitions.
15
+
16
+ As used herein, "this License" refers to version 3 of the GNU Lesser
17
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
18
+ General Public License.
19
+
20
+ "The Library" refers to a covered work governed by this License,
21
+ other than an Application or a Combined Work as defined below.
22
+
23
+ An "Application" is any work that makes use of an interface provided
24
+ by the Library, but which is not otherwise based on the Library.
25
+ Defining a subclass of a class defined by the Library is deemed a mode
26
+ of using an interface provided by the Library.
27
+
28
+ A "Combined Work" is a work produced by combining or linking an
29
+ Application with the Library. The particular version of the Library
30
+ with which the Combined Work was made is also called the "Linked
31
+ Version".
32
+
33
+ The "Minimal Corresponding Source" for a Combined Work means the
34
+ Corresponding Source for the Combined Work, excluding any source code
35
+ for portions of the Combined Work that, considered in isolation, are
36
+ based on the Application, and not on the Linked Version.
37
+
38
+ The "Corresponding Application Code" for a Combined Work means the
39
+ object code and/or source code for the Application, including any data
40
+ and utility programs needed for reproducing the Combined Work from the
41
+ Application, but excluding the System Libraries of the Combined Work.
42
+
43
+ 1. Exception to Section 3 of the GNU GPL.
44
+
45
+ You may convey a covered work under sections 3 and 4 of this License
46
+ without being bound by section 3 of the GNU GPL.
47
+
48
+ 2. Conveying Modified Versions.
49
+
50
+ If you modify a copy of the Library, and, in your modifications, a
51
+ facility refers to a function or data to be supplied by an Application
52
+ that uses the facility (other than as an argument passed when the
53
+ facility is invoked), then you may convey a copy of the modified
54
+ version:
55
+
56
+ a) under this License, provided that you make a good faith effort to
57
+ ensure that, in the event an Application does not supply the
58
+ function or data, the facility still operates, and performs
59
+ whatever part of its purpose remains meaningful, or
60
+
61
+ b) under the GNU GPL, with none of the additional permissions of
62
+ this License applicable to that copy.
63
+
64
+ 3. Object Code Incorporating Material from Library Header Files.
65
+
66
+ The object code form of an Application may incorporate material from
67
+ a header file that is part of the Library. You may convey such object
68
+ code under terms of your choice, provided that, if the incorporated
69
+ material is not limited to numerical parameters, data structure
70
+ layouts and accessors, or small macros, inline functions and templates
71
+ (ten or fewer lines in length), you do both of the following:
72
+
73
+ a) Give prominent notice with each copy of the object code that the
74
+ Library is used in it and that the Library and its use are
75
+ covered by this License.
76
+
77
+ b) Accompany the object code with a copy of the GNU GPL and this license
78
+ document.
79
+
80
+ 4. Combined Works.
81
+
82
+ You may convey a Combined Work under terms of your choice that,
83
+ taken together, effectively do not restrict modification of the
84
+ portions of the Library contained in the Combined Work and reverse
85
+ engineering for debugging such modifications, if you also do each of
86
+ the following:
87
+
88
+ a) Give prominent notice with each copy of the Combined Work that
89
+ the Library is used in it and that the Library and its use are
90
+ covered by this License.
91
+
92
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
93
+ document.
94
+
95
+ c) For a Combined Work that displays copyright notices during
96
+ execution, include the copyright notice for the Library among
97
+ these notices, as well as a reference directing the user to the
98
+ copies of the GNU GPL and this license document.
99
+
100
+ d) Do one of the following:
101
+
102
+ 0) Convey the Minimal Corresponding Source under the terms of this
103
+ License, and the Corresponding Application Code in a form
104
+ suitable for, and under terms that permit, the user to
105
+ recombine or relink the Application with a modified version of
106
+ the Linked Version to produce a modified Combined Work, in the
107
+ manner specified by section 6 of the GNU GPL for conveying
108
+ Corresponding Source.
109
+
110
+ 1) Use a suitable shared library mechanism for linking with the
111
+ Library. A suitable mechanism is one that (a) uses at run time
112
+ a copy of the Library already present on the user's computer
113
+ system, and (b) will operate properly with a modified version
114
+ of the Library that is interface-compatible with the Linked
115
+ Version.
116
+
117
+ e) Provide Installation Information, but only if you would otherwise
118
+ be required to provide such information under section 6 of the
119
+ GNU GPL, and only to the extent that such information is
120
+ necessary to install and execute a modified version of the
121
+ Combined Work produced by recombining or relinking the
122
+ Application with a modified version of the Linked Version. (If
123
+ you use option 4d0, the Installation Information must accompany
124
+ the Minimal Corresponding Source and Corresponding Application
125
+ Code. If you use option 4d1, you must provide the Installation
126
+ Information in the manner specified by section 6 of the GNU GPL
127
+ for conveying Corresponding Source.)
128
+
129
+ 5. Combined Libraries.
130
+
131
+ You may place library facilities that are a work based on the
132
+ Library side by side in a single library together with other library
133
+ facilities that are not Applications and are not covered by this
134
+ License, and convey such a combined library under terms of your
135
+ choice, if you do both of the following:
136
+
137
+ a) Accompany the combined library with a copy of the same work based
138
+ on the Library, uncombined with any other library facilities,
139
+ conveyed under the terms of this License.
140
+
141
+ b) Give prominent notice with the combined library that part of it
142
+ is a work based on the Library, and explaining where to find the
143
+ accompanying uncombined form of the same work.
144
+
145
+ 6. Revised Versions of the GNU Lesser General Public License.
146
+
147
+ The Free Software Foundation may publish revised and/or new versions
148
+ of the GNU Lesser General Public License from time to time. Such new
149
+ versions will be similar in spirit to the present version, but may
150
+ differ in detail to address new problems or concerns.
151
+
152
+ Each version is given a distinguishing version number. If the
153
+ Library as you received it specifies that a certain numbered version
154
+ of the GNU Lesser General Public License "or any later version"
155
+ applies to it, you have the option of following the terms and
156
+ conditions either of that published version or of any later version
157
+ published by the Free Software Foundation. If the Library as you
158
+ received it does not specify a version number of the GNU Lesser
159
+ General Public License, you may choose any version of the GNU Lesser
160
+ General Public License ever published by the Free Software Foundation.
161
+
162
+ If the Library as you received it specifies that a proxy can decide
163
+ whether future versions of the GNU Lesser General Public License shall
164
+ apply, that proxy's public statement of acceptance of any version is
165
+ permanent authorization for you to choose that version for the
166
+ Library.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: resfo-utilities
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: A utility library for working with the output of reservoir simulators.
5
5
  Author-email: Equinor <fg_sib-scout@equinor.com>
6
6
  Maintainer-email: Eivind Jahren <ejah@equinor.com>, Håkon Steinkopf Søhoel <hsoho@equinor.com>
@@ -16,11 +16,11 @@ Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Requires-Python: <3.14,>=3.11
18
18
  Description-Content-Type: text/markdown
19
+ License-File: LICENSE.md
19
20
  Requires-Dist: numpy
20
21
  Requires-Dist: resfo
21
- Requires-Dist: shapely
22
- Requires-Dist: trimesh[easy]
23
22
  Requires-Dist: matplotlib
23
+ Requires-Dist: scipy
24
24
  Provides-Extra: doc
25
25
  Requires-Dist: sphinx; extra == "doc"
26
26
  Requires-Dist: sphinx-rtd-theme; extra == "doc"
@@ -29,11 +29,12 @@ Requires-Dist: pytest; extra == "dev"
29
29
  Requires-Dist: hypothesis; extra == "dev"
30
30
  Requires-Dist: pre-commit; extra == "dev"
31
31
  Requires-Dist: mypy; extra == "dev"
32
- Requires-Dist: types-shapely; extra == "dev"
33
32
  Requires-Dist: pytest-benchmark; extra == "dev"
33
+ Requires-Dist: scipy-stubs; extra == "dev"
34
+ Dynamic: license-file
34
35
 
35
- resfo
36
- ===========
36
+ resfo-utilities
37
+ ===============
37
38
 
38
39
 
39
40
  resfo-utilities is a library for working with output from
@@ -1,5 +1,5 @@
1
- resfo
2
- ===========
1
+ resfo-utilities
2
+ ===============
3
3
 
4
4
 
5
5
  resfo-utilities is a library for working with output from
@@ -4,14 +4,14 @@ Glossary
4
4
  .. glossary::
5
5
 
6
6
  corner-point grid
7
- A corner-point grid is a tessellation of a 3D volumne where
7
+ A corner-point grid is a tessellation of a 3D volume where
8
8
  each cell is a hexahedron. See the `corner-point grid wikipedia page`_ or
9
9
  `OPM Flow manual`_ section 6.2.2 for more information.
10
10
 
11
11
  pillar
12
12
  In a :term:`corner-point grid` the pillars are a set of straight lines used
13
- to define each cell. The 8 corner vertecies of each cell is determined by
14
- the giving the height along four adjecent pillars.
13
+ to define each cell. The 8 corner vertices of each cell is determined by
14
+ giving the height along four adjacent pillars.
15
15
 
16
16
  UTM-coordinates
17
17
  The Universal Transverse Mercator (UTM) is a coordinate system based on
@@ -15,7 +15,7 @@ classifiers=[
15
15
  "Programming Language :: Python :: 3.12",
16
16
  "Programming Language :: Python :: 3.13",
17
17
  ]
18
- dependencies = ["numpy","resfo", "shapely", "trimesh[easy]", "matplotlib"]
18
+ dependencies = ["numpy","resfo", "matplotlib", "scipy"]
19
19
  dynamic=["version"]
20
20
 
21
21
  authors = [
@@ -45,8 +45,8 @@ dev = [
45
45
  "hypothesis",
46
46
  "pre-commit",
47
47
  "mypy",
48
- "types-shapely",
49
48
  "pytest-benchmark",
49
+ "scipy-stubs",
50
50
  ]
51
51
 
52
52
  [tool.setuptools_scm]
@@ -1,11 +1,11 @@
1
1
  from __future__ import annotations
2
2
  import os
3
- from typing import Self, Any, IO, TypeVar
3
+ from typing import Self, Any, IO, TypeVar, Callable
4
4
  from dataclasses import dataclass
5
5
  from numpy import typing as npt
6
6
  import numpy as np
7
7
  import resfo
8
- import trimesh
8
+ import scipy.optimize
9
9
  import warnings
10
10
  from matplotlib.path import Path
11
11
  import heapq
@@ -72,7 +72,7 @@ class MapAxes:
72
72
  @dataclass
73
73
  class CornerpointGrid:
74
74
  """
75
- A :term:`corner-point grid` is a tessellation of a 3D volumne where
75
+ A :term:`corner-point grid` is a tessellation of a 3D volume where
76
76
  each cell is a hexahedron.
77
77
 
78
78
  Each cell is identified by a integer coordinate (i,j,k).
@@ -92,14 +92,15 @@ class CornerpointGrid:
92
92
  of the i,j pillar and coord[i,j,1] is the corresponding bottom end point.
93
93
  zcorn:
94
94
  A (ni, nj, nk, 8) array where zcorn[i,j,k] is the z value of
95
- the 8 corners of the cell at i,j,k.
95
+ the 8 corners of the cell at i,j,k. The order of the corner z values
96
+ are as follows:
97
+ [TSW, TSE, TNW, TNE, BSW, BSE, BNW, BNE] where N(orth) means higher y,
98
+ E(east) means higher x, T(op) means lower z (when z is interpreted as depth).
96
99
 
97
100
  map_axes:
98
101
  Optionally each point is interpreted to be relative to some map
99
102
  coordinate system. Defaults to the unit coordinate system with
100
- origo at (0,0). The order of the corner z valus are as follows:
101
- [TSW, TSE, TNW, TNE, BSW, BSE, BNW, BNE] where N(orth) means higher y,
102
- E(east) means higer x, T(op) means lower z (when z is interpreted as depth).
103
+ origin at (0,0).
103
104
 
104
105
  """
105
106
 
@@ -117,7 +118,7 @@ class CornerpointGrid:
117
118
 
118
119
  Args:
119
120
  file_like:
120
- The EGRID file, could either be a filename, patlike or an opened
121
+ The EGRID file, could either be a filename, pathlike or an opened
121
122
  EGRID file. The function also handles formatted egrid files (.FEGRID).
122
123
  Whether the file is formatted or not is determined by looking at the
123
124
  extension a filepath is given and by whether the stream is a byte-stream
@@ -245,8 +246,11 @@ class CornerpointGrid:
245
246
  return cls(coord, zcorn, map_axes)
246
247
 
247
248
  def find_cell_containing_point(
248
- self, points: npt.ArrayLike, map_coordinates: bool = True
249
- ) -> list[tuple[float, float, float] | None]:
249
+ self,
250
+ points: npt.ArrayLike,
251
+ map_coordinates: bool = True,
252
+ tolerance: float = 1.0e-6,
253
+ ) -> list[tuple[int, int, int] | None]:
250
254
  """Find a cell in the grid which contains the given point.
251
255
 
252
256
  Args:
@@ -255,13 +259,16 @@ class CornerpointGrid:
255
259
  map_coordinates:
256
260
  Whether points are in the map coordinate system.
257
261
  Defaults to True.
262
+ tolerance:
263
+ The maximum distance to the cell boundary a point can have to
264
+ be considered to be contained in the cell.
258
265
 
259
266
  Returns:
260
- list of i,j,k indecies for each point (or None if the
267
+ list of i,j,k indices for each point (or None if the
261
268
  point is not contained in any cell.
262
269
  """
263
270
  points = np.asarray(points)
264
- result: list[tuple[float, float, float] | None] = []
271
+ result: list[tuple[int, int, int] | None] = []
265
272
  if map_coordinates and self.map_axes is not None:
266
273
  points = self.map_axes.transform_map_points(points)
267
274
 
@@ -321,7 +328,7 @@ class CornerpointGrid:
321
328
  def __lt__(self, other: object) -> bool:
322
329
  """Used to order elements in the search queue.
323
330
 
324
- The Quads are orderd by distance_from_bounds.
331
+ The Quads are ordered by distance_from_bounds.
325
332
  """
326
333
  if not isinstance(other, Quad):
327
334
  return False
@@ -346,14 +353,16 @@ class CornerpointGrid:
346
353
 
347
354
  # If the quad contains the point then search through each k index
348
355
  # for that quad
349
- if node.distance_from_bounds <= 0 and Path(vertices).contains_points(
350
- [p[0:2]]
351
- ):
356
+ if node.distance_from_bounds <= tolerance and Path(
357
+ vertices
358
+ ).contains_points([p[0:2]], radius=tolerance):
352
359
  for k in range(self.zcorn.shape[2]):
353
360
  zcorn = self.zcorn[i, j, k]
361
+ z = p[2]
354
362
  # Prune by bounding box first then check whether point_in_cell
355
- if zcorn.min() <= p[2] <= zcorn.max() and self.point_in_cell(
356
- p, i, j, k, map_coordinates=False
363
+ if (
364
+ zcorn.min() - tolerance <= z <= zcorn.max() + tolerance
365
+ and self.point_in_cell(p, i, j, k, map_coordinates=False)
357
366
  ):
358
367
  prev_ij = (i, j)
359
368
  result.append((i, j, k))
@@ -378,6 +387,30 @@ class CornerpointGrid:
378
387
 
379
388
  return result
380
389
 
390
+ def cell_corners(self, i: int, j: int, k: int) -> npt.NDArray[np.float32]:
391
+ """Array of coordinates for all corners of the cell at i,j,k
392
+
393
+ The order of the corners are the same as in zcorn.
394
+ """
395
+ pillar_vertices = np.concatenate(
396
+ [
397
+ self.coord[i, j, :],
398
+ self.coord[i, j + 1, :],
399
+ self.coord[i + 1, j, :],
400
+ self.coord[i + 1, j + 1, :],
401
+ ]
402
+ )
403
+ top = pillar_vertices[::2][[0, 2, 1, 3]]
404
+ bot = pillar_vertices[1::2][[0, 2, 1, 3]]
405
+ top_z = top[:, 2]
406
+ bot_z = bot[:, 2]
407
+
408
+ def twice(a: npt.NDArray[Any]) -> npt.NDArray[Any]:
409
+ return np.concatenate([a, a])
410
+
411
+ t = (self.zcorn[i, j, k] - twice(top_z)) / twice(bot_z - top_z)
412
+ return twice(top) + t[:, np.newaxis] * twice(bot - top)
413
+
381
414
  def point_in_cell(
382
415
  self,
383
416
  points: npt.ArrayLike,
@@ -389,12 +422,14 @@ class CornerpointGrid:
389
422
  ) -> npt.NDArray[np.bool_]:
390
423
  """Whether the points (x,y,z) is in the cell at (i,j,k).
391
424
 
425
+ For containment the cell are considered to have bilinear faces.
426
+
392
427
  Param:
393
428
  points:
394
429
  x,y,z triple or array of x,y,z triples to be tested for containment.
395
430
  tolerance:
396
- The maximum distance to the cell boundary a point can have to
397
- be considered to be contained in the cell.
431
+ The tolerance used for numerical precision in the linear
432
+ interpolation calculation.
398
433
  map_coordinates:
399
434
  Whether the given points are in the mapaxes coordinate system,
400
435
  defaults to true.
@@ -408,43 +443,65 @@ class CornerpointGrid:
408
443
  points = points[np.newaxis, :]
409
444
  if map_coordinates and self.map_axes is not None:
410
445
  points = self.map_axes.transform_map_points(points)
411
- pillar_vertices = np.concatenate(
446
+
447
+ vertices = self.cell_corners(i, j, k).astype(np.float64)
448
+
449
+ corner_signs = np.array(
412
450
  [
413
- self.coord[i, j, :],
414
- self.coord[i, j + 1, :],
415
- self.coord[i + 1, j, :],
416
- self.coord[i + 1, j + 1, :],
451
+ [-1, -1, -1],
452
+ [1, -1, -1],
453
+ [-1, 1, -1],
454
+ [1, 1, -1],
455
+ [-1, -1, 1],
456
+ [1, -1, 1],
457
+ [-1, 1, 1],
458
+ [1, 1, 1],
417
459
  ]
418
460
  )
419
- top = pillar_vertices[::2][[0, 2, 1, 3]]
420
- bot = pillar_vertices[1::2][[0, 2, 1, 3]]
421
- top_z = top[:, 2]
422
- bot_z = bot[:, 2]
423
-
424
- def twice(a: npt.NDArray[Any]) -> npt.NDArray[Any]:
425
- return np.concatenate([a, a])
426
461
 
427
- t = (self.zcorn[i, j, k] - twice(top_z)) / twice(bot_z - top_z)
428
- mesh = trimesh.Trimesh(
429
- vertices=twice(top) + t[:, np.newaxis] * twice(bot - top),
430
- faces=np.array(
431
- [
432
- [0, 1, 2],
433
- [1, 2, 3],
434
- [0, 1, 5],
435
- [0, 4, 5],
436
- [0, 2, 6],
437
- [0, 4, 6],
438
- [4, 6, 5],
439
- [5, 6, 7],
440
- [1, 3, 7],
441
- [1, 5, 7],
442
- [2, 3, 7],
443
- [2, 6, 7],
444
- ]
445
- ),
446
- )
447
- return mesh.contains(points) | (mesh.nearest.on_surface(points)[1] < tolerance)
462
+ def residual(
463
+ point: tuple[float, float, float],
464
+ ) -> Callable[[npt.NDArray[np.float64]], npt.NDArray[np.float64]]:
465
+ def inner(
466
+ xi_eta_zeta: npt.NDArray[np.float64],
467
+ ) -> npt.NDArray[np.float64]:
468
+ xi, eta, zeta = xi_eta_zeta
469
+ shape_matrix = (
470
+ 1
471
+ / 8
472
+ * (1 + xi * corner_signs[:, 0])
473
+ * (1 + eta * corner_signs[:, 1])
474
+ * (1 + zeta * corner_signs[:, 2])
475
+ )
476
+ mapped = shape_matrix @ vertices
477
+ return mapped - point
478
+
479
+ return inner
480
+
481
+ solutions = []
482
+ for point in points:
483
+ point = point.astype(np.float64)
484
+ initial_guess = 2 * (point - vertices[0]) / (vertices[6] - vertices[0]) - 1
485
+ initial_guess = np.clip(initial_guess, -1, 1)
486
+ np.nan_to_num(initial_guess, copy=False)
487
+ sol = scipy.optimize.least_squares(
488
+ residual(point),
489
+ initial_guess,
490
+ method="trf",
491
+ xtol=tolerance,
492
+ ftol=tolerance,
493
+ gtol=tolerance,
494
+ )
495
+ if not sol.success:
496
+ solutions.append(False)
497
+ else:
498
+ solutions.append(
499
+ bool(
500
+ np.all(np.abs(sol.x) <= 1.0 + tolerance)
501
+ and np.linalg.norm(residual(point)(sol.x)) <= 1e-4 + tolerance
502
+ )
503
+ )
504
+ return np.array(solutions, dtype=np.bool_)
448
505
 
449
506
  def _pillars_z_plane_intersection(self, z: np.float32) -> npt.NDArray[np.float32]:
450
507
  shape = self.coord.shape
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: resfo-utilities
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: A utility library for working with the output of reservoir simulators.
5
5
  Author-email: Equinor <fg_sib-scout@equinor.com>
6
6
  Maintainer-email: Eivind Jahren <ejah@equinor.com>, Håkon Steinkopf Søhoel <hsoho@equinor.com>
@@ -16,11 +16,11 @@ Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Requires-Python: <3.14,>=3.11
18
18
  Description-Content-Type: text/markdown
19
+ License-File: LICENSE.md
19
20
  Requires-Dist: numpy
20
21
  Requires-Dist: resfo
21
- Requires-Dist: shapely
22
- Requires-Dist: trimesh[easy]
23
22
  Requires-Dist: matplotlib
23
+ Requires-Dist: scipy
24
24
  Provides-Extra: doc
25
25
  Requires-Dist: sphinx; extra == "doc"
26
26
  Requires-Dist: sphinx-rtd-theme; extra == "doc"
@@ -29,11 +29,12 @@ Requires-Dist: pytest; extra == "dev"
29
29
  Requires-Dist: hypothesis; extra == "dev"
30
30
  Requires-Dist: pre-commit; extra == "dev"
31
31
  Requires-Dist: mypy; extra == "dev"
32
- Requires-Dist: types-shapely; extra == "dev"
33
32
  Requires-Dist: pytest-benchmark; extra == "dev"
33
+ Requires-Dist: scipy-stubs; extra == "dev"
34
+ Dynamic: license-file
34
35
 
35
- resfo
36
- ===========
36
+ resfo-utilities
37
+ ===============
37
38
 
38
39
 
39
40
  resfo-utilities is a library for working with output from
@@ -3,6 +3,7 @@
3
3
  .pre-commit-config.yaml
4
4
  .readthedocs.yaml
5
5
  CONTRIBUTING.md
6
+ LICENSE.md
6
7
  README.md
7
8
  SECURITY.md
8
9
  pyproject.toml
@@ -1,16 +1,15 @@
1
1
  numpy
2
2
  resfo
3
- shapely
4
- trimesh[easy]
5
3
  matplotlib
4
+ scipy
6
5
 
7
6
  [dev]
8
7
  pytest
9
8
  hypothesis
10
9
  pre-commit
11
10
  mypy
12
- types-shapely
13
11
  pytest-benchmark
12
+ scipy-stubs
14
13
 
15
14
  [doc]
16
15
  sphinx
@@ -7,7 +7,7 @@ import pytest
7
7
  @pytest.fixture
8
8
  def large_regular_grid():
9
9
  ni, nj, nk = 50, 50, 10
10
- height = 500
10
+ height = 100
11
11
  top_depth = 0.0
12
12
  bot_depth = top_depth + height
13
13
  coord = np.zeros((ni + 1, nj + 1, 2, 3), dtype=np.float32)
@@ -16,14 +16,14 @@ def large_regular_grid():
16
16
  coord[i, j, 0] = [i, j, top_depth]
17
17
  coord[i, j, 1] = [i, j, bot_depth]
18
18
  for i, j, k in product(range(ni), range(nj), range(nk)):
19
- zcorn[i, j, k] = [height * (k // nk)] * 4 + [height * ((k + 1) // nk)] * 4
19
+ zcorn[i, j, k] = [height * (k / nk)] * 4 + [height * ((k + 1) / nk)] * 4
20
20
  return CornerpointGrid(coord, zcorn)
21
21
 
22
22
 
23
23
  def test_benchmark_find_cell(large_regular_grid, benchmark):
24
24
  def run():
25
25
  assert large_regular_grid.find_cell_containing_point(
26
- [(i + 25.5, j + 25.5, 20.0) for i, j in product(range(10), range(10))]
27
- ) == [(i + 25, j + 25, 9) for i, j in product(range(10), range(10))]
26
+ [(i + 25.5, j + 25.5, 20.5) for i, j in product(range(10), range(10))]
27
+ ) == [(i + 25, j + 25, 2) for i, j in product(range(10), range(10))]
28
28
 
29
29
  benchmark(run)