<s> """<STR_LIT>""" <EOL> import sys <EOL> import numpy as np <EOL> from . . pakbase import Package <EOL> from numpy import atleast_2d <EOL> from flopy . modflow . mfparbc import ModflowParBc as mfparbc <EOL> from numpy . lib . recfunctions import stack_arrays <EOL> class ModflowHfb ( Package ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , model , nphfb = <NUM_LIT:0> , mxfb = <NUM_LIT:0> , nhfbnp = <NUM_LIT:0> , <EOL> hfb_data = None , nacthfb = <NUM_LIT:0> , no_print = False , <EOL> options = None , extension = '<STR_LIT>' , unitnumber = <NUM_LIT> ) : <EOL> Package . __init__ ( self , model , extension , '<STR_LIT>' , <EOL> unitnumber ) <EOL> self . heading = '<STR_LIT>' <EOL> self . url = '<STR_LIT>' <EOL> self . nphfb = nphfb <EOL> self . mxfb = mxfb <EOL> self . nacthfb = nacthfb <EOL> self . no_print = no_print <EOL> self . np = <NUM_LIT:0> <EOL> if options is None : <EOL> options = [ ] <EOL> if self . no_print : <EOL> options . append ( '<STR_LIT>' ) <EOL> self . options = options <EOL> aux_names = [ ] <EOL> it = <NUM_LIT:0> <EOL> while it < len ( options ) : <EOL> print ( it , options [ it ] ) <EOL> if '<STR_LIT>' in options [ it ] . lower ( ) : <EOL> aux_names . append ( options [ it + <NUM_LIT:1> ] . lower ( ) ) <EOL> it += <NUM_LIT:1> <EOL> it += <NUM_LIT:1> <EOL> if hfb_data is None : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> self . nhfbnp = len ( hfb_data ) <EOL> self . hfb_data = ModflowHfb . get_empty ( self . nhfbnp ) <EOL> for ibnd , t in enumerate ( hfb_data ) : <EOL> self . hfb_data [ ibnd ] = tuple ( t ) <EOL> self . parent . add_package ( self ) <EOL> def ncells ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . nhfbnp <EOL> def write_file ( self ) : <EOL> """<STR_LIT>""" <EOL> f_hfb = open ( self . fn_path , '<STR_LIT:w>' ) <EOL> f_hfb . write ( '<STR_LIT>' . format ( self . heading ) ) <EOL> f_hfb . write ( '<STR_LIT>' . format ( self . nphfb , self . mxfb , self . nhfbnp ) ) <EOL> for option in self . options : <EOL> f_hfb . write ( '<STR_LIT>' . format ( option ) ) <EOL> f_hfb . write ( '<STR_LIT:\n>' ) <EOL> for a in self . hfb_data : <EOL> f_hfb . write ( <EOL> '<STR_LIT>' . format ( a [ <NUM_LIT:0> ] + <NUM_LIT:1> , a [ <NUM_LIT:1> ] + <NUM_LIT:1> , a [ <NUM_LIT:2> ] + <NUM_LIT:1> , a [ <NUM_LIT:3> ] + <NUM_LIT:1> , a [ <NUM_LIT:4> ] + <NUM_LIT:1> , <EOL> a [ <NUM_LIT:5> ] ) ) <EOL> f_hfb . write ( '<STR_LIT>' . format ( self . nacthfb ) ) <EOL> f_hfb . close ( ) <EOL> @ staticmethod <EOL> def get_empty ( ncells = <NUM_LIT:0> , aux_names = None , structured = True ) : <EOL> """<STR_LIT>""" <EOL> dtype = ModflowHfb . get_default_dtype ( structured = structured ) <EOL> if aux_names is not None : <EOL> dtype = Package . add_to_dtype ( dtype , aux_names , np . float32 ) <EOL> d = np . zeros ( ( ncells , len ( dtype ) ) , dtype = dtype ) <EOL> d [ : , : ] = - <NUM_LIT> <EOL> return np . core . records . fromarrays ( d . transpose ( ) , dtype = dtype ) <EOL> @ staticmethod <EOL> def get_default_dtype ( structured = True ) : <EOL> """<STR_LIT>""" <EOL> if structured : <EOL> dtype = np . dtype ( [ ( "<STR_LIT:k>" , np . int ) , <EOL> ( "<STR_LIT>" , np . int ) , ( "<STR_LIT>" , np . int ) , <EOL> ( "<STR_LIT>" , np . int ) , ( "<STR_LIT>" , np . int ) , <EOL> ( "<STR_LIT>" , np . float32 ) ] ) <EOL> else : <EOL> assert not structured , '<STR_LIT>' <EOL> return dtype <EOL> @ staticmethod <EOL> def load ( f , model , ext_unit_dict = None ) : <EOL> """<STR_LIT>""" <EOL> if model . verbose : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> if not hasattr ( f , '<STR_LIT>' ) : <EOL> filename = f <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> while True : <EOL> line = f . readline ( ) <EOL> if line [ <NUM_LIT:0> ] != '<STR_LIT:#>' : <EOL> break <EOL> t = line . strip ( ) . split ( ) <EOL> nphfb = int ( t [ <NUM_LIT:0> ] ) <EOL> mxfb = int ( t [ <NUM_LIT:1> ] ) <EOL> nhfbnp = int ( t [ <NUM_LIT:2> ] ) <EOL> options = [ ] <EOL> aux_names = [ ] <EOL> if len ( t ) > <NUM_LIT:2> : <EOL> it = <NUM_LIT:2> <EOL> while it < len ( t ) : <EOL> toption = t [ it ] <EOL> if toption . lower ( ) is '<STR_LIT>' : <EOL> options . append ( toption ) <EOL> elif '<STR_LIT>' in toption . lower ( ) : <EOL> options . append ( '<STR_LIT:U+0020>' . join ( t [ it : it + <NUM_LIT:2> ] ) ) <EOL> aux_names . append ( t [ it + <NUM_LIT:1> ] . lower ( ) ) <EOL> it += <NUM_LIT:1> <EOL> it += <NUM_LIT:1> <EOL> if nphfb > <NUM_LIT:0> : <EOL> dt = ModflowHfb . get_empty ( <NUM_LIT:1> ) . dtype <EOL> pak_parms = mfparbc . load ( f , nphfb , dt , model . verbose ) <EOL> bnd_output = None <EOL> if nhfbnp > <NUM_LIT:0> : <EOL> specified = ModflowHfb . get_empty ( nhfbnp ) <EOL> for ibnd in range ( nhfbnp ) : <EOL> line = f . readline ( ) <EOL> if "<STR_LIT>" in line . lower ( ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> t = line . strip ( ) . split ( ) <EOL> specified [ ibnd ] = tuple ( t [ : len ( specified . dtype . names ) ] ) <EOL> specified [ '<STR_LIT:k>' ] -= <NUM_LIT:1> <EOL> specified [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> specified [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> specified [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> specified [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> bnd_output = np . recarray . copy ( specified ) <EOL> if nphfb > <NUM_LIT:0> : <EOL> partype = [ '<STR_LIT>' ] <EOL> line = f . readline ( ) <EOL> t = line . strip ( ) . split ( ) <EOL> nacthfb = int ( t [ <NUM_LIT:0> ] ) <EOL> for iparm in range ( nacthfb ) : <EOL> line = f . readline ( ) <EOL> t = line . strip ( ) . split ( ) <EOL> pname = t [ <NUM_LIT:0> ] . lower ( ) <EOL> iname = '<STR_LIT>' <EOL> par_dict , current_dict = pak_parms . get ( pname ) <EOL> data_dict = current_dict [ iname ] <EOL> par_current = ModflowHfb . get_empty ( par_dict [ '<STR_LIT>' ] ) <EOL> if model . mfpar . pval is None : <EOL> parval = np . float ( par_dict [ '<STR_LIT>' ] ) <EOL> else : <EOL> try : <EOL> parval = np . float ( model . mfpar . pval . pval_dict [ pname ] ) <EOL> except : <EOL> parval = np . float ( par_dict [ '<STR_LIT>' ] ) <EOL> for ibnd , t in enumerate ( data_dict ) : <EOL> par_current [ ibnd ] = tuple ( t [ : len ( par_current . dtype . names ) ] ) <EOL> par_current [ '<STR_LIT:k>' ] -= <NUM_LIT:1> <EOL> par_current [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> par_current [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> par_current [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> par_current [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> for ptype in partype : <EOL> par_current [ ptype ] *= parval <EOL> if bnd_output is None : <EOL> bnd_output = np . recarray . copy ( par_current ) <EOL> else : <EOL> bnd_output = stack_arrays ( ( bnd_output , par_current ) , <EOL> asrecarray = True , usemask = False ) <EOL> hfb = ModflowHfb ( model , nphfb = <NUM_LIT:0> , mxfb = <NUM_LIT:0> , nhfbnp = len ( bnd_output ) , <EOL> hfb_data = bnd_output , <EOL> nacthfb = <NUM_LIT:0> , options = options ) <EOL> return hfb </s>
