#NEWLINE# def test_list_states( self ) : #NEWLINE# #INDENT# top = Problem ( ) #NEWLINE# root = top . root = Group ( ) #NEWLINE# sub = root . add ( 'sub' , Group ( ) ) #NEWLINE# sub . add ( 'comp' , SimpleImplicitComp ( ) ) #NEWLINE# sub . ln_solver = ScipyGMRES ( ) #NEWLINE# top . setup ( check = False ) #NEWLINE# top [ 'sub.comp.z' ] = 7.7 #NEWLINE# stream = cStringIO ( ) #NEWLINE# root . list_states ( stream = stream ) #NEWLINE# self . assertTrue ( ( 'sub.comp.z' in stream . getvalue ( ) ) ) #NEWLINE# self . assertTrue ( ( 'Value: 7.7' in stream . getvalue ( ) ) ) #NEWLINE# self . assertTrue ( ( 'Residual: 0.0' in stream . getvalue ( ) ) ) #NEWLINE# self . assertTrue ( ( 'States in model:' in stream . getvalue ( ) ) ) #NEWLINE# stream = cStringIO ( ) #NEWLINE# sub . list_states ( stream = stream ) #NEWLINE# self . assertTrue ( ( 'comp.z' in stream . getvalue ( ) ) ) #NEWLINE# self . assertTrue ( ( 'Value: 7.7' in stream . getvalue ( ) ) ) #NEWLINE# self . assertTrue ( ( 'Residual: 0.0' in stream . getvalue ( ) ) ) #NEWLINE# self . assertTrue ( ( 'sub.comp.z' not in stream . getvalue ( ) ) ) #NEWLINE# self . assertTrue ( ( 'States in sub:' in stream . getvalue ( ) ) ) #NEWLINE# top = Problem ( ) #NEWLINE# root = top . root = ExampleGroupWithPromotes ( ) #NEWLINE# top . setup ( check = False ) #NEWLINE# stream = cStringIO ( ) #NEWLINE# root . list_states ( stream = stream ) #NEWLINE# self . assertTrue ( ( 'No states in model.' in stream . getvalue ( ) ) ) #NEWLINE# stream = cStringIO ( ) #NEWLINE# root . G2 . list_states ( stream = stream ) #NEWLINE# self . assertTrue ( ( 'No states in G2.' in stream . getvalue ( ) ) ) #NEWLINE# class ArrayImplicitComp ( Component ) : #NEWLINE# #INDENT# ' Needed to test arrays here. ' #NEWLINE# def __init__( self ) : #NEWLINE# #INDENT# super ( ArrayImplicitComp , self ) . __init__ ( ) #NEWLINE# self . add_param ( 'x' , np . zeros ( ( 3 , 1 ) ) ) #NEWLINE# self . add_output ( 'y' , np . zeros ( ( 3 , 1 ) ) ) #NEWLINE# self . add_state ( 'z' , ( 2.0 * np . ones ( ( 3 , 1 ) ) ) , lower = 1.5 , upper = np . array ( [ 2.5 , 2.6 , 2.7 ] ) ) #NEWLINE# #UNINDENT# def solve_nonlinear( self , params , unknowns , resids ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# def apply_nonlinear( self , params , unknowns , resids ) : #NEWLINE# #INDENT# " Don't solve; just calculate the residual." #NEWLINE# pass #NEWLINE# #UNINDENT# def linearize( self , params , unknowns , resids ) : #NEWLINE# #INDENT# 'Analytical derivatives.' #NEWLINE# pass #NEWLINE# #UNINDENT# #UNINDENT# top = Problem ( ) #NEWLINE# root = top . root = Group ( ) #NEWLINE# root . add ( 'comp' , ArrayImplicitComp ( ) ) #NEWLINE# root . ln_solver . options [ 'maxiter' ] = 2 #NEWLINE# top . setup ( check = False ) #NEWLINE# stream = cStringIO ( ) #NEWLINE# root . list_states ( stream = stream ) #NEWLINE# base = 'States in model:\n\ncomp.z\nValue: [[ 2.]\n [ 2.]\n [ 2.]]\nResidual: [[ 0.]\n [ 0.]\n [ 0.]]' #NEWLINE# self . assertTrue ( ( top in stream . getvalue ( ) ) )