Search code examples
openmdao

OpenMDAO efficiency with using multiple comp


I recently read this sentence in a paper:

One important feature of OpenMDAO is the ability to subdivide a problem into components that have a small number of inputs and outputs and contain relatively simple analyzes.

Moreover, looking at the examples in the manual there are few number of inputs and outputs for each component.

Would that mean it is more efficient to use an execcomp that takes in two inputs from from an explicit component and outputs a constraint instead of doing everything within the explicitcomp. I try to come up with an example here:

x1,x2 --> ExplicitComp -->y1 

y1    --> Execcomp --->constraint

OR

x1,x2 --->ExplicitComp -->y1,constraint

Solution

  • What the comment in that paper is referring to is not computational efficiency, but rather the benefit to the user in terms of making models more modular and maintainable. Additionally, when you have smaller components with fewer inputs, it is much easier to compute analytic derivatives for them.

    The idea is that by breaking your calculation up into smaller steps, the partial derivatives are them simpler for you to compute by hand. OpenMDAO will then compute the total derivatives across the model for you.

    So in a sense, you're leaning on OpenMDAO's ability to compute derivatives across large models to lessen your work load.

    From a computational cost perspective, there is some cost associated with having more components vs less. Taken to the extreme, if you had one component for each line of code in a huge calculation then the framework overhead could become a problem. There are some features in OpenMDAO that can help mitigate some of this cost, specifically the in-memory assembly of Jacobians, for serial models.

    With regard to the ExecComp specifically, that component is meant for simple and inexpensive calculations. It computes its derivatives using complex-step, which can be costly if large array inputs are involved. Its there to make simple steps like adding variables easier. But for expensive calculations, you shouldn't use it.

    In your specific case, I would suggest that you consider if it is hard to propogate the derivatives from x1,x1 through to the constraint yourself. If the chain rule is not hard to handle, then probably I would just lump it all into one calculation. If for some reason, the derivatives are nasty when you combine all the calculations, then just split them up.