1
+ from pathlib import Path
2
+ from tempfile import TemporaryDirectory
3
+
1
4
import numpy as np
2
5
3
6
from flopy .discretization import StructuredGrid , UnstructuredGrid , VertexGrid
6
9
7
10
8
11
class GridCases :
9
- def structured_small (self ):
12
+ @staticmethod
13
+ def structured_small ():
10
14
nlay , nrow , ncol = 3 , 2 , 3
11
15
delc = 1.0 * np .ones (nrow , dtype = float )
12
16
delr = 1.0 * np .ones (ncol , dtype = float )
@@ -27,7 +31,8 @@ def structured_small(self):
27
31
idomain = idomain ,
28
32
)
29
33
30
- def structured_cbd_small (self ):
34
+ @staticmethod
35
+ def structured_cbd_small ():
31
36
nlay = 3
32
37
nrow = ncol = 15
33
38
laycbd = np .array ([1 , 2 , 0 ], dtype = int )
@@ -61,7 +66,8 @@ def structured_cbd_small(self):
61
66
laycbd = laycbd ,
62
67
)
63
68
64
- def vertex_small (self ):
69
+ @staticmethod
70
+ def vertex_small ():
65
71
nlay , ncpl = 3 , 5
66
72
vertices = [
67
73
[0 , 0.0 , 3.0 ],
@@ -99,7 +105,8 @@ def vertex_small(self):
99
105
idomain = idomain ,
100
106
)
101
107
102
- def unstructured_small (self ):
108
+ @staticmethod
109
+ def unstructured_small ():
103
110
nlay = 3
104
111
ncpl = [5 , 5 , 5 ]
105
112
vertices = [
@@ -167,7 +174,8 @@ def unstructured_small(self):
167
174
idomain = idomain .flatten (),
168
175
)
169
176
170
- def unstructured_medium (self ):
177
+ @staticmethod
178
+ def unstructured_medium ():
171
179
iverts = [
172
180
[4 , 3 , 2 , 1 , 0 , None ],
173
181
[7 , 0 , 1 , 6 , 5 , None ],
@@ -211,7 +219,8 @@ def unstructured_medium(self):
211
219
212
220
return UnstructuredGrid (verts , iverts , ncpl = [len (iverts )])
213
221
214
- def voronoi_polygon (self , function_tmpdir ):
222
+ @staticmethod
223
+ def voronoi_polygon ():
215
224
ncpl = 3803
216
225
domain = [
217
226
[1831.381546 , 6335.543757 ],
@@ -237,18 +246,20 @@ def voronoi_polygon(self, function_tmpdir):
237
246
max_area = 100.0 ** 2
238
247
angle = 30
239
248
240
- tri = Triangle (
241
- maximum_area = max_area , angle = angle , model_ws = str (function_tmpdir )
242
- )
243
- tri .add_polygon (poly )
244
- tri .build (verbose = False )
245
- vor = VoronoiGrid (tri )
246
- gridprops = vor .get_gridprops_vertexgrid ()
247
- grid = VertexGrid (** gridprops , nlay = 1 )
249
+ with TemporaryDirectory () as tempdir :
250
+ tri = Triangle (
251
+ maximum_area = max_area , angle = angle , model_ws = str (Path (tempdir ))
252
+ )
253
+ tri .add_polygon (poly )
254
+ tri .build (verbose = False )
255
+ vor = VoronoiGrid (tri )
256
+ gridprops = vor .get_gridprops_vertexgrid ()
257
+ grid = VertexGrid (** gridprops , nlay = 1 )
248
258
249
259
return ncpl , vor , gridprops , grid
250
260
251
- def voronoi_rectangle (self , function_tmpdir ):
261
+ @staticmethod
262
+ def voronoi_rectangle ():
252
263
ncpl = 1679
253
264
xmin = 0.0
254
265
xmax = 2.0
@@ -260,18 +271,20 @@ def voronoi_rectangle(self, function_tmpdir):
260
271
max_area = 0.001
261
272
angle = 30
262
273
263
- tri = Triangle (
264
- maximum_area = max_area , angle = angle , model_ws = str (function_tmpdir )
265
- )
266
- tri .add_polygon (poly )
267
- tri .build (verbose = False )
268
- vor = VoronoiGrid (tri )
269
- gridprops = vor .get_gridprops_vertexgrid ()
270
- grid = VertexGrid (** gridprops , nlay = 1 )
274
+ with TemporaryDirectory () as tempdir :
275
+ tri = Triangle (
276
+ maximum_area = max_area , angle = angle , model_ws = str (Path (tempdir ))
277
+ )
278
+ tri .add_polygon (poly )
279
+ tri .build (verbose = False )
280
+ vor = VoronoiGrid (tri )
281
+ gridprops = vor .get_gridprops_vertexgrid ()
282
+ grid = VertexGrid (** gridprops , nlay = 1 )
271
283
272
284
return ncpl , vor , gridprops , grid
273
285
274
- def voronoi_circle (self , function_tmpdir ):
286
+ @staticmethod
287
+ def voronoi_circle ():
275
288
ncpl = 538
276
289
theta = np .arange (0.0 , 2 * np .pi , 0.2 )
277
290
radius = 100.0
@@ -281,18 +294,20 @@ def voronoi_circle(self, function_tmpdir):
281
294
max_area = 50
282
295
angle = 30
283
296
284
- tri = Triangle (
285
- maximum_area = max_area , angle = angle , model_ws = str (function_tmpdir )
286
- )
287
- tri .add_polygon (poly )
288
- tri .build (verbose = False )
289
- vor = VoronoiGrid (tri )
290
- gridprops = vor .get_gridprops_vertexgrid ()
291
- grid = VertexGrid (** gridprops , nlay = 1 )
297
+ with TemporaryDirectory () as tempdir :
298
+ tri = Triangle (
299
+ maximum_area = max_area , angle = angle , model_ws = str (Path (tempdir ))
300
+ )
301
+ tri .add_polygon (poly )
302
+ tri .build (verbose = False )
303
+ vor = VoronoiGrid (tri )
304
+ gridprops = vor .get_gridprops_vertexgrid ()
305
+ grid = VertexGrid (** gridprops , nlay = 1 )
292
306
293
307
return ncpl , vor , gridprops , grid
294
308
295
- def voronoi_nested_circles (self , function_tmpdir ):
309
+ @staticmethod
310
+ def voronoi_nested_circles ():
296
311
ncpl = 300
297
312
298
313
theta = np .arange (0.0 , 2 * np .pi , 0.2 )
@@ -311,86 +326,92 @@ def voronoi_nested_circles(self, function_tmpdir):
311
326
max_area = 100
312
327
angle = 30
313
328
314
- tri = Triangle (
315
- maximum_area = max_area , angle = angle , model_ws = str (function_tmpdir )
316
- )
317
- for poly in polys :
318
- tri .add_polygon (poly )
319
- tri .add_hole ((25 , 25 ))
320
- tri .build (verbose = False )
321
- vor = VoronoiGrid (tri )
322
- gridprops = vor .get_gridprops_vertexgrid ()
323
- grid = VertexGrid (** gridprops , nlay = 1 )
329
+ with TemporaryDirectory () as tempdir :
330
+ tri = Triangle (
331
+ maximum_area = max_area , angle = angle , model_ws = str (Path (tempdir ))
332
+ )
333
+ for poly in polys :
334
+ tri .add_polygon (poly )
335
+ tri .add_hole ((25 , 25 ))
336
+ tri .build (verbose = False )
337
+ vor = VoronoiGrid (tri )
338
+ gridprops = vor .get_gridprops_vertexgrid ()
339
+ grid = VertexGrid (** gridprops , nlay = 1 )
324
340
325
341
return ncpl , vor , gridprops , grid
326
342
327
- def voronoi_polygons (self , function_tmpdir ):
343
+ @staticmethod
344
+ def voronoi_polygons ():
328
345
ncpl = 410
329
346
active_domain = [(0 , 0 ), (100 , 0 ), (100 , 100 ), (0 , 100 )]
330
347
area1 = [(10 , 10 ), (40 , 10 ), (40 , 40 ), (10 , 40 )]
331
348
area2 = [(60 , 60 ), (80 , 60 ), (80 , 80 ), (60 , 80 )]
332
- tri = Triangle (angle = 30 , model_ws = str (function_tmpdir ))
333
- tri .add_polygon (active_domain )
334
- tri .add_polygon (area1 )
335
- tri .add_polygon (area2 )
336
- tri .add_region (
337
- (1 , 1 ), 0 , maximum_area = 100
338
- ) # point inside active domain
339
- tri .add_region ((11 , 11 ), 1 , maximum_area = 10 ) # point inside area1
340
- tri .add_region ((61 , 61 ), 2 , maximum_area = 3 ) # point inside area2
341
- tri .build (verbose = False )
342
- vor = VoronoiGrid (tri )
343
- gridprops = vor .get_gridprops_vertexgrid ()
344
- grid = VertexGrid (** gridprops , nlay = 1 )
349
+
350
+ with TemporaryDirectory () as tempdir :
351
+ tri = Triangle (angle = 30 , model_ws = str (Path (tempdir )))
352
+ tri .add_polygon (active_domain )
353
+ tri .add_polygon (area1 )
354
+ tri .add_polygon (area2 )
355
+ tri .add_region (
356
+ (1 , 1 ), 0 , maximum_area = 100
357
+ ) # point inside active domain
358
+ tri .add_region ((11 , 11 ), 1 , maximum_area = 10 ) # point inside area1
359
+ tri .add_region ((61 , 61 ), 2 , maximum_area = 3 ) # point inside area2
360
+ tri .build (verbose = False )
361
+ vor = VoronoiGrid (tri )
362
+ gridprops = vor .get_gridprops_vertexgrid ()
363
+ grid = VertexGrid (** gridprops , nlay = 1 )
345
364
346
365
return ncpl , vor , gridprops , grid
347
366
348
- def voronoi_many_polygons (self , function_tmpdir ):
367
+ @staticmethod
368
+ def voronoi_many_polygons ():
349
369
ncpl = 1305
350
370
active_domain = [(0 , 0 ), (100 , 0 ), (100 , 100 ), (0 , 100 )]
351
371
area1 = [(10 , 10 ), (40 , 10 ), (40 , 40 ), (10 , 40 )]
352
372
area2 = [(70 , 70 ), (90 , 70 ), (90 , 90 ), (70 , 90 )]
353
373
354
- tri = Triangle (angle = 30 , model_ws = str (function_tmpdir ))
355
-
356
- # requirement that active_domain is first polygon to be added
357
- tri .add_polygon (active_domain )
358
-
359
- # requirement that any holes be added next
360
- theta = np .arange (0.0 , 2 * np .pi , 0.2 )
361
- radius = 10.0
362
- x = radius * np .cos (theta ) + 50.0
363
- y = radius * np .sin (theta ) + 70.0
364
- circle_poly0 = [(x , y ) for x , y in zip (x , y )]
365
- tri .add_polygon (circle_poly0 )
366
- tri .add_hole ((50 , 70 ))
367
-
368
- # Add a polygon to force cells to conform to it
369
- theta = np .arange (0.0 , 2 * np .pi , 0.2 )
370
- radius = 10.0
371
- x = radius * np .cos (theta ) + 70.0
372
- y = radius * np .sin (theta ) + 20.0
373
- circle_poly1 = [(x , y ) for x , y in zip (x , y )]
374
- tri .add_polygon (circle_poly1 )
375
- # tri.add_hole((70, 20))
376
-
377
- # add line through domain to force conforming cells
378
- line = [(x , x ) for x in np .linspace (11 , 89 , 100 )]
379
- tri .add_polygon (line )
380
-
381
- # then regions and other polygons should follow
382
- tri .add_polygon (area1 )
383
- tri .add_polygon (area2 )
384
- tri .add_region (
385
- (1 , 1 ), 0 , maximum_area = 100
386
- ) # point inside active domain
387
- tri .add_region ((11 , 11 ), 1 , maximum_area = 10 ) # point inside area1
388
- tri .add_region ((70 , 70 ), 2 , maximum_area = 1 ) # point inside area2
389
-
390
- tri .build (verbose = False )
391
-
392
- vor = VoronoiGrid (tri )
393
- gridprops = vor .get_gridprops_vertexgrid ()
394
- grid = VertexGrid (** gridprops , nlay = 1 )
374
+ with TemporaryDirectory () as tempdir :
375
+ tri = Triangle (angle = 30 , model_ws = str (Path (tempdir )))
376
+
377
+ # requirement that active_domain is first polygon to be added
378
+ tri .add_polygon (active_domain )
379
+
380
+ # requirement that any holes be added next
381
+ theta = np .arange (0.0 , 2 * np .pi , 0.2 )
382
+ radius = 10.0
383
+ x = radius * np .cos (theta ) + 50.0
384
+ y = radius * np .sin (theta ) + 70.0
385
+ circle_poly0 = [(x , y ) for x , y in zip (x , y )]
386
+ tri .add_polygon (circle_poly0 )
387
+ tri .add_hole ((50 , 70 ))
388
+
389
+ # Add a polygon to force cells to conform to it
390
+ theta = np .arange (0.0 , 2 * np .pi , 0.2 )
391
+ radius = 10.0
392
+ x = radius * np .cos (theta ) + 70.0
393
+ y = radius * np .sin (theta ) + 20.0
394
+ circle_poly1 = [(x , y ) for x , y in zip (x , y )]
395
+ tri .add_polygon (circle_poly1 )
396
+ # tri.add_hole((70, 20))
397
+
398
+ # add line through domain to force conforming cells
399
+ line = [(x , x ) for x in np .linspace (11 , 89 , 100 )]
400
+ tri .add_polygon (line )
401
+
402
+ # then regions and other polygons should follow
403
+ tri .add_polygon (area1 )
404
+ tri .add_polygon (area2 )
405
+ tri .add_region (
406
+ (1 , 1 ), 0 , maximum_area = 100
407
+ ) # point inside active domain
408
+ tri .add_region ((11 , 11 ), 1 , maximum_area = 10 ) # point inside area1
409
+ tri .add_region ((70 , 70 ), 2 , maximum_area = 1 ) # point inside area2
410
+
411
+ tri .build (verbose = False )
412
+
413
+ vor = VoronoiGrid (tri )
414
+ gridprops = vor .get_gridprops_vertexgrid ()
415
+ grid = VertexGrid (** gridprops , nlay = 1 )
395
416
396
417
return ncpl , vor , gridprops , grid
0 commit comments