Reputation: 83
I'd like to create an OpenMDAO om.Group
that rearranges a some scalar variables into arrays. I'd like it to have a certain set of named inputs and outputs, like
class IonMixMux(om.Group):
r"""Multiplex ion data into arrays
Inputs
------
nA : float
m**-3, Species A density
nB : float
m**-3, Species B density
nC : float
m**-3, Species C density
AC : float
kg, Mass of species C
Outputs
-------
n : array
m**-3, Species densities
A : array
kg, Species masses
"""
The output n
should equal [nA, nB, nC]
, and the output A
should equal [1, 2, AC]
, since species A and B always have masses 1 and 2, respectively.
As I understand it, joining values together into an array can (only?) be done using MuxComp
. However, I'm not sure how to build a Group that does this. Normally I make a Group
of ExplicitComponent
s that have their own inputs and outputs, which then may be promoted so that it looks like the Group itself has these inputs or outputs.
I'm not sure how to make the promotion of named inputs without having a subcomponent to the group, and also not sure how to set individual indices of an OpenMDAO array.
Is this in fact not a job for MuxComp
at all? Can I instead simply build an ExplicitComponent that build arrays 'from scratch'?
Upvotes: 1
Views: 90
Reputation: 2704
This is currently not within the capability of MuxComp, which assumes that an array output n
has some number of inputs named n_0
, n_1
, n_2
, ...
We could consider adding this capability to the API if it's a very common use-case, but it's pretty easy to build an ExplicitComponent for this case and build the output arrays in compute. The partials in this case are all linear and so can be specified in setup with declare_partials
:
self.declare_partials(of='A', wrt='AC', rows=[0], cols=[2], val=1.0)
self.declare_partials(of='n', wrt='nA', rows=[0], cols=[0], val=1.0)
self.declare_partials(of='n', wrt='nB', rows=[1], cols=[0], val=1.0)
self.declare_partials(of='n', wrt='nC', rows=[2], cols=[0], val=1.0)
Upvotes: 2