0

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?

maxbec
  • 1
  • 2
  • Are you performing a fix point iteration, where you keep running comp1 and comp2 until the values stop changing and the system converges? – Kenneth Moore Nov 20 '15 at 18:03
  • Basically my comp1 wraps some external program to calculate loads for a certain speed and comp2 takes the loads as input to calculate displacements. Now for the next speed, which corresponds to the next run, I would like to feedback the calculated displacements as an input for comp1 to calculate new loads. I know the number of runs, which simpy corresponds to the length of my speed vector, so I do not have to iterate. How can I implement such a structure in OpenMDAO? – maxbec Nov 20 '15 at 21:58
  • The way you're describing the problem, I suggest using multiple instances of comp1 and comp2, rather than using some kind of drive. You run comp1a, pass its output to comp2a, then pass its output to comp1b, etc. – Justin Gray Nov 23 '15 at 12:31
  • Okay, that is of course a solution, but I thought maybe there exists some nicer way to implement it. I guess this is probably quite a unique problem. Thank you for helping me out. – maxbec Nov 24 '15 at 09:05

1 Answers1

0

You don't want a drive in this case. You're talking about a solver (distinct from a driver in OpenMDAO > 1.0).

You can see an example of how to set up this kind of thing in our Sellar Example, using a Non Linear Gauss Seidel. Basically you just need to connect up the components in a circular fashion and then add an appropriate solver to make sure they are converged.

Justin Gray
  • 5,605
  • 1
  • 11
  • 16
  • I see that this is a solution for a mathematical problem, where I am looking for some converged value. However, for my problem as explained in my other comment, I think there is no converged value for which I can solve as I only want to run a fixed number of runs. What would be the right way to implement it for this special problem? – maxbec Nov 20 '15 at 22:11