def test_jacobian_set_item(self, dtypes, shapes):
shape, constructor, expected_shape = shapes
dtype, value = dtypes
prob = Problem(model=Group())
comp = ExplicitSetItemComp(dtype, value, shape, constructor)
prob.model.add_subsystem('C1', comp)
prob.setup(check=False)
prob.set_solver_print(level=0)
prob.run_model()
prob.model.run_apply_nonlinear()
prob.model.run_linearize()
expected = constructor(value)
with prob.model._subsystems_allprocs[0].jacobian_context() as J:
jac_out = J['out', 'in'] * -1
self.assertEqual(len(jac_out.shape), 2)
expected_dtype = np.promote_types(dtype, float)
self.assertEqual(jac_out.dtype, expected_dtype)
assert_rel_error(self, jac_out, np.atleast_2d(expected).reshape(expected_shape), 1e-15)
评论列表
文章目录