23
23
from imod .mf6 .write_context import WriteContext
24
24
from imod .schemata import ValidationError
25
25
from imod .tests .fixtures .flow_basic_fixture import BasicDisSettings
26
+ from imod .typing .grid import ones_like
26
27
27
28
times = [
28
29
datetime (1981 , 11 , 30 ),
34
35
]
35
36
36
37
38
+ class BasicGridCases :
39
+ @staticmethod
40
+ def case_structured (basic_dis ):
41
+ idomain , top , bottom = basic_dis
42
+ return (
43
+ imod .mf6 .StructuredDiscretization ,
44
+ idomain ,
45
+ top ,
46
+ bottom ,
47
+ )
48
+
49
+ @staticmethod
50
+ def case_unstructured (basic_unstructured_dis ):
51
+ idomain , top , bottom = basic_unstructured_dis
52
+ return imod .mf6 .VerticesDiscretization , idomain , top , bottom
53
+
54
+
37
55
class GridAgnosticWellCases :
38
56
def case_well_stationary (self , well_high_lvl_test_data_stationary ):
39
57
obj = imod .mf6 .Well (* well_high_lvl_test_data_stationary )
@@ -330,21 +348,22 @@ def test_to_mf6_pkg__validate_filter_top(well_high_lvl_test_data_stationary):
330
348
)
331
349
332
350
351
+ @parametrize_with_cases ("dis" , cases = BasicGridCases )
333
352
def test_to_mf6_pkg__logging_with_message (
334
- tmp_path , basic_dis , well_high_lvl_test_data_transient
353
+ tmp_path , dis , well_high_lvl_test_data_transient
335
354
):
336
355
# Arrange
337
356
logfile_path = tmp_path / "logfile.txt"
338
- idomain , top , bottom = basic_dis
357
+ _ , idomain , top , bottom = dis
339
358
modified_well_fixture = list (well_high_lvl_test_data_transient )
340
359
341
360
# create an idomain where layer 1 is active and layer 2 and 3 are inactive.
342
361
# layer 1 has a bottom at -5, layer 2 at -35 and layer 3 at -135
343
362
# so only wells that have a filter top above -5 will end up in the simulation
344
363
active = idomain == 1
345
364
346
- active .loc [1 , :, : ] = True
347
- active .loc [2 :, :, : ] = False
365
+ active .loc [1 , ... ] = True
366
+ active .loc [2 :, ... ] = False
348
367
349
368
# modify the well filter top and filter bottoms so that
350
369
# well 0 is not placed
@@ -393,7 +412,7 @@ def test_to_mf6_pkg__logging_with_message(
393
412
394
413
wel = imod .mf6 .Well (* modified_well_fixture )
395
414
396
- k = xr . ones_like (idomain )
415
+ k = ones_like (idomain )
397
416
_ = wel .to_mf6_pkg (active , top , bottom , k )
398
417
399
418
# the wells that were fully or partially placed should not appear in the log message
@@ -415,15 +434,16 @@ def test_to_mf6_pkg__logging_with_message(
415
434
assert "id = 11 x" in log
416
435
417
436
437
+ @parametrize_with_cases ("dis" , cases = BasicGridCases )
418
438
def test_to_mf6_pkg__logging_without_message (
419
- tmp_path , basic_dis , well_high_lvl_test_data_transient
439
+ tmp_path , dis , well_high_lvl_test_data_transient
420
440
):
421
441
# This test activates logging, and then converts a high level well package to
422
442
# an MF6 package, in such a way that all the wells can be placed.
423
443
# Logging is active, and the log file should not include the "Some wells were not placed"
424
444
# message
425
445
logfile_path = tmp_path / "logfile.txt"
426
- idomain , top , bottom = basic_dis
446
+ _ , idomain , top , bottom = dis
427
447
428
448
with open (logfile_path , "w" ) as sys .stdout :
429
449
imod .logging .configure (
@@ -435,10 +455,10 @@ def test_to_mf6_pkg__logging_without_message(
435
455
436
456
wel = imod .mf6 .Well (* well_high_lvl_test_data_transient )
437
457
active = idomain == 1
438
- k = xr . ones_like (idomain )
458
+ k = ones_like (idomain )
439
459
440
- active .loc [1 , :, : ] = True
441
- active .loc [2 :, :, : ] = True
460
+ active .loc [1 , ... ] = True
461
+ active .loc [2 :, ... ] = True
442
462
443
463
# Act
444
464
_ = wel .to_mf6_pkg (active , top , bottom , k )
@@ -448,32 +468,36 @@ def test_to_mf6_pkg__logging_without_message(
448
468
assert "Some wells were not placed" not in log
449
469
450
470
451
- def test_to_mf6_pkg__error_on_all_wells_removed (
452
- basic_dis , well_high_lvl_test_data_transient
453
- ):
471
+ @parametrize_with_cases ("dis" , cases = BasicGridCases )
472
+ def test_to_mf6_pkg__error_on_all_wells_removed (dis , well_high_lvl_test_data_transient ):
454
473
"""Drop all wells, then run to_mf6_pkg"""
455
- idomain , top , bottom = basic_dis
474
+ _ , idomain , top , bottom = dis
456
475
457
476
wel = imod .mf6 .Well (* well_high_lvl_test_data_transient )
458
477
wel .dataset = wel .dataset .drop_sel (index = wel .dataset ["index" ])
459
478
active = idomain == 1
460
- k = xr . ones_like (idomain )
479
+ k = ones_like (idomain )
461
480
462
481
with pytest .raises (ValidationError , match = "No wells were assigned in package" ):
463
482
wel .to_mf6_pkg (active , top , bottom , k )
464
483
465
484
466
- def test_to_mf6_pkg__error_on_well_removal (
467
- basic_dis , well_high_lvl_test_data_transient
468
- ):
485
+ @parametrize_with_cases ("dis" , cases = BasicGridCases )
486
+ def test_to_mf6_pkg__error_on_well_removal (dis , well_high_lvl_test_data_transient ):
469
487
"""Set k values at well location x=81 to 1e-3, causing it to be dropped.
470
488
Should throw error if error_on_well_removal = True"""
471
- idomain , top , bottom = basic_dis
489
+ dis_pkg_type , idomain , top , bottom = dis
472
490
473
491
wel = imod .mf6 .Well (minimum_k = 0.9 , * well_high_lvl_test_data_transient )
474
492
active = idomain == 1
475
- k = xr .ones_like (idomain )
476
- k .loc [{"x" : 85.0 }] = 1e-3
493
+ k = ones_like (idomain ).astype (float )
494
+ # Set k values at well location x=81 to 1e-3, causing it to be dropped.
495
+ if dis_pkg_type is imod .mf6 .VerticesDiscretization :
496
+ dim = k .ugrid .grid .face_dimension
497
+ indices = k .sel (layer = 1 ).ugrid .sel (x = 85.0 ).coords [dim ].data
498
+ k .loc [{dim : indices }] = 1e-3
499
+ else :
500
+ k .loc [{"x" : 85.0 }] = 1e-3
477
501
478
502
with pytest .raises (ValidationError , match = "x = 81" ):
479
503
wel .to_mf6_pkg (active , top , bottom , k , strict_well_validation = True )
@@ -521,17 +545,18 @@ def test_is_empty(well_high_lvl_test_data_transient):
521
545
assert wel_empty .is_empty ()
522
546
523
547
524
- def test_cleanup (basic_dis , well_high_lvl_test_data_transient ):
548
+ @parametrize_with_cases ("dis" , cases = BasicGridCases )
549
+ def test_cleanup (dis , well_high_lvl_test_data_transient ):
525
550
# Arrange
526
551
wel = imod .mf6 .Well (* well_high_lvl_test_data_transient )
527
552
ds_original = wel .dataset .copy ()
528
- idomain , top , bottom = basic_dis
529
- top = top .isel (layer = 0 , drop = True )
553
+
554
+ dis_pkg_type , idomain , top , bottom = dis
555
+ if "layer" in top .dims :
556
+ top = top .isel (layer = 0 , drop = True )
530
557
deep_offset = 100.0
531
- dis_normal = imod .mf6 .StructuredDiscretization (top , bottom , idomain )
532
- dis_deep = imod .mf6 .StructuredDiscretization (
533
- top - deep_offset , bottom - deep_offset , idomain
534
- )
558
+ dis_normal = dis_pkg_type (top , bottom , idomain )
559
+ dis_deep = dis_pkg_type (top - deep_offset , bottom - deep_offset , idomain )
535
560
536
561
# Nothing to be cleaned up with default discretization
537
562
wel .cleanup (dis_normal )
0 commit comments