example.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # This is an example script how groundwater flow and solute transport are
  3. # computed within grass
  4. import sys
  5. import os
  6. import grass.script as grass
  7. # Overwrite existing maps
  8. grass.run_command("g.gisenv", set="OVERWRITE=1")
  9. grass.message("Set the region")
  10. # The area is 200m x 100m with a cell size of 1m x 1m
  11. grass.run_command("g.region", res=1, res3=1, t=10, b=0, n=100, s=0, w=0, e=200)
  12. grass.run_command("r.mapcalc", expression="phead=if(col() == 1 , 50, 40)")
  13. grass.run_command("r.mapcalc", expression="phead=if(col() ==200 , 45 + row()/40, phead)")
  14. grass.run_command("r.mapcalc", expression="status=if(col() == 1 || col() == 200 , 2, 1)")
  15. grass.run_command("r.mapcalc", expression="well=if((row() == 50 && col() == 175) || (row() == 10 && col() == 135) , -0.001, 0)")
  16. grass.run_command("r.mapcalc", expression="hydcond=0.00005")
  17. grass.run_command("r.mapcalc", expression="recharge=0")
  18. grass.run_command("r.mapcalc", expression="top_conf=20")
  19. grass.run_command("r.mapcalc", expression="bottom=0")
  20. grass.run_command("r.mapcalc", expression="poros=0.17")
  21. grass.run_command("r.mapcalc", expression="syield=0.0001")
  22. grass.run_command("r.mapcalc", expression="null=0.0")
  23. #
  24. grass.message(_("Compute a steady state groundwater flow"))
  25. grass.run_command("r.gwflow", solver="cg", top="top_conf", bottom="bottom", phead="phead",\
  26. status="status", hc_x="hydcond", hc_y="hydcond", q="well", s="syield",\
  27. recharge="recharge", output="gwresult_conf", dt=8640000000000, type="confined")
  28. grass.message(_("generate the transport data"))
  29. grass.run_command("r.mapcalc", expression="c=if(col() == 15 && row() == 75 , 500.0, 0.0)")
  30. grass.run_command("r.mapcalc", expression="cs=if(col() == 15 && row() == 75 , 0.0, 0.0)")
  31. grass.run_command("r.mapcalc", expression="tstatus=if(col() == 1 || col() == 200 , 3, 1)")
  32. grass.run_command("r.mapcalc", expression="diff=0.0000001")
  33. grass.run_command("r.mapcalc", expression="R=1.0")
  34. # Compute the initial state
  35. grass.run_command("r.solute.transport", solver="bicgstab", top="top_conf",\
  36. bottom="bottom", phead="gwresult_conf", status="tstatus", hc_x="hydcond", hc_y="hydcond",\
  37. rd="R", cs="cs", q="well", nf="poros", output="stresult_conf_0", dt=3600, diff_x="diff",\
  38. diff_y="diff", c="c", al=0.1, at=0.01)
  39. # Compute the solute transport for 300 days in 10 day steps
  40. for dt in range(30):
  41. grass.run_command("r.solute.transport", solver="bicgstab", top="top_conf",\
  42. bottom="bottom", phead="gwresult_conf", status="tstatus", hc_x="hydcond", hc_y="hydcond",\
  43. rd="R", cs="cs", q="well", nf="poros", output="stresult_conf_" + str(dt + 1), dt=864000, diff_x="diff",\
  44. diff_y="diff", c="stresult_conf_" + str(dt), al=0.1, at=0.01, vx="vx", vy="vy")