@@ -15,6 +15,9 @@ import scipy.sparse as sp
15
15
import numpy as np
16
16
from .interputils_cython cimport _bisect_left, _bisect_right
17
17
18
+ class TreeMeshNotFinalizedError (RuntimeError ):
19
+ """ Raise when a TreeMesh is not finalized."""
20
+
18
21
19
22
cdef class TreeCell:
20
23
""" A class for defining cells within instances of :class:`~discretize.TreeMesh`.
@@ -1959,7 +1962,7 @@ cdef class _TreeMesh:
1959
1962
(n_cells, dim) numpy.ndarray of float
1960
1963
Gridded cell center locations
1961
1964
"""
1962
- self ._error_if_not_finalized(" cell_centers" , is_property = True )
1965
+ self ._error_if_not_finalized(" cell_centers" )
1963
1966
cdef np.float64_t[:, :] gridCC
1964
1967
cdef np.int64_t ii, ind, dim
1965
1968
if self ._cell_centers is None :
@@ -1985,7 +1988,7 @@ cdef class _TreeMesh:
1985
1988
(n_nodes, dim) numpy.ndarray of float
1986
1989
Gridded non-hanging node locations
1987
1990
"""
1988
- self ._error_if_not_finalized(" nodes" , is_property = True )
1991
+ self ._error_if_not_finalized(" nodes" )
1989
1992
cdef np.float64_t[:, :] gridN
1990
1993
cdef Node * node
1991
1994
cdef np.int64_t ii, ind, dim
@@ -2014,7 +2017,7 @@ cdef class _TreeMesh:
2014
2017
(n_hanging_nodes, dim) numpy.ndarray of float
2015
2018
Gridded hanging node locations
2016
2019
"""
2017
- self ._error_if_not_finalized(" hanging_nodes" , is_property = True )
2020
+ self ._error_if_not_finalized(" hanging_nodes" )
2018
2021
cdef np.float64_t[:, :] gridN
2019
2022
cdef Node * node
2020
2023
cdef np.int64_t ii, ind, dim
@@ -2041,7 +2044,7 @@ cdef class _TreeMesh:
2041
2044
(n_boundary_nodes, dim) numpy.ndarray of float
2042
2045
Gridded boundary node locations
2043
2046
"""
2044
- self ._error_if_not_finalized(" boundary_nodes" , is_property = True )
2047
+ self ._error_if_not_finalized(" boundary_nodes" )
2045
2048
nodes = self .nodes
2046
2049
x0, xF = self ._xs[0 ], self ._xs[- 1 ]
2047
2050
y0, yF = self ._ys[0 ], self ._ys[- 1 ]
@@ -2073,7 +2076,7 @@ cdef class _TreeMesh:
2073
2076
(n_cells, dim) numpy.ndarray of float
2074
2077
Gridded cell dimensions
2075
2078
"""
2076
- self ._error_if_not_finalized(" h_gridded" , is_property = True )
2079
+ self ._error_if_not_finalized(" h_gridded" )
2077
2080
if self ._h_gridded is not None :
2078
2081
return self ._h_gridded
2079
2082
cdef np.float64_t[:, :] gridCH
@@ -2102,7 +2105,7 @@ cdef class _TreeMesh:
2102
2105
(n_edges_x, dim) numpy.ndarray of float
2103
2106
Gridded locations of all non-hanging x-edges
2104
2107
"""
2105
- self ._error_if_not_finalized(" edges_x" , is_property = True )
2108
+ self ._error_if_not_finalized(" edges_x" )
2106
2109
cdef np.float64_t[:, :] gridEx
2107
2110
cdef Edge * edge
2108
2111
cdef np.int64_t ii, ind, dim
@@ -2130,7 +2133,7 @@ cdef class _TreeMesh:
2130
2133
(n_hanging_edges_x, dim) numpy.ndarray of float
2131
2134
Gridded locations of all hanging x-edges
2132
2135
"""
2133
- self ._error_if_not_finalized(" hanging_edges_x" , is_property = True )
2136
+ self ._error_if_not_finalized(" hanging_edges_x" )
2134
2137
cdef np.float64_t[:, :] gridhEx
2135
2138
cdef Edge * edge
2136
2139
cdef np.int64_t ii, ind, dim
@@ -2156,7 +2159,7 @@ cdef class _TreeMesh:
2156
2159
(n_edges_y, dim) numpy.ndarray of float
2157
2160
Gridded locations of all non-hanging y-edges
2158
2161
"""
2159
- self ._error_if_not_finalized(" edges_y" , is_property = True )
2162
+ self ._error_if_not_finalized(" edges_y" )
2160
2163
cdef np.float64_t[:, :] gridEy
2161
2164
cdef Edge * edge
2162
2165
cdef np.int64_t ii, ind, dim
@@ -2184,7 +2187,7 @@ cdef class _TreeMesh:
2184
2187
(n_haning_edges_y, dim) numpy.ndarray of float
2185
2188
Gridded locations of all hanging y-edges
2186
2189
"""
2187
- self ._error_if_not_finalized(" hanging_edges_y" , is_property = True )
2190
+ self ._error_if_not_finalized(" hanging_edges_y" )
2188
2191
cdef np.float64_t[:, :] gridhEy
2189
2192
cdef Edge * edge
2190
2193
cdef np.int64_t ii, ind, dim
@@ -2210,7 +2213,7 @@ cdef class _TreeMesh:
2210
2213
(n_edges_z, dim) numpy.ndarray of float
2211
2214
Gridded locations of all non-hanging z-edges
2212
2215
"""
2213
- self ._error_if_not_finalized(" edges_z" , is_property = True )
2216
+ self ._error_if_not_finalized(" edges_z" )
2214
2217
cdef np.float64_t[:, :] gridEz
2215
2218
cdef Edge * edge
2216
2219
cdef np.int64_t ii, ind, dim
@@ -2238,7 +2241,7 @@ cdef class _TreeMesh:
2238
2241
(n_hanging_edges_z, dim) numpy.ndarray of float
2239
2242
Gridded locations of all hanging z-edges
2240
2243
"""
2241
- self ._error_if_not_finalized(" hanging_edges_z" , is_property = True )
2244
+ self ._error_if_not_finalized(" hanging_edges_z" )
2242
2245
cdef np.float64_t[:, :] gridhEz
2243
2246
cdef Edge * edge
2244
2247
cdef np.int64_t ii, ind, dim
@@ -2266,7 +2269,7 @@ cdef class _TreeMesh:
2266
2269
(n_boundary_edges, dim) numpy.ndarray of float
2267
2270
Gridded boundary edge locations
2268
2271
"""
2269
- self ._error_if_not_finalized(" boundary_edges" , is_property = True )
2272
+ self ._error_if_not_finalized(" boundary_edges" )
2270
2273
edges_x = self .edges_x
2271
2274
edges_y = self .edges_y
2272
2275
x0, xF = self ._xs[0 ], self ._xs[- 1 ]
@@ -2306,7 +2309,7 @@ cdef class _TreeMesh:
2306
2309
(n_faces_x, dim) numpy.ndarray of float
2307
2310
Gridded locations of all non-hanging x-faces
2308
2311
"""
2309
- self ._error_if_not_finalized(" faces_x" , is_property = True )
2312
+ self ._error_if_not_finalized(" faces_x" )
2310
2313
if (self ._dim == 2 ): return self .edges_y
2311
2314
2312
2315
cdef np.float64_t[:, :] gridFx
@@ -2336,7 +2339,7 @@ cdef class _TreeMesh:
2336
2339
(n_faces_y, dim) numpy.ndarray of float
2337
2340
Gridded locations of all non-hanging y-faces
2338
2341
"""
2339
- self ._error_if_not_finalized(" faces_y" , is_property = True )
2342
+ self ._error_if_not_finalized(" faces_y" )
2340
2343
if (self ._dim == 2 ): return self .edges_x
2341
2344
cdef np.float64_t[:, :] gridFy
2342
2345
cdef Face * face
@@ -2365,7 +2368,7 @@ cdef class _TreeMesh:
2365
2368
(n_faces_z, dim) numpy.ndarray of float
2366
2369
Gridded locations of all non-hanging z-faces
2367
2370
"""
2368
- self ._error_if_not_finalized(" faces_z" , is_property = True )
2371
+ self ._error_if_not_finalized(" faces_z" )
2369
2372
if (self ._dim == 2 ): return self .cell_centers
2370
2373
2371
2374
cdef np.float64_t[:, :] gridFz
@@ -2395,7 +2398,7 @@ cdef class _TreeMesh:
2395
2398
(n_hanging_faces_x, dim) numpy.ndarray of float
2396
2399
Gridded locations of all hanging x-faces
2397
2400
"""
2398
- self ._error_if_not_finalized(" hanging_faces_x" , is_property = True )
2401
+ self ._error_if_not_finalized(" hanging_faces_x" )
2399
2402
if (self ._dim == 2 ): return self .hanging_edges_y
2400
2403
2401
2404
cdef np.float64_t[:, :] gridFx
@@ -2423,7 +2426,7 @@ cdef class _TreeMesh:
2423
2426
(n_hanging_faces_y, dim) numpy.ndarray of float
2424
2427
Gridded locations of all hanging y-faces
2425
2428
"""
2426
- self ._error_if_not_finalized(" hanging_faces_y" , is_property = True )
2429
+ self ._error_if_not_finalized(" hanging_faces_y" )
2427
2430
if (self ._dim == 2 ): return self .hanging_edges_x
2428
2431
2429
2432
cdef np.float64_t[:, :] gridhFy
@@ -2451,7 +2454,7 @@ cdef class _TreeMesh:
2451
2454
(n_hanging_faces_z, dim) numpy.ndarray of float
2452
2455
Gridded locations of all hanging z-faces
2453
2456
"""
2454
- self ._error_if_not_finalized(" hanging_faces_z" , is_property = True )
2457
+ self ._error_if_not_finalized(" hanging_faces_z" )
2455
2458
if (self ._dim == 2 ): return np.array([])
2456
2459
2457
2460
cdef np.float64_t[:, :] gridhFz
@@ -2481,7 +2484,7 @@ cdef class _TreeMesh:
2481
2484
(n_boundary_faces, dim) numpy.ndarray of float
2482
2485
Gridded boundary face locations
2483
2486
"""
2484
- self ._error_if_not_finalized(" boundary_faces" , is_property = True )
2487
+ self ._error_if_not_finalized(" boundary_faces" )
2485
2488
faces_x = self .faces_x
2486
2489
faces_y = self .faces_y
2487
2490
x0, xF = self ._xs[0 ], self ._xs[- 1 ]
@@ -2511,7 +2514,7 @@ cdef class _TreeMesh:
2511
2514
(n_boundary_faces, dim) numpy.ndarray of float
2512
2515
Outward normals of boundary faces
2513
2516
"""
2514
- self ._error_if_not_finalized(" boundary_face_outward_normals" , is_property = True )
2517
+ self ._error_if_not_finalized(" boundary_face_outward_normals" )
2515
2518
faces_x = self .faces_x
2516
2519
faces_y = self .faces_y
2517
2520
x0, xF = self ._xs[0 ], self ._xs[- 1 ]
@@ -2554,7 +2557,7 @@ cdef class _TreeMesh:
2554
2557
- *3D:* Returns the cell volumes
2555
2558
2556
2559
"""
2557
- self ._error_if_not_finalized(" cell_volumes" , is_property = True )
2560
+ self ._error_if_not_finalized(" cell_volumes" )
2558
2561
cdef np.float64_t[:] vol
2559
2562
if self ._cell_volumes is None :
2560
2563
self ._cell_volumes = np.empty(self .n_cells, dtype = np.float64)
@@ -2579,7 +2582,7 @@ cdef class _TreeMesh:
2579
2582
respectively
2580
2583
- *3D:* returns the x, y and z-face areas in order
2581
2584
"""
2582
- self ._error_if_not_finalized(" face_areas" , is_property = True )
2585
+ self ._error_if_not_finalized(" face_areas" )
2583
2586
if self ._dim == 2 and self ._face_areas is None :
2584
2587
self ._face_areas = np.r_[self .edge_lengths[self .n_edges_x:], self .edge_lengths[:self .n_edges_x]]
2585
2588
cdef np.float64_t[:] area
@@ -2622,7 +2625,7 @@ cdef class _TreeMesh:
2622
2625
- *2D:* returns the x-edge and y-edge lengths in order
2623
2626
- *3D:* returns the x, y and z-edge lengths in order
2624
2627
"""
2625
- self ._error_if_not_finalized(" edge_lengths" , is_property = True )
2628
+ self ._error_if_not_finalized(" edge_lengths" )
2626
2629
cdef np.float64_t[:] edge_l
2627
2630
cdef Edge * edge
2628
2631
cdef int_t ind, offset
@@ -3587,7 +3590,7 @@ cdef class _TreeMesh:
3587
3590
( n_total_faces_x, n_cells) scipy. sparse. csr_matrix
3588
3591
The stencil for the x-component of the cell gradient
3589
3592
"""
3590
- self ._error_if_not_finalized(" stencil_cell_gradient_x" , is_property = True )
3593
+ self ._error_if_not_finalized(" stencil_cell_gradient_x" )
3591
3594
if getattr (self , ' _stencil_cell_gradient_x' , None ) is not None :
3592
3595
return self ._stencil_cell_gradient_x
3593
3596
cdef np.int64_t[:] I = np.zeros(2 * self .n_total_faces_x, dtype = np.int64)
@@ -3665,7 +3668,7 @@ cdef class _TreeMesh:
3665
3668
( n_total_faces_y, n_cells) scipy. sparse. csr_matrix
3666
3669
The stencil for the y-component of the cell gradient
3667
3670
"""
3668
- self ._error_if_not_finalized(" stencil_cell_gradient_y" , is_property = True )
3671
+ self ._error_if_not_finalized(" stencil_cell_gradient_y" )
3669
3672
if getattr (self , ' _stencil_cell_gradient_y' , None ) is not None :
3670
3673
return self ._stencil_cell_gradient_y
3671
3674
@@ -3744,7 +3747,7 @@ cdef class _TreeMesh:
3744
3747
( n_total_faces_z, n_cells) scipy. sparse. csr_matrix
3745
3748
The stencil for the z-component of the cell gradient
3746
3749
"""
3747
- self ._error_if_not_finalized(" stencil_cell_gradient_z" , is_property = True )
3750
+ self ._error_if_not_finalized(" stencil_cell_gradient_z" )
3748
3751
if getattr (self , ' _stencil_cell_gradient_z' , None ) is not None :
3749
3752
return self ._stencil_cell_gradient_z
3750
3753
@@ -5045,7 +5048,7 @@ cdef class _TreeMesh:
5045
5048
5046
5049
phi_f = Acf @ phi_c
5047
5050
"""
5048
- self ._error_if_not_finalized(" average_cell_to_face" , is_property = True )
5051
+ self ._error_if_not_finalized(" average_cell_to_face" )
5049
5052
if self ._average_cell_to_face is not None :
5050
5053
return self ._average_cell_to_face
5051
5054
stacks = [self .average_cell_to_face_x, self .average_cell_to_face_y]
@@ -5106,7 +5109,7 @@ cdef class _TreeMesh:
5106
5109
in the x-direction. For boundary faces, nearest neighbor is used to extrapolate
5107
5110
the values.
5108
5111
"""
5109
- self ._error_if_not_finalized(" average_cell_vector_to_face" , is_property = True )
5112
+ self ._error_if_not_finalized(" average_cell_vector_to_face" )
5110
5113
if self ._average_cell_vector_to_face is not None :
5111
5114
return self ._average_cell_vector_to_face
5112
5115
stacks = [self .average_cell_to_face_x, self .average_cell_to_face_y]
@@ -5130,7 +5133,7 @@ cdef class _TreeMesh:
5130
5133
(n_faces_x, n_cells) scipy.sparse.csr_matrix
5131
5134
The scalar averaging operator from cell centers to x faces
5132
5135
"""
5133
- self ._error_if_not_finalized(" average_cell_to_face_x" , is_property = True )
5136
+ self ._error_if_not_finalized(" average_cell_to_face_x" )
5134
5137
if self ._average_cell_to_face_x is not None :
5135
5138
return self ._average_cell_to_face_x
5136
5139
cdef np.int64_t[:] I = np.zeros(2 * self .n_total_faces_x, dtype = np.int64)
@@ -5247,7 +5250,7 @@ cdef class _TreeMesh:
5247
5250
(n_faces_y, n_cells) scipy.sparse.csr_matrix
5248
5251
The scalar averaging operator from cell centers to y faces
5249
5252
"""
5250
- self ._error_if_not_finalized(" average_cell_to_face_y" , is_property = True )
5253
+ self ._error_if_not_finalized(" average_cell_to_face_y" )
5251
5254
if self ._average_cell_to_face_y is not None :
5252
5255
return self ._average_cell_to_face_y
5253
5256
cdef np.int64_t[:] I = np.zeros(2 * self .n_total_faces_y, dtype = np.int64)
@@ -5364,7 +5367,7 @@ cdef class _TreeMesh:
5364
5367
(n_faces_z, n_cells) scipy.sparse.csr_matrix
5365
5368
The scalar averaging operator from cell centers to z faces
5366
5369
"""
5367
- self ._error_if_not_finalized(" average_cell_to_face_z" , is_property = True )
5370
+ self ._error_if_not_finalized(" average_cell_to_face_z" )
5368
5371
if self .dim == 2 :
5369
5372
raise Exception (' TreeMesh has no z-faces in 2D' )
5370
5373
if self ._average_cell_to_face_z is not None :
@@ -5455,7 +5458,7 @@ cdef class _TreeMesh:
5455
5458
scipy. sparse. csr_matrix
5456
5459
( n_boundary_faces, n_faces) Projection matrix with shape
5457
5460
"""
5458
- self ._error_if_not_finalized(" project_face_to_boundary_face" , is_property = True )
5461
+ self ._error_if_not_finalized(" project_face_to_boundary_face" )
5459
5462
faces_x = self .faces_x
5460
5463
faces_y = self .faces_y
5461
5464
@@ -5491,7 +5494,7 @@ cdef class _TreeMesh:
5491
5494
( n_boundary_edges, n_edges) scipy. sparse. csr_matrix
5492
5495
Projection matrix with shape
5493
5496
"""
5494
- self ._error_if_not_finalized(" project_edge_to_boundary_edge" , is_property = True )
5497
+ self ._error_if_not_finalized(" project_edge_to_boundary_edge" )
5495
5498
edges_x = self .edges_x
5496
5499
edges_y = self .edges_y
5497
5500
@@ -5534,7 +5537,7 @@ cdef class _TreeMesh:
5534
5537
( n_boundary_nodes, n_nodes) scipy. sparse. csr_matrix
5535
5538
Projection matrix with shape
5536
5539
"""
5537
- self ._error_if_not_finalized(" project_node_to_boundary_node" , is_property = True )
5540
+ self ._error_if_not_finalized(" project_node_to_boundary_node" )
5538
5541
nodes = self .nodes
5539
5542
x0, xF = self ._xs[0 ], self ._xs[- 1 ]
5540
5543
y0, yF = self ._ys[0 ], self ._ys[- 1 ]
@@ -6998,7 +7001,7 @@ cdef class _TreeMesh:
6998
7001
"""
6999
7002
return self .get_cells_in_aabb(* rectangle.reshape(self .dim, 2 ).T)
7000
7003
7001
- def _error_if_not_finalized (self , method: str , is_property: bool ):
7004
+ def _error_if_not_finalized (self , method: str ):
7002
7005
"""
7003
7006
Raise error if mesh is not finalized.
7004
7007
"""
0 commit comments