<s> import os <EOL> import sys <EOL> import time <EOL> import numpy as np <EOL> import flopy <EOL> base_pth = os . path . join ( '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> cf_pth = os . path . join ( '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> res_pth = os . path . join ( '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def cf_model ( model , k , i , j , base , Q = - <NUM_LIT:100> ) : <EOL> wd = { <NUM_LIT:1> : [ [ k , i , j , Q ] ] } <EOL> model . remove_package ( '<STR_LIT>' ) <EOL> wel = flopy . modflow . ModflowWel ( model = model , stress_period_data = wd ) <EOL> wel . write_file ( ) <EOL> model . run_model ( silent = True ) <EOL> hedObj = flopy . utils . HeadFile ( os . path . join ( cf_pth , '<STR_LIT>' ) , precision = '<STR_LIT>' ) <EOL> cbcObj = flopy . utils . CellBudgetFile ( os . path . join ( cf_pth , '<STR_LIT>' ) , precision = '<STR_LIT>' ) <EOL> kk = hedObj . get_kstpkper ( ) <EOL> v = np . zeros ( ( len ( kk ) ) , dtype = np . float ) <EOL> h = hedObj . get_ts ( ( k , i , j ) ) <EOL> for idx , kon in enumerate ( kk ) : <EOL> if h [ idx , <NUM_LIT:1> ] == model . lpf . hdry : <EOL> v [ idx ] = np . nan <EOL> else : <EOL> v1 = cbcObj . get_data ( kstpkper = kon , text = '<STR_LIT>' , full3D = True ) [ <NUM_LIT:0> ] <EOL> v2 = cbcObj . get_data ( kstpkper = kon , text = '<STR_LIT>' , full3D = True ) [ <NUM_LIT:0> ] <EOL> v3 = cbcObj . get_data ( kstpkper = kon , text = '<STR_LIT>' , full3D = True ) [ <NUM_LIT:0> ] <EOL> v [ idx ] = ( ( v1 . sum ( ) + v2 . sum ( ) + v3 . sum ( ) ) - base ) / ( - Q ) <EOL> return v <EOL> ml = flopy . modflow . Modflow . load ( '<STR_LIT>' , version = '<STR_LIT>' , exe_name = '<STR_LIT>' , <EOL> verbose = True , model_ws = base_pth ) <EOL> nrow , ncol = ml . dis . nrow , ml . dis . ncol <EOL> ibound = ml . bas6 . ibound [ <NUM_LIT:3> , : , : ] <EOL> ml . model_ws = cf_pth <EOL> ml . write_input ( ) <EOL> ml . run_model ( ) <EOL> cbcObj = flopy . utils . CellBudgetFile ( os . path . join ( cf_pth , '<STR_LIT>' ) , precision = '<STR_LIT>' ) <EOL> v1 = cbcObj . get_data ( kstpkper = ( <NUM_LIT:0> , <NUM_LIT:0> ) , text = '<STR_LIT>' , full3D = True ) [ <NUM_LIT:0> ] <EOL> v2 = cbcObj . get_data ( kstpkper = ( <NUM_LIT:0> , <NUM_LIT:0> ) , text = '<STR_LIT>' , full3D = True ) [ <NUM_LIT:0> ] <EOL> v3 = cbcObj . get_data ( kstpkper = ( <NUM_LIT:0> , <NUM_LIT:0> ) , text = '<STR_LIT>' , full3D = True ) [ <NUM_LIT:0> ] <EOL> baseQ = v1 . sum ( ) + v2 . sum ( ) + v3 . sum ( ) <EOL> ml . remove_package ( '<STR_LIT>' ) <EOL> stress_period_data = { ( <NUM_LIT:1> , <NUM_LIT:9> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT:10> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT:20> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT:30> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT:50> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT> ) : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ( <NUM_LIT:1> , <NUM_LIT:100> ) : [ ] } <EOL> oc = flopy . modflow . ModflowOc ( ml , stress_period_data = stress_period_data ) <EOL> oc . write_file ( ) <EOL> nstep = <NUM_LIT:4> <EOL> nrow2 = nrow // nstep <EOL> ncol2 = ncol // nstep <EOL> fs = open ( os . path . join ( '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' . format ( nstep ) ) , '<STR_LIT:w>' , <NUM_LIT:0> ) <EOL> fs . write ( '<STR_LIT>' . format ( nrow , ncol ) ) <EOL> fs . write ( '<STR_LIT>' . format ( nstep ) ) <EOL> fs . write ( '<STR_LIT>' . format ( nrow2 , ncol2 ) ) <EOL> cf_array = np . empty ( ( <NUM_LIT:10> , nrow2 , ncol2 ) , dtype = np . float ) <EOL> cf_array . fill ( np . nan ) <EOL> start = time . time ( ) <EOL> icnt = <NUM_LIT:0> <EOL> jcnt = <NUM_LIT:0> <EOL> idx = <NUM_LIT:0> <EOL> for i in range ( <NUM_LIT:0> , nrow , nstep ) : <EOL> jcnt = <NUM_LIT:0> <EOL> for j in range ( <NUM_LIT:0> , ncol , nstep ) : <EOL> if ibound [ i , j ] < <NUM_LIT:1> : <EOL> sys . stdout . write ( '<STR_LIT:.>' ) <EOL> else : <EOL> line = '<STR_LIT>' . format ( icnt + <NUM_LIT:1> , nrow2 , jcnt + <NUM_LIT:1> , ncol2 ) <EOL> fs . write ( line ) <EOL> sys . stdout . write ( line ) <EOL> s0 = time . time ( ) <EOL> cf = cf_model ( ml , <NUM_LIT:3> , i , j , baseQ ) <EOL> s1 = time . time ( ) <EOL> line = '<STR_LIT>' . format ( idx , s1 - s0 ) <EOL> fs . write ( line ) <EOL> sys . stdout . write ( line ) <EOL> idx += <NUM_LIT:1> <EOL> if icnt < nrow2 and jcnt < ncol2 : <EOL> cf_array [ : , icnt , jcnt ] = cf . copy ( ) <EOL> jcnt += <NUM_LIT:1> <EOL> icnt += <NUM_LIT:1> <EOL> end = time . time ( ) <EOL> ets = end - start <EOL> line = '<STR_LIT:\n>' + '<STR_LIT>' . format ( ets ) + '<STR_LIT>' . format ( ets / <NUM_LIT> ) + '<STR_LIT>' . format ( ets / <NUM_LIT> ) <EOL> fs . write ( line ) <EOL> sys . stdout . write ( line ) <EOL> fs . close ( ) <EOL> filelist = [ f for f in os . listdir ( cf_pth ) ] <EOL> for f in filelist : <EOL> os . remove ( os . path . join ( cf_pth , f ) ) <EOL> if not os . path . exists ( res_pth ) : <EOL> os . makedirs ( res_pth ) <EOL> for idx in range ( <NUM_LIT:10> ) : <EOL> fn = os . path . join ( res_pth , '<STR_LIT>' . format ( nstep , idx + <NUM_LIT:1> ) ) <EOL> print ( '<STR_LIT>' . format ( os . path . basename ( fn ) ) ) <EOL> np . savetxt ( fn , cf_array [ idx , : , : ] , delimiter = '<STR_LIT:U+0020>' ) </s>
