Skip to content

Instantly share code, notes, and snippets.

@bbrelje
Created April 19, 2020 21:58
Show Gist options
  • Save bbrelje/dff1d9f62d58ea5b058ff33f26de3f5b to your computer and use it in GitHub Desktop.
Save bbrelje/dff1d9f62d58ea5b058ff33f26de3f5b to your computer and use it in GitHub Desktop.
out of bounds src_indices not caught when 1D list of indices used
import openmdao.api as om
import numpy as np
import mpi4py.MPI as MPI
# The system will catch that 21 is out of bounds if specified as a list of tuples
# SRC_INDICES = [(1,),(21,)]
# The system will catch that 21 is out of bounds if it is first in the flat list
# It interprets this the same way as a list of 1D tuples
# SRC_INDICES = [21, 1]
# The system will NOT catch that 21 is out of bounds if it is not first in the flat list
# even though it's correctly interpreted the same way as the list of tuples
# where is this reading from? nobody knows
SRC_INDICES = [1, 21]
class TestComp(om.ExplicitComponent):
def initialize(self):
self.options['distributed'] = False
def setup(self):
# src_indices = 1 will not raise an error, but reads a value of 1.0 on every proc
self.add_input('x', shape=2, src_indices=SRC_INDICES, val=-2038.0)
self.add_output('y', shape=1)
self.declare_partials('y', 'x')
def compute(self, inputs, outputs):
outputs['y'] = np.sum(inputs['x'])
def compute_partials(self, inputs, J):
J['y', 'x'] = np.ones((2,))
prob = om.Problem()
model = prob.model
model.add_subsystem('p1', om.IndepVarComp('x', np.array([1.0, 3.0])))
model.add_subsystem('c3', TestComp())
model.connect("p1.x", "c3.x")
prob.setup(check=False, mode='fwd')
prob.run_model()
# list_outputs only shows the value on the first proc (0th)
prob.model.list_outputs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment