example.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env python3
  2. # This is an example script how groundwater flow and solute transport are
  3. # computed within GRASS GIS
  4. import grass.script as gs
  5. # Overwrite existing maps
  6. gs.run_command("g.gisenv", set="OVERWRITE=1")
  7. gs.message("Set the region")
  8. # The area is 200m x 100m with a cell size of 1m x 1m
  9. gs.run_command("g.region", res=1, res3=1, t=10, b=0, n=100, s=0, w=0, e=200)
  10. gs.run_command("r.mapcalc", expression="phead=if(col() == 1 , 50, 40)")
  11. gs.run_command("r.mapcalc", expression="phead=if(col() ==200 , 45 + row()/40, phead)")
  12. gs.run_command("r.mapcalc", expression="status=if(col() == 1 || col() == 200 , 2, 1)")
  13. gs.run_command(
  14. "r.mapcalc",
  15. expression="well=if((row() == 50 && col() == 175) || (row() == 10 && col() == 135) , -0.001, 0)", # noqa: E501
  16. )
  17. gs.run_command("r.mapcalc", expression="hydcond=0.00005")
  18. gs.run_command("r.mapcalc", expression="recharge=0")
  19. gs.run_command("r.mapcalc", expression="top_conf=20")
  20. gs.run_command("r.mapcalc", expression="bottom=0")
  21. gs.run_command("r.mapcalc", expression="poros=0.17")
  22. gs.run_command("r.mapcalc", expression="syield=0.0001")
  23. gs.run_command("r.mapcalc", expression="null=0.0")
  24. #
  25. gs.message(_("Compute a steady state groundwater flow"))
  26. gs.run_command(
  27. "r.gwflow",
  28. solver="cg",
  29. top="top_conf",
  30. bottom="bottom",
  31. phead="phead",
  32. status="status",
  33. hc_x="hydcond",
  34. hc_y="hydcond",
  35. q="well",
  36. s="syield",
  37. recharge="recharge",
  38. output="gwresult_conf",
  39. dt=8640000000000,
  40. type="confined",
  41. )
  42. gs.message(_("generate the transport data"))
  43. gs.run_command("r.mapcalc", expression="c=if(col() == 15 && row() == 75 , 500.0, 0.0)")
  44. gs.run_command("r.mapcalc", expression="cs=if(col() == 15 && row() == 75 , 0.0, 0.0)")
  45. gs.run_command("r.mapcalc", expression="tstatus=if(col() == 1 || col() == 200 , 3, 1)")
  46. gs.run_command("r.mapcalc", expression="diff=0.0000001")
  47. gs.run_command("r.mapcalc", expression="R=1.0")
  48. # Compute the initial state
  49. gs.run_command(
  50. "r.solute.transport",
  51. solver="bicgstab",
  52. top="top_conf",
  53. bottom="bottom",
  54. phead="gwresult_conf",
  55. status="tstatus",
  56. hc_x="hydcond",
  57. hc_y="hydcond",
  58. rd="R",
  59. cs="cs",
  60. q="well",
  61. nf="poros",
  62. output="stresult_conf_0",
  63. dt=3600,
  64. diff_x="diff",
  65. diff_y="diff",
  66. c="c",
  67. al=0.1,
  68. at=0.01,
  69. )
  70. # Compute the solute transport for 300 days in 10 day steps
  71. for dt in range(30):
  72. gs.run_command(
  73. "r.solute.transport",
  74. solver="bicgstab",
  75. top="top_conf",
  76. bottom="bottom",
  77. phead="gwresult_conf",
  78. status="tstatus",
  79. hc_x="hydcond",
  80. hc_y="hydcond",
  81. rd="R",
  82. cs="cs",
  83. q="well",
  84. nf="poros",
  85. output="stresult_conf_" + str(dt + 1),
  86. dt=864000,
  87. diff_x="diff",
  88. diff_y="diff",
  89. c="stresult_conf_" + str(dt),
  90. al=0.1,
  91. at=0.01,
  92. vx="vx",
  93. vy="vy",
  94. )