POEM ID: 041
Title: Add expressions to ExecComp after instantiation
authors: [robfalck]
Competing POEMs: N/A
Related POEMs: N/A
Associated implementation PR: #1977
- Active
- Requesting decision
- Accepted
- Rejected
- Integrated
Almost all OpenMDAO components allow for IO to be added after instantiation.
Currently, ExecComp does not; the handling of all IO is done in setup
.
There are situations where an expression needs to be added at setup time.
This POEM proposes to add a new method to ExecComp: add_expr
.
Add_expr will take the same form as ExecComp initialization:
def add_expr(expr, **kwargs)
To make it usable during the configure step of setup, add_expr
will immediately add the necessary IO and declare the relevant partials for the given expression.
import openmdao.api as om
exec_comp = om.ExecComp()
exec_comp.add_expr('y = sin(x)', y={'shape': (5,)}, x={'shape': (5,)})
If added after the above example, the following should raise an error:
exec_comp.add_expr('z = cos(x)', z={'shape': (6,)}, x={'shape': (6,)})
ValueError: Input x has multiple values for metadata: 'shape'