#NEWLINE# def solve( self , params , unknowns , resids , system , solver , alpha , fnorm0 , metadata = None ) : #NEWLINE# #INDENT# ' Take the gradient calculated by the parent solver and figure out\n        how far to go.\n\n        Args\n        ----\n        params : `VecWrapper`\n            `VecWrapper` containing parameters. (p)\n\n        unknowns : `VecWrapper`\n            `VecWrapper` containing outputs and states. (u)\n\n        resids : `VecWrapper`\n            `VecWrapper` containing residuals. (r)\n\n        system : `System`\n            Parent `System` object.\n\n        metadata : dict, optional\n            Dictionary containing execution metadata (e.g. iteration coordinate).\n\n        solver : `Solver`\n            Parent solver instance.\n\n        alpha : float\n            Initial over-relaxation factor as used in parent solver.\n\n        fnorm0 : float\n            Initial norm of the residual for relative tolerance check.\n\n        Returns\n        --------\n        float\n            Norm of the final residual\n        ' #NEWLINE# atol = self . options [ 'atol' ] #NEWLINE# rtol = self . options [ 'rtol' ] #NEWLINE# maxiter = self . options [ 'maxiter' ] #NEWLINE# result = system . dumat [ None ] #NEWLINE# local_meta = create_local_meta ( metadata , system . pathname ) #NEWLINE# alpha = unknowns . distance_along_vector_to_limit ( alpha , result ) #NEWLINE# unknowns . vec += ( alpha * result . vec ) #NEWLINE# update_local_meta ( local_meta , ( solver . iter_count , 0 ) ) #NEWLINE# if solver . options [ 'solve_subsystems' ] : #NEWLINE# #INDENT# system . children_solve_nonlinear ( local_meta ) #NEWLINE# #UNINDENT# system . apply_nonlinear ( params , unknowns , resids , local_meta ) #NEWLINE# self . recorders . record_iteration ( system , local_meta ) #NEWLINE# fnorm = resids . norm ( ) #NEWLINE# if ( solver . options [ 'iprint' ] > 0 ) : #NEWLINE# #INDENT# self . print_norm ( solver . print_name , system . pathname , solver . iter_count , fnorm , fnorm0 ) #NEWLINE# #UNINDENT# itercount = 0 #NEWLINE# ls_alpha = alpha #NEWLINE# while ( ( itercount < maxiter ) and ( fnorm > atol ) and ( ( fnorm / fnorm0 ) > rtol ) ) : #NEWLINE# #INDENT# ls_alpha *= 0.5 #NEWLINE# unknowns . vec -= ( ls_alpha * result . vec ) #NEWLINE# itercount += 1 #NEWLINE# update_local_meta ( local_meta , ( solver . iter_count , atol ) ) #NEWLINE# if self . options [ 'solve_subsystems' ] : #NEWLINE# #INDENT# system . children_solve_nonlinear ( local_meta ) #NEWLINE# #UNINDENT# system . apply_nonlinear ( params , unknowns , resids , local_meta ) #NEWLINE# solver . recorders . record_iteration ( system , local_meta ) #NEWLINE# fnorm = resids . norm ( ) #NEWLINE# if ( self . options [ 'iprint' ] > 0 ) : #NEWLINE# #INDENT# self . print_norm ( self . print_name , system . pathname , itercount , fnorm , fnorm0 , indent = 1 , solver = 'LS' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( itercount >= maxiter ) and self . options [ 'err_on_maxiter' ] ) : #NEWLINE# #INDENT# raise AnalysisError ( ( "Solve in '%s': BackTracking failed to converge after %d iterations." % ( system . pathname , maxiter ) ) ) #NEWLINE# #UNINDENT# return fnorm