Guest User

Untitled

a guest
Oct 8th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | None | 0 0
  1. import flopy
  2. import numpy as np
  3.  
  4. modelname = 'test'
  5. mf = flopy.modflow.Modflow(modelname = modelname, exe_name = 'mf2005')
  6.  
  7. q = 50
  8. Lx = 500
  9. Ly = 500
  10. ncol = 50
  11. nrow = 50
  12. nlay = 1
  13. ztop = 0.0
  14. zbot = -50
  15. botm = np.linspace(ztop, zbot, nlay + 1)
  16. delr = Ly / nrow
  17. delc = Lx / ncol
  18. dis = flopy.modflow.ModflowDis(mf,
  19.                                nlay = nlay,
  20.                                nrow = nrow,
  21.                                ncol = ncol,
  22.                                delc = delc,
  23.                                delr = delr,
  24.                                ztop = ztop,
  25.                                botm = botm[1:])
  26.  
  27. ibound = np.ones((nlay, nrow, ncol))
  28. ibound[:,0,:] = 0
  29. ibound[:,-1,:] = 0
  30. ibound[:, :, 0] = -1
  31.  
  32. strt = 10 * np.ones((nlay, nrow, ncol))
  33. strt[:, :, 0] = 0.0
  34. strt[:, :, -1] = 10.0
  35. bas = flopy.modflow.ModflowBas(mf, ibound = ibound, strt=strt)
  36.  
  37. lpf = flopy.modflow.ModflowLpf(mf,
  38.                                hk = 50,
  39.                                vka = 1,
  40.                                sy = 0.1,
  41.                                ss = 1.0e-4,
  42.                                laytyp = 1)
  43.  
  44. spd = []
  45. for il in range(nlay):
  46.     for ir in range(nrow):
  47.         spd.append([il, ir, 0, 0, q])
  48.  
  49. fhb = flopy.modflow.ModflowFhb(mf, ds5 = spd)
  50.  
  51. pcg = flopy.modflow.ModflowPcg(mf)
  52.  
  53. spd2 = {(0, 0): ["print head", "print budget", "save head", "save budget"]}
  54. oc = flopy.modflow.ModflowOc(mf, stress_period_data=spd2, compact=True)
  55.  
  56. # Write the model input files
  57. mf.write_input()
  58.  
  59. # Run the model
  60. success, mfoutput = mf.run_model()
  61. if not success:
  62.     raise Exception("MODFLOW did not terminate normally.")
  63.  
  64. # Imports
  65. import matplotlib.pyplot as plt
  66. import flopy.utils.binaryfile as bf
  67.  
  68.  
  69. hds = bf.HeadFile(modelname + ".hds")
  70. head = hds.get_data(totim=1.0)
  71.  
  72. extent = (delr / 2.0, Lx - delr / 2.0, Ly - delc / 2.0, delc / 2.0)
  73. fig = plt.figure(figsize=(6, 6))
  74. ax = fig.add_subplot(1, 1, 1, aspect="equal")
  75. ax.contour(head[0, :, :], levels=np.arange(1, 10, 1), extent=extent)
  76.  
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment