#NEWLINE# def test_param_as_obj_1darray_explicit( self ) : #NEWLINE# #INDENT# prob = Problem ( ) #NEWLINE# root = prob . root = Group ( ) #NEWLINE# root . add ( 'comp' , ExecComp ( 'y = 3.0*x' , x = np . zeros ( ( 10 , ) ) , y = np . zeros ( ( 10 , ) ) ) ) #NEWLINE# root . add ( 'p' , IndepVarComp ( 'x' , np . zeros ( ( 10 , ) ) ) ) #NEWLINE# root . connect ( 'p.x' , 'comp.x' ) #NEWLINE# prob . driver . add_desvar ( 'p.x' , np . ones ( ( 8 , ) ) , indices = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) #NEWLINE# prob . driver . add_objective ( 'p.x' , indices = [ 5 , 6 , 7 ] ) #NEWLINE# prob . driver . add_constraint ( 'comp.y' , lower = ( - 100.0 ) ) #NEWLINE# prob . setup ( check = False ) #NEWLINE# prob . driver . _problem = prob #NEWLINE# prob . run ( ) #NEWLINE# Jbase = np . zeros ( ( 3 , 8 ) ) #NEWLINE# Jbase [ ( 0 , 4 ) ] = 1.0 #NEWLINE# Jbase [ ( 1 , 5 ) ] = 1.0 #NEWLINE# Jbase [ ( 2 , 6 ) ] = 1.0 #NEWLINE# J = prob . driver . calc_gradient ( [ 'p.x' ] , [ 'p.x' ] , mode = 'fwd' , return_format = 'dict' ) #NEWLINE# diff = np . linalg . norm ( ( J [ 'p.x' ] [ 'p.x' ] - Jbase ) ) #NEWLINE# assert_rel_error ( self , diff , 0.0 , 1e-09 ) #NEWLINE# J = prob . driver . calc_gradient ( [ 'p.x' ] , [ 'p.x' ] , mode = 'fwd' , return_format = 'array' ) #NEWLINE# diff = np . linalg . norm ( ( J - Jbase ) ) #NEWLINE# assert_rel_error ( self , diff , 0.0 , 1e-09 ) #NEWLINE# J = prob . driver . calc_gradient ( [ 'p.x' ] , [ 'p.x' ] , mode = 'rev' , return_format = 'dict' ) #NEWLINE# diff = np . linalg . norm ( ( J [ 'p.x' ] [ 'p.x' ] - Jbase ) ) #NEWLINE# assert_rel_error ( self , diff , 0.0 , 1e-09 ) #NEWLINE# J = prob . driver . calc_gradient ( [ 'p.x' ] , [ 'p.x' ] , mode = 'rev' , return_format = 'array' ) #NEWLINE# diff = np . linalg . norm ( ( J - Jbase ) ) #NEWLINE# assert_rel_error ( self , diff , 0.0 , 1e-09 ) #NEWLINE# J = prob . driver . calc_gradient ( [ 'p.x' ] , [ 'p.x' ] , mode = 'fd' , return_format = 'dict' ) #NEWLINE# diff = np . linalg . norm ( ( J [ 'p.x' ] [ 'p.x' ] - Jbase ) ) #NEWLINE# assert_rel_error ( self , diff , 0.0 , 1e-09 ) #NEWLINE# J = prob . driver . calc_gradient ( [ 'p.x' ] , [ 'p.x' ] , mode = 'fd' , return_format = 'array' ) #NEWLINE# diff = np . linalg . norm ( ( J - Jbase ) ) #NEWLINE# assert_rel_error ( self , diff , 0.0 , 1e-09 )