Search code examples
openmdao

Outputs initialization using input values


In an ExplicitComponent class, within the definition of the setup function is there a way to give the value of an output during its declaration based on the value of an input created just before in that setup function ?

For instance to do something like :

class Discipline_1(ExplicitComponent):
    def setup(self):
        self.add_input('Input_1', val=5.0)

        self.add_output('Output_1',val = 0.07*inputs['Input_1'])

The idea is, as the 'NonlinearBlockGS' solver in a cycle use the 'val' information to initialize a fixed point method, I would like to give an appropriate initialization to minimize the number of 'NonlinearBlockGS' iterations.


Solution

  • If you really wanted to initialize the output based on the input value, just define the input value as a local variable:

    class Discipline_1(ExplicitComponent):
        def setup(self):
            inp_val = 5.0
            self.add_input('Input_1', val=inp_val)
    
            self.add_output('Output_1',val = 0.07*inp_val)
    

    That would only work if you had a fixed value known at setup time. You could pass that value into the class constructor via metadata to make it a little more general. However this may not be the most general approach.

    Your group has a certain run sequence, which you could set manually if you liked. the GaussSeidel solver will execute the loop on that sequence, so you only need to initialize the value that is the the input to the first component in the loop. All the others will get their values passed to them by their upstream component source as the GS solver runs. This initial value could be set manually after setup is called by setting the value using the problem interface:

    prob['Input_1'] = 5.0
    

    As a side note in openmdao 2.0.2 we have a guess_nonlinear method defined on ImplicitComponents that you can use to initialize implicit output variables, but that is not applicable here