I have two components comp1 and comp2 which form a problem, which should be run several times. To do that I found that I could use the UniformDriver (I don't know if this is the most appropriate one for my purpose). However, I would like to feedback an output from comp2 into comp1. So after the first run, I obtain an output from comp2, which for the next run should be an input to comp1. I think the following example makes it a bit more clear what I would like to do:
from openmdao.api import Component, Group, Problem, UniformDriver
class Times2Plus(Component):
def __init__(self):
super(Times2Plus, self).__init__()
self.add_param('x', 1.0)
self.add_param('z', 2.0)
self.add_output('y', shape=1)
def solve_nonlinear(self, params, unknowns, resids):
unknowns['y'] = params['x'] * 2.0 + params['z']
class Power3(Component):
def __init__(self):
super(Power3, self).__init__()
self.add_param('y', shape=1)
self.add_output('x', shape=1) # feedback to params['x'] as input in next run
def solve_nonlinear(self, params, unknowns, resids):
unknowns['x'] = params['y'] ** 3.0
prob = Problem(root=Group())
prob.driver = UniformDriver(num_samples=5)
prob.root.add('comp1', Times2Plus())
prob.root.add('comp2', Power3())
prob.root.connect('comp1.y', 'comp2.y')
prob.setup()
prob.run()
Basically the output x of the component Power3 of the previous run shall be connected to the input x of component Times2Plus. In addition I have some parameter z, which I know beforehand, for component Times2Plus which differs for each run. What would be the best way to include this changing parameter and the feedback option?