OpenMDAO Logo

An open-source framework for efficient multidisciplinary optimization.

POEM 039: User Functions in ExecComp

There is a new POEM (Proposal for OpenMDAO EnhanceMent) on the street. POEMS are the way that any new feature is vetted before being implemented. Developers and users are all welcome to propose POEMS! Also, we value any user input on POEMS before they are implemented. So please hop over to the proposal for POEM 039 and feel free to leave any comments you like (or submit suggested modifications as a PR of your own).

POEM 039 would enable users to register their own functions to the ExecComp, so they can use them in a simplified and streamlined manner without the boilerplate of writing their own component wrapper.

Here is an example of how it could work:

def aero_forces(rho, v, CD, CL, S)
    q = 0.5 * rho * v**2
    lift = q * CL * S
    drag = q * CD * S
    return lift, drag

om.ExecComp.register('aero_forces', aero_forces)

om.ExecComp('L,D = aero_forces(rho, v, CD, CL, S)', 
             rho={'units': 'kg/m**3'},
             v={'units': 'm/s'},
             S={'units': 'm**2'},
             lift={'units': 'N'},
             drag={'units': 'N'}, 
             vectorized=True, shape_by_conn=True, has_diag_partials=True

Also included is a small addition to make it easier to set up ExecComps to have I/O sized by connection. This will reduce the amount of boiler plate you need to set up ExecComps with vectorized I/O.

Comments are closed.

Fork me on GitHub