@@ -45,18 +45,17 @@ def read_gradients(Grad_filename, scale=1.0):
4545 """
4646
4747 # open file and skip first line
48- gradfile = open (Grad_filename )
49- gradfile .readline ()
50-
51- # read values
52- grad_vals = []
53- for line in gradfile :
54- line = line .strip ()
55- if len (line ) == 0 :
56- break
57- grad_vals .append (float (line ) * scale )
58- #: for each line
59-
48+ with open (Grad_filename ) as gradfile :
49+ gradfile .readline ()
50+
51+ # read values
52+ grad_vals = []
53+ for line in gradfile :
54+ line = line .strip ()
55+ if len (line ) == 0 :
56+ break
57+ grad_vals .append (float (line ) * scale )
58+ # done
6059 return grad_vals
6160
6261
@@ -387,7 +386,7 @@ def read_aerodynamics(
387386 Func_Values [key ] = history_data ["TAVG_" + key ][- 1 ]
388387 else :
389388 # in steady cases take only last value.
390- for key , value in Func_Values .iteritems ():
389+ for key , value in Func_Values .items ():
391390 if not history_data .get (key ):
392391 raise KeyError (
393392 "Key "
@@ -641,7 +640,7 @@ def get_dvID(kindName):
641640 try :
642641 return id_map [kindName ]
643642 except KeyError :
644- raise Exception ("Unrecognized Design Variable Name: %s" , kindName )
643+ raise Exception ("Unrecognized Design Variable Name: %s" % kindName )
645644
646645
647646#: def get_dvID()
@@ -652,7 +651,10 @@ def get_dvID(kindName):
652651# -------------------------------------------------------------------
653652
654653
655- def get_gradFileFormat (grad_type , plot_format , kindID , special_cases = []):
654+ def get_gradFileFormat (grad_type , plot_format , kindID , special_cases = None ):
655+
656+ if special_cases is None :
657+ special_cases = []
656658
657659 # start header, build a list of strings and join at the end
658660 header = []
@@ -731,7 +733,7 @@ def get_gradFileFormat(grad_type, plot_format, kindID, special_cases=[]):
731733 write_format .append (r", %s, %s, %s" )
732734 elif kindID == "CST" :
733735 header .append (r',"Up/Down","Kulfan number", "Total Kulfan numbers"' )
734- write_format .append (r", %s, %s" , " %s" )
736+ write_format .append (r", %s, %s, %s" )
735737 elif kindID == "FAIRING" :
736738 header .append (r',"ControlPoint_Index","Theta_Disp","R_Disp"' )
737739 write_format .append (r", %s, %s, %s" )
@@ -1170,8 +1172,8 @@ def make_link(src, dst):
11701172 os .symlink (src , dst )
11711173
11721174
1173- def restart2solution (config , state = {} ):
1174- """restart2solution(config,state={} )
1175+ def restart2solution (config , state = None ):
1176+ """restart2solution(config, state=None )
11751177 moves restart file to solution file,
11761178 optionally updates state
11771179 direct or adjoint is read from config
0 commit comments