def test_vtk_vector(): from flopy.utils import postprocessing as pp # test mf 2005 freyberg mpth = os.path.join('..', 'examples', 'data', 'freyberg_multilayer_transient') namfile = 'freyberg.nam' cbcfile = os.path.join(mpth, 'freyberg.cbc') hdsfile = os.path.join(mpth, 'freyberg.hds') m = flopy.modflow.Modflow.load(namfile, model_ws=mpth, verbose=False, load_only=['dis', 'bas6', 'upw']) q = pp.get_specific_discharge(m, cbcfile=cbcfile) output_dir = os.path.join(cpth, 'freyberg_vector') filenametocheck = 'discharge.vtu' # export and check with point scalar vtk.export_vector(m, q, output_dir, 'discharge', point_scalars=True) filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==2247857) nlines = count_lines_in_file(filetocheck) assert(nlines==10605) # with point scalars and binary vtk.export_vector(m, q, output_dir + '_bin', 'discharge', point_scalars=True, binary=True) filetocheck = os.path.join(output_dir + '_bin', filenametocheck) # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==942413) # nlines1 = count_lines_in_file(filetocheck, binary=True) # assert(nlines1==3824) assert(os.path.exists(filetocheck)) # with values directly given at vertices q = pp.get_specific_discharge(m, cbcfile=cbcfile, hdsfile=hdsfile, position='vertices') nancount = np.count_nonzero(np.isnan(q[0])) assert(nancount==308) overall = np.nansum(q[0]) + np.nansum(q[1]) + np.nansum(q[2]) assert np.allclose(overall, -15.467904755216372) output_dir = os.path.join(cpth, 'freyberg_vector') filenametocheck = 'discharge_verts.vtu' vtk.export_vector(m, q, output_dir, 'discharge_verts') filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==1990047) nlines2 = count_lines_in_file(filetocheck) assert(nlines2==10598) # with values directly given at vertices and binary vtk.export_vector(m, q, output_dir + '_bin', 'discharge_verts', binary=True) filetocheck = os.path.join(output_dir + '_bin', filenametocheck) # totalbytes3 = os.path.getsize(filetocheck) # assert(totalbytes3==891486) # nlines3 = count_lines_in_file(filetocheck, binary=True) # assert(nlines3==3012) assert(os.path.exists(filetocheck)) return
def test_vtk_export_true2d_nonregxy(): import flopy.utils.binaryfile as bf from flopy.utils import postprocessing as pp output_dir = os.path.join(cpth, 'true2d_nonregxy') cbc_unit_nb = 53 # model with one layer, non-regular grid in x and y name = 'nonregxy' m = flopy.modflow.Modflow(name, model_ws=output_dir, exe_name='mf2005') nlay, nrow, ncol = 1, 10, 10 delr = np.concatenate((np.ones((5,)), 2.*np.ones((5,)))) delc = delr top = 50. botm = 0. dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol, delr=delr, delc=delc, top=top, botm=botm) ibound = np.ones((nlay, nrow, ncol), dtype=np.int32) ibound[:, :, 0] = -1 ibound[:, :, -1] = -1 strt = np.linspace(1., 0., ncol).reshape(1, 1, ncol) strt = strt * np.ones((nlay, nrow, ncol)) bas = flopy.modflow.ModflowBas(m, ibound=ibound, strt=strt) lpf = flopy.modflow.ModflowLpf(m, hk=1., vka=1., ipakcb=cbc_unit_nb) spd = {(0, 0): ['print head', 'print budget', 'save head', 'save budget']} oc = flopy.modflow.ModflowOc(m, stress_period_data=spd, compact=True) pcg = flopy.modflow.ModflowPcg(m) m.write_input() m.run_model(silent=True) # export and check head with point scalar hdsfile = os.path.join(output_dir, name + '.hds') hds = bf.HeadFile(hdsfile) head = hds.get_data() vtk.export_array(m, head, output_dir, name + '_head', point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + '_head.vtr') # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==4997) nlines = count_lines_in_file(filetocheck) assert(nlines==59) # export and check specific discharge given at vertices cbcfile = os.path.join(output_dir, name + '.cbc') q = pp.get_specific_discharge(m, cbcfile, position='vertices') vtk.export_vector(m, q, output_dir, name + '_q', point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + '_q.vtr') # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==5772) nlines1 = count_lines_in_file(filetocheck) assert(nlines1==54) return
def test_vtk_export_true2d_nonregxy(): import flopy.utils.binaryfile as bf from flopy.utils import postprocessing as pp output_dir = os.path.join(cpth, "true2d_nonregxy") cbc_unit_nb = 53 # model with one layer, non-regular grid in x and y name = "nonregxy" m = flopy.modflow.Modflow(name, model_ws=output_dir, exe_name="mf2005") nlay, nrow, ncol = 1, 10, 10 delr = np.concatenate((np.ones((5, )), 2.0 * np.ones((5, )))) delc = delr top = 50.0 botm = 0.0 dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol, delr=delr, delc=delc, top=top, botm=botm) ibound = np.ones((nlay, nrow, ncol), dtype=np.int32) ibound[:, :, 0] = -1 ibound[:, :, -1] = -1 strt = np.linspace(1.0, 0.0, ncol).reshape(1, 1, ncol) strt = strt * np.ones((nlay, nrow, ncol)) bas = flopy.modflow.ModflowBas(m, ibound=ibound, strt=strt) lpf = flopy.modflow.ModflowLpf(m, hk=1.0, vka=1.0, ipakcb=cbc_unit_nb) spd = {(0, 0): ["print head", "print budget", "save head", "save budget"]} oc = flopy.modflow.ModflowOc(m, stress_period_data=spd, compact=True) pcg = flopy.modflow.ModflowPcg(m) m.write_input() m.run_model(silent=True) # export and check head with point scalar hdsfile = os.path.join(output_dir, name + ".hds") hds = bf.HeadFile(hdsfile) head = hds.get_data() vtk.export_array(m, head, output_dir, name + "_head", point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + "_head.vtr") # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==4997) nlines = count_lines_in_file(filetocheck) assert nlines == 59 # export and check specific discharge given at vertices cbcfile = os.path.join(output_dir, name + ".cbc") cbc = bf.CellBudgetFile(cbcfile) keys = ["FLOW RIGHT FACE", "FLOW FRONT FACE"] vectors = [cbc.get_data(text=t)[0] for t in keys] q = pp.get_specific_discharge(vectors, m, position="vertices") vtk.export_vector(m, q, output_dir, name + "_q", point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + "_q.vtr") # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==5772) nlines1 = count_lines_in_file(filetocheck) assert nlines1 == 54 return
def test_vtk_export_true2d_nonregyz(): import flopy.utils.binaryfile as bf from flopy.utils import postprocessing as pp output_dir = os.path.join(cpth, "true2d_nonregyz") cbc_unit_nb = 53 # model with one col, non-regular grid in y and stepwise z name = "nonregyz" m = flopy.modflow.Modflow(name, model_ws=output_dir, exe_name="mf2005") nlay, nrow, ncol = 2, 10, 1 delr = 1.0 delc = np.concatenate((2.0 * np.ones((5, )), np.ones((5, )))) top = np.linspace(3.0, 2.0, nrow).reshape((1, nrow, 1)) botm1 = np.linspace(2.5, 1.0, nrow).reshape((1, nrow, 1)) botm2 = np.linspace(0.5, 0.0, nrow).reshape((1, nrow, 1)) botm = np.concatenate((botm1, botm2)) dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol, delr=delr, delc=delc, top=top, botm=botm) ibound = np.ones((nlay, nrow, ncol), dtype=np.int32) ibound[:, 0, :] = -1 ibound[:, -1, :] = -1 strt = np.linspace(1.0, 0.0, nrow).reshape(1, nrow, 1) strt = strt * np.ones((nlay, nrow, ncol)) bas = flopy.modflow.ModflowBas(m, ibound=ibound, strt=strt) lpf = flopy.modflow.ModflowLpf(m, hk=1.0, vka=1.0, ipakcb=cbc_unit_nb) spd = {(0, 0): ["print head", "print budget", "save head", "save budget"]} oc = flopy.modflow.ModflowOc(m, stress_period_data=spd, compact=True) pcg = flopy.modflow.ModflowPcg(m) m.write_input() m.run_model(silent=True) # export and check head hdsfile = os.path.join(output_dir, name + ".hds") hds = bf.HeadFile(hdsfile) head = hds.get_data() vtk.export_array(m, head, output_dir, name + "_head", true2d=True) filetocheck = os.path.join(output_dir, name + "_head.vtu") # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==4217) nlines = count_lines_in_file(filetocheck) assert nlines == 105 # export and check head with point scalar hdsfile = os.path.join(output_dir, name + ".hds") hds = bf.HeadFile(hdsfile) head = hds.get_data() vtk.export_array( m, head, output_dir, name + "_head_points", point_scalars=True, true2d=True, ) filetocheck = os.path.join(output_dir, name + "_head_points.vtu") # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==6155) nlines1 = count_lines_in_file(filetocheck) assert nlines1 == 129 # export and check specific discharge given at vertices cbcfile = os.path.join(output_dir, name + ".cbc") cbc = bf.CellBudgetFile(cbcfile) keys = ["FLOW FRONT FACE", "FLOW LOWER FACE"] vectors = [cbc.get_data(text=t)[0] for t in keys] vectors.insert(0, None) q = pp.get_specific_discharge(vectors, m, position="vertices") vtk.export_vector(m, q, output_dir, name + "_q", point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + "_q.vtu") # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==7032) nlines2 = count_lines_in_file(filetocheck) assert nlines2 == 123 return
def test_vtk_vector(): from flopy.utils import postprocessing as pp from flopy.utils import HeadFile, CellBudgetFile # test mf 2005 freyberg mpth = os.path.join("..", "examples", "data", "freyberg_multilayer_transient") namfile = "freyberg.nam" cbcfile = os.path.join(mpth, "freyberg.cbc") hdsfile = os.path.join(mpth, "freyberg.hds") cbc = CellBudgetFile(cbcfile) keys = ["FLOW RIGHT FACE", "FLOW FRONT FACE", "FLOW LOWER FACE"] vectors = [cbc.get_data(text=t)[0] for t in keys] hds = HeadFile(hdsfile) head = hds.get_data() m = flopy.modflow.Modflow.load(namfile, model_ws=mpth, verbose=False, load_only=["dis", "bas6", "upw"]) q = pp.get_specific_discharge(vectors, m, head) output_dir = os.path.join(cpth, "freyberg_vector") filenametocheck = "discharge.vtu" # export and check with point scalar vtk.export_vector(m, q, output_dir, "discharge", point_scalars=True) filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==2247857) nlines = count_lines_in_file(filetocheck) assert nlines == 10605 # with point scalars and binary vtk.export_vector(m, q, output_dir + "_bin", "discharge", point_scalars=True, binary=True) filetocheck = os.path.join(output_dir + "_bin", filenametocheck) # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==942413) # nlines1 = count_lines_in_file(filetocheck, binary=True) # assert(nlines1==3824) assert os.path.exists(filetocheck), "file (0) does not exist: {}".format( filetocheck) # with values directly given at vertices q = pp.get_specific_discharge(vectors, m, head, position="vertices") nancount = np.count_nonzero(np.isnan(q[0])) assert nancount == 472, "nancount != 472 ({})".format(nancount) overall = np.nansum(q[0]) + np.nansum(q[1]) + np.nansum(q[2]) assert np.allclose( overall, -15.849639024891047), "vertices overall = {}".format(overall) output_dir = os.path.join(cpth, "freyberg_vector") filenametocheck = "discharge_verts.vtu" vtk.export_vector(m, q, output_dir, "discharge_verts") filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==1990047) nlines2 = count_lines_in_file(filetocheck) assert nlines2 == 10598, "nlines != 10598 ({})".format(nlines2) # with values directly given at vertices and binary vtk.export_vector(m, q, output_dir + "_bin", "discharge_verts", binary=True) filetocheck = os.path.join(output_dir + "_bin", filenametocheck) # totalbytes3 = os.path.getsize(filetocheck) # assert(totalbytes3==891486) # nlines3 = count_lines_in_file(filetocheck, binary=True) # assert(nlines3==3012) assert os.path.exists(filetocheck), "file (1) does not exist: {}".format( filetocheck) return