validation_7x7_grid.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """Test to verify r.gwflow calculation, this calculation is based on
  2. the example at page 133 of the following book:
  3. author = "Kinzelbach, W. and Rausch, R.",
  4. title = "Grundwassermodellierung",
  5. publisher = "Gebr{\"u}der Borntraeger (Berlin, Stuttgart)",
  6. year = "1995"
  7. @author Soeren Gebbert
  8. """
  9. from grass.gunittest.case import TestCase
  10. class Validation7x7Grid(TestCase):
  11. @classmethod
  12. def setUpClass(cls):
  13. """Use temporary region settings"""
  14. cls.use_temp_region()
  15. cls.runModule("g.region", res=100, n=700, s=0, w=0, e=700)
  16. @classmethod
  17. def tearDownClass(cls):
  18. """!Remove the temporary region
  19. """
  20. cls.del_temp_region()
  21. def setUp(self):
  22. """Create input data for transient groundwater flow computation
  23. """
  24. self.runModule("r.mapcalc", expression="phead=50")
  25. self.runModule("r.mapcalc", expression="status=if(col() == 1 || col() == 7 , 2, 1)")
  26. self.runModule("r.mapcalc", expression="well=if((row() == 4 && col() == 4), -0.1, 0)")
  27. self.runModule("r.mapcalc", expression="hydcond=0.0005")
  28. self.runModule("r.mapcalc", expression="recharge=0")
  29. self.runModule("r.mapcalc", expression="top_conf=20")
  30. self.runModule("r.mapcalc", expression="bottom=0")
  31. self.runModule("r.mapcalc", expression="s=0.0001")
  32. self.runModule("r.mapcalc", expression="null=0.0")
  33. def test_transient(self):
  34. #First compute the groundwater flow after 500 seconds to have initial conditions
  35. self.assertModule("r.gwflow", flags="f", solver="cholesky", top="top_conf", bottom="bottom", phead="phead",\
  36. status="status", hc_x="hydcond", hc_y="hydcond", q="well", s="s",\
  37. recharge="recharge", output="gwresult_conf", dtime=500, type="confined", budget="water_budget", overwrite=True)
  38. # loop over the timesteps each 500 seconds
  39. for i in range(20):
  40. self.assertModule("r.gwflow", flags="f", solver="cholesky", top="top_conf", bottom="bottom", phead="gwresult_conf",\
  41. status="status", hc_x="hydcond", hc_y="hydcond", q="well", s="s",\
  42. recharge="recharge", output="gwresult_conf", dtime=500, type="confined", budget="water_budget", overwrite=True)
  43. # Output of r.univar
  44. univar_string="""n=49
  45. null_cells=0
  46. cells=49
  47. min=45.1219899394172
  48. max=50
  49. range=4.8780100605828
  50. mean=49.081632669812
  51. mean_of_abs=49.081632669812
  52. stddev=0.908558909200636
  53. variance=0.825479291487849
  54. coeff_var=1.85111794326975
  55. sum=2405.00000082079"""
  56. # Output of r.info, only a subset of the output is needed
  57. info_string="""north=700
  58. south=0
  59. east=700
  60. west=0
  61. nsres=100
  62. ewres=100
  63. rows=7
  64. cols=7
  65. cells=49
  66. datatype=DCELL
  67. ncats=0
  68. min=45.1219899394172
  69. max=50
  70. map=gwresult_conf"""
  71. self.assertRasterFitsUnivar(raster="gwresult_conf", reference=univar_string, precision=3)
  72. self.assertRasterFitsInfo(raster="gwresult_conf", reference=info_string, precision=3)
  73. if __name__ == '__main__':
  74. from grass.gunittest.main import test
  75. test()