Find a solution that fulfils a subset of output parameters

I new using openMDAO so I assume this should be an easy question.

I have a complex group (with explicit components and cycles) that I can solve for a set of input variables:

y1, y2,..., yi = Group(x1, x2,..., xj)

What I am trying to do now is to match two outputs (y1_target and y2_target) changing two inputs from the group (x1, x2), i.e., adding two equations out of the group such as,

y1_target - y1 = 0

y2_target - y2 = 0

I understand that this should be done with two implicit components but ¿how I force to only change x1 and x2?

Thanks,

Upvotes: 0

Views: 70

Answers (1)

Rob Falck
Rob Falck

Reputation: 2704

This can be done with a single BalanceComp on a group outside of the group you mention there. A simple diagram of the system, as I understand it, is below.

Here a BalanceComp is added that handles your two residual equations. BalanceComp is an ImplicitComponent in OpenMDAO that handles simple "set X equal to Y" situations like the one in your case. The documentation for it is here.

In your case, the outer group (called g_outer in the code below) would have a balance comp that is set to satisfy two residual equations. Subsystem "group" refers to your existing group.

bal = g_outer.add_subsystem('balance', bal)
bal.add_balance('x1', lhs_name='y1_target', rhs_name='y1')
bal.add_balance('x2', lhs_name='y2_target', rhs_name='y2')

g_outer.connect('balance.x1', 'group.x1')
g_outer.connect('balance.x2', 'group.x2')
g_outer.connect('group.y1', 'balance.y1')
g_outer.connect('group.y2', 'balance.y2')

Another absolutely critical set is setting the nonlinear and linear solvers of g_outer. The default solvers only work for explicit systems. This implicit system requires a NewtonSolver for the nonlinear solver, and some iterative linear solver. DirectSolver often works fine unless the system is very large.

g_outer.nonlinear_solver = om.NewtonSolver(solve_subsystems=True)
g_outer.linear_solver = om.DirectSolver()

Left out of the above snippet is the code that either connects a value to balance.y1_target and balance.y2_target, or sets them after setup.

enter image description here

Upvotes: 1

Related Questions