<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from openmdao . api import IndepVarComp , Component , Group , Problem <EOL> class SimpleComp ( Component ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( SimpleComp , self ) . __init__ ( ) <EOL> self . add_param ( '<STR_LIT:x>' , <NUM_LIT> ) <EOL> self . add_output ( '<STR_LIT:y>' , <NUM_LIT:0.0> ) <EOL> self . print_output = True <EOL> def solve_nonlinear ( self , params , unknowns , resids ) : <EOL> """<STR_LIT>""" <EOL> unknowns [ '<STR_LIT:y>' ] = <NUM_LIT> * params [ '<STR_LIT:x>' ] <EOL> if self . print_output : <EOL> print ( '<STR_LIT>' , self . name ) <EOL> def linearize ( self , params , unknowns , resids ) : <EOL> """<STR_LIT>""" <EOL> J = { } <EOL> J [ ( '<STR_LIT:y>' , '<STR_LIT:x>' ) ] = <NUM_LIT> <EOL> if self . print_output : <EOL> print ( '<STR_LIT>' , self . name ) <EOL> return J <EOL> class Model ( Group ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( Model , self ) . __init__ ( ) <EOL> self . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT> ) ) <EOL> self . add ( '<STR_LIT>' , SimpleComp ( ) ) <EOL> self . add ( '<STR_LIT>' , SimpleComp ( ) ) <EOL> self . add ( '<STR_LIT>' , SimpleComp ( ) ) <EOL> self . add ( '<STR_LIT>' , SimpleComp ( ) ) <EOL> self . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . fd_options [ '<STR_LIT>' ] = True <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> top = Problem ( ) <EOL> top . root = Model ( ) <EOL> top . setup ( ) <EOL> top . run ( ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT:->' * <NUM_LIT> ) <EOL> J = top . calc_gradient ( [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> print ( J ) </s>
