#NEWLINE# def test_execcomp_derivatives( self ) : #NEWLINE# #INDENT# exp1 = [ 'y1 = 2.0*x1 + x2*x2' , 'y2 = 3.0*x1*x2' ] #NEWLINE# deriv1 = [ 'dy1_dx1 = 2.0' , 'dy1_dx2 = 2.0*x2' , 'dy2_dx1 = 3.0*x2' , 'dy2_dx2 = 3.0*x1' ] #NEWLINE# self . top . add ( 'comp1' , ExecCompWithDerivatives ( exp1 , deriv1 ) ) #NEWLINE# self . top . driver . workflow . add ( 'comp1' ) #NEWLINE# self . top . comp1 . x1 = 3.0 #NEWLINE# self . top . comp1 . x2 = 5.0 #NEWLINE# self . top . run ( ) #NEWLINE# J = self . top . driver . calc_gradient ( inputs = [ 'comp1.x1' , 'comp1.x2' ] , outputs = [ 'comp1.y1' , 'comp1.y2' ] ) #NEWLINE# assert_rel_error ( self , J [ ( 0 , 0 ) ] , 2.0 , 0.0001 ) #NEWLINE# assert_rel_error ( J , J [ ( 0 , 1 ) ] , 10.0 , 0.0001 ) #NEWLINE# assert_rel_error ( self , J [ ( 1 , 0 ) ] , 15.0 , 0.0001 ) #NEWLINE# assert_rel_error ( self , J [ ( 1 , 1 ) ] , 9.0 , 0.0001 ) #NEWLINE# self . assertEqual ( self . top . comp1 . y2 , 45.0 )