def setup(self): g = self.group # define a subsystem (this is a very simple example) group = Group() p = group.create_indep_var('p', val=7) q = group.create_indep_var('q', val=8) r = p + q group.register_output('r', r) # add child system g.add_subsystem('R', group, promotes=['*']) # declare output of child system as input to parent system r = g.declare_input('r') c = g.declare_input('c', val=18) # a == (3 + a - 2 * a**2)**(1 / 4) with g.create_group('coeff_a') as group: a = group.create_output('a') a.define((3 + a - 2 * a**2)**(1 / 4)) group.nonlinear_solver = NonlinearBlockGS(iprint=0, maxiter=100) a = g.declare_input('a') with g.create_group('coeff_b') as group: group.create_indep_var('b', val=-4) b = g.declare_input('b') y = g.create_implicit_output('y') z = a * y**2 + b * y + c - r y.define_residual_bracketed(z, x1=0, x2=2)
def setup(self): group = Group() a = group.declare_input('a', val=2) b = group.create_indep_var('b', val=12) group.register_output('prod', a * b) self.add_subsystem('sys', group, promotes=['*']) # These expressions do not lead to constructing any Component # objects x1 = self.declare_input('x1') x2 = self.declare_input('x2') y1 = x2 + x1 y2 = x2 - x1 y3 = x1 * x2 y5 = x2**2
def setup(self): g = self.group # define a subsystem (this is a very simple example) group = Group() p = group.create_indep_var('p', val=[7, -7]) q = group.create_indep_var('q', val=[8, -8]) r = p + q group.register_output('r', r) # add child system g.add_subsystem('R', group, promotes=['*']) # declare output of child system as input to parent system r = g.declare_input('r', shape=(2, )) c = g.declare_input('c', val=[18, -18]) # a == (3 + a - 2 * a**2)**(1 / 4) with g.create_group('coeff_a') as group: a = group.create_output('a') a.define((3 + a - 2 * a**2)**(1 / 4)) group.nonlinear_solver = NonlinearBlockGS(iprint=0, maxiter=100) # store positive and negative values of `a` in an array ap = g.declare_input('a') an = -ap a = g.create_output('vec_a', shape=(2, )) a[0] = ap a[1] = an with g.create_group('coeff_b') as group: group.create_indep_var('b', val=[-4, 4]) b = g.declare_input('b', shape=(2, )) y = g.create_implicit_output('y', shape=(2, )) z = a * y**2 + b * y + c - r y.define_residual_bracketed( z, x1=[0, 2.], x2=[2, np.pi], )
def setup(self): # Create independent variable x1 = self.create_indep_var('x1', val=40) # Powers y4 = x1**2 # Create subsystem that depends on previously created # independent variable subgroup = Group() # This value is overwritten by connection from the main group a = subgroup.declare_input('x1', val=2) b = subgroup.create_indep_var('x2', val=12) subgroup.register_output('prod', a * b) self.add_subsystem('subsystem', subgroup, promotes=['*']) # declare inputs with default values # This value is overwritten by connection # from the subgroup x2 = self.declare_input('x2', val=3) # Simple addition y1 = x2 + x1 self.register_output('y1', y1) # Simple subtraction self.register_output('y2', x2 - x1) # Simple multitplication self.register_output('y3', x1 * x2) # Powers y5 = x2**2 # register outputs in reverse order to how they are defined self.register_output('y5', y5) self.register_output('y6', y1 + y5) self.register_output('y4', y4)
def setup(self): g = self.group # define a subsystem (this is a very simple example) group = Group() p = group.create_indep_var('p', val=7) q = group.create_indep_var('q', val=8) r = p + q group.register_output('r', r) # add child system g.add_subsystem('R', group, promotes=['*']) # declare output of child system as input to parent system r = g.declare_input('r') c = g.declare_input('c', val=18) # a == (3 + a - 2 * a**2)**(1 / 4) group = Group() a = group.create_output('a') a.define((3 + a - 2 * a**2)**(1 / 4)) group.nonlinear_solver = NonlinearBlockGS(iprint=0, maxiter=100) g.add_subsystem('coeff_a', group, promotes=['*']) a = g.declare_input('a') group = Group() group.create_indep_var('b', val=-4) g.add_subsystem('coeff_b', group, promotes=['*']) b = g.declare_input('b') y = g.create_implicit_output('y') z = a * y**2 + b * y + c - r y.define_residual(z) self.linear_solver = ScipyKrylov() self.nonlinear_solver = NewtonSolver( solve_subsystems=False, maxiter=100, )