@@ -416,3 +416,114 @@ def test_write_ascii(function_tmpdir):
416416 assert f"{ gwf_name } .oc" in file_names
417417 assert f"{ gwf_name } .npf" in file_names
418418 assert f"{ gwf_name } .chd" in file_names
419+
420+
421+ def test_to_dict_fields ():
422+ time = ModelTime (perlen = [1.0 ], nstp = [1 ], tsmult = [1.0 ])
423+ grid = StructuredGrid (nlay = 1 , nrow = 10 , ncol = 10 )
424+ dims = {
425+ "nlay" : grid .nlay ,
426+ "nrow" : grid .nrow ,
427+ "ncol" : grid .ncol ,
428+ "nper" : time .nper ,
429+ "nodes" : grid .nnodes ,
430+ }
431+
432+ chd = Chd (dims = dims , head = {0 : {(0 , 0 , 0 ): 1.0 , (0 , 9 , 9 ): 0.0 }})
433+ result = chd .to_dict ()
434+
435+ assert "head" in result
436+ assert result ["head" ][0 , 0 ] == 1.0
437+ assert result ["head" ][0 , 99 ] == 0.0
438+
439+ npf = Npf (dims = dims , k = 5.0 )
440+ result = npf .to_dict ()
441+
442+ assert "filename" not in result
443+ assert "k" in result
444+ assert "icelltype" in result
445+ assert "k33" in result
446+ assert np .array_equal (result ["k" ], np .full (100 , 5.0 ))
447+
448+
449+ def test_to_dict_blocks ():
450+ time = ModelTime (perlen = [1.0 ], nstp = [1 ], tsmult = [1.0 ])
451+ grid = StructuredGrid (nlay = 1 , nrow = 10 , ncol = 10 )
452+ dims = {
453+ "nlay" : grid .nlay ,
454+ "nrow" : grid .nrow ,
455+ "ncol" : grid .ncol ,
456+ "nper" : time .nper ,
457+ "nodes" : grid .nnodes ,
458+ }
459+
460+ chd = Chd (
461+ dims = dims ,
462+ print_flows = True ,
463+ head = {0 : {(0 , 0 , 0 ): 1.0 , (0 , 9 , 9 ): 0.0 }},
464+ )
465+ result = chd .to_dict (blocks = True )
466+
467+ assert "options" in result
468+ assert "period" in result
469+ assert "print_flows" in result ["options" ]
470+ assert result ["options" ]["print_flows" ] is True
471+ assert "head" in result ["period" ]
472+ assert result ["period" ]["head" ][0 , 0 ] == 1.0
473+ assert result ["period" ]["head" ][0 , 99 ] == 0.0
474+
475+ npf = Npf (dims = dims , save_flows = True , k = 2.0 )
476+ result = npf .to_dict (blocks = True )
477+
478+ assert "options" in result
479+ assert "griddata" in result
480+ assert "save_flows" in result ["options" ]
481+ assert result ["options" ]["save_flows" ] is True
482+ assert "k" in result ["griddata" ]
483+ assert np .array_equal (result ["griddata" ]["k" ], np .full (100 , 2.0 ))
484+
485+
486+ def test_to_dict_on_component ():
487+ dims = {
488+ "nper" : 1 ,
489+ "nlay" : 1 ,
490+ "nrow" : 2 ,
491+ "ncol" : 2 ,
492+ "nodes" : 4 ,
493+ }
494+ dis = Dis (dims = dims )
495+ result = dis .to_dict ()
496+
497+ assert "filename" not in result
498+ assert "nlay" in result
499+
500+
501+ def test_to_dict_on_context ():
502+ time = ModelTime (perlen = [1.0 ], nstp = [1 ], tsmult = [1.0 ])
503+ ims = Ims (models = ["gwf" ])
504+ sim = Simulation (tdis = time , solutions = {"ims" : ims })
505+
506+ result = sim .to_dict ()
507+
508+ assert "filename" not in result
509+ assert "workspace" not in result
510+ assert "tdis" in result
511+
512+
513+ def test_to_dict_excludes_derived_dims ():
514+ # TODO eventually revise to test exclusion of all derived dimensions,
515+ # once we have a mechanism to mark them as such
516+ dims = {
517+ "nper" : 1 ,
518+ "nlay" : 1 ,
519+ "nrow" : 2 ,
520+ "ncol" : 2 ,
521+ "nodes" : 4 ,
522+ }
523+ dis = Dis (dims = dims )
524+ result = dis .to_dict ()
525+
526+ assert "nlay" in result
527+ assert "nrow" in result
528+ assert "ncol" in result
529+ assert "nodes" not in result
0 commit comments