Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

How do I build an OpenMDAO group that uses MuxComp to combine individual variables into an array?

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 ExplicitComponents 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'?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...