def setUp(self):
        dm.options['include_check_partials'] = True

        self.p = om.Problem(model=om.Group())

        ivp = self.p.model.add_subsystem('ivc',
                                         subsys=om.IndepVarComp(),
                                         promotes_outputs=['*'])

        ivp.add_output('pos', val=np.zeros((100, 3)))
        self.p.model.add_design_var('pos', lower=0, upper=100)

        bv_comp = self.p.model.add_subsystem(
            'bv_comp', BoundaryConstraintComp(loc='initial'))
        bv_comp._add_constraint(name='pos', shape=(3, ))

        src_idxs = np.array([0, 1, 2], dtype=int)

        self.p.model.connect('pos',
                             'bv_comp.initial_value_in:pos',
                             src_indices=src_idxs,
                             flat_src_indices=True)

        self.p.setup(force_alloc_complex=True)

        self.p['pos'][:, 0] = np.arange(100)
        self.p['pos'][:, 1] = 100 + np.arange(100)
        self.p['pos'][:, 2] = 200 + np.arange(100)

        self.p.run_model()
Exemplo n.º 2
0
    def setUp(self):

        self.p = om.Problem(model=om.Group())

        ivp = self.p.model.add_subsystem('ivc', subsys=om.IndepVarComp(), promotes_outputs=['*'])

        ivp.add_output('M', val=np.zeros((100, 3, 3)))
        self.p.model.add_design_var('M', lower=0, upper=100)

        bv_comp = self.p.model.add_subsystem('bv_comp', BoundaryConstraintComp(loc='final'))
        bv_comp._add_constraint(name='M', shape=(3, 3))

        src_idxs = np.array([[-9, -8, -7], [-6, -5, -4], [-3, -2, -1]])

        self.p.model.connect('M', 'bv_comp.final_value_in:M', src_indices=src_idxs,
                             flat_src_indices=True)

        self.p.setup(force_alloc_complex=True)

        self.p['M'][:, 0, 0] = np.arange(100)
        self.p['M'][:, 0, 1] = 100 + np.arange(100)
        self.p['M'][:, 0, 2] = 200 + np.arange(100)

        self.p['M'][:, 1, 0] = 1000 + np.arange(100)
        self.p['M'][:, 1, 1] = 1000 + 100 + np.arange(100)
        self.p['M'][:, 1, 2] = 1000 + 200 + np.arange(100)

        self.p['M'][:, 2, 0] = 2000 + np.arange(100)
        self.p['M'][:, 2, 1] = 2000 + 100 + np.arange(100)
        self.p['M'][:, 2, 2] = 2000 + 200 + np.arange(100)

        self.p.run_model()
Exemplo n.º 3
0
    def setUp(self):

        self.p = om.Problem(model=om.Group())

        ivp = self.p.model.add_subsystem('ivc', subsys=om.IndepVarComp(), promotes_outputs=['*'])

        ivp.add_output('M', val=np.zeros((100, 3, 3)))
        ivp.add_output('pos', val=np.zeros((100, 3)))
        ivp.add_output('x', val=np.zeros((100,)))

        self.p.model.add_design_var('M', lower=0, upper=100)
        self.p.model.add_design_var('pos', lower=0, upper=100)
        self.p.model.add_design_var('x', lower=0, upper=100)

        bv_comp = self.p.model.add_subsystem('bv_comp', BoundaryConstraintComp(loc='initial'))

        M_shape = (3, 3)
        M_size = np.prod(M_shape)
        bv_comp._add_constraint(name='M', shape=M_shape)
        src_idxs = np.arange(M_size, dtype=int).reshape(M_shape)
        self.p.model.connect('M', 'bv_comp.initial_value_in:M', src_indices=src_idxs,
                             flat_src_indices=True)

        pos_shape = (3,)
        pos_size = np.prod(pos_shape)
        bv_comp._add_constraint(name='pos', shape=pos_shape)
        src_idxs = np.arange(pos_size, dtype=int).reshape(pos_shape)
        self.p.model.connect('pos', 'bv_comp.initial_value_in:pos', src_indices=src_idxs,
                             flat_src_indices=True)

        x_shape = (1,)
        x_size = np.prod(x_shape)
        bv_comp._add_constraint(name='x', shape=x_shape)
        src_idxs = np.arange(x_size, dtype=int).reshape(x_shape)
        self.p.model.connect('x', 'bv_comp.initial_value_in:x', src_indices=src_idxs,
                             flat_src_indices=True)

        self.p.setup(force_alloc_complex=True)

        self.p['M'][:, 0, 0] = np.arange(100)
        self.p['M'][:, 0, 1] = 100 + np.arange(100)
        self.p['M'][:, 0, 2] = 200 + np.arange(100)

        self.p['M'][:, 1, 0] = 1000 + np.arange(100)
        self.p['M'][:, 1, 1] = 1000 + 100 + np.arange(100)
        self.p['M'][:, 1, 2] = 1000 + 200 + np.arange(100)

        self.p['M'][:, 2, 0] = 2000 + np.arange(100)
        self.p['M'][:, 2, 1] = 2000 + 100 + np.arange(100)
        self.p['M'][:, 2, 2] = 2000 + 200 + np.arange(100)

        self.p['pos'][:, 0] = 100000 + np.arange(100)
        self.p['pos'][:, 1] = 100000 + 100 + np.arange(100)
        self.p['pos'][:, 2] = 100000 + 200 + np.arange(100)

        self.p.run_model()
Exemplo n.º 4
0
    def setUp(self):

        self.p = om.Problem(model=om.Group())

        ivp = self.p.model.add_subsystem('ivc', subsys=om.IndepVarComp(), promotes_outputs=['*'])

        ivp.add_output('x', val=np.arange(100))
        self.p.model.add_design_var('x', lower=0, upper=100)

        bv_comp = self.p.model.add_subsystem('bv_comp', BoundaryConstraintComp(loc='final'))
        bv_comp._add_constraint(name='x', shape=(1,))

        self.p.model.connect('x', 'bv_comp.final_value_in:x', src_indices=[-1])

        self.p.setup(force_alloc_complex=True)
        self.p.run_model()