def test_generate_delaunay(self): vlist = variable_list() vlist.append(variable(lb=0, ub=1)) vlist.append(variable(lb=1, ub=2)) vlist.append(variable(lb=2, ub=3)) if not (util.numpy_available and util.scipy_available): with self.assertRaises(ImportError): util.generate_delaunay(vlist) else: tri = util.generate_delaunay(vlist, num=2) self.assertTrue(isinstance(tri, util.scipy.spatial.Delaunay)) self.assertEqual(len(tri.simplices), 6) self.assertEqual(len(tri.points), 8) tri = util.generate_delaunay(vlist, num=3) self.assertTrue(isinstance(tri, util.scipy.spatial.Delaunay)) self.assertEqual(len(tri.simplices), 62) self.assertEqual(len(tri.points), 27) # # Check cases where not all variables are bounded # vlist = variable_list() vlist.append(variable(lb=0)) with self.assertRaises(ValueError): util.generate_delaunay(vlist) vlist = variable_list() vlist.append(variable(ub=0)) with self.assertRaises(ValueError): util.generate_delaunay(vlist)
def setUpModule(): global _test_v global _test_tri global _test_values if util.numpy_available and util.scipy_available: _test_v = variable_list(variable(lb=i, ub=i + 1) for i in range(3)) _test_tri = util.generate_delaunay(_test_v, num=4) _test_values = [] for _xi in _test_tri.points: _test_values.append(sum(_xi)) _test_values = util.numpy.array(_test_values)
def test_call(self): # # 2d points # vlist = variable_list([variable(lb=0, ub=1), variable(lb=0, ub=1)]) tri = util.generate_delaunay(vlist, num=3) x, y = tri.points.T values = x * y g = PiecewiseLinearFunctionND(tri, values) f = TransformedPiecewiseLinearFunctionND(g) self.assertTrue(f.parent is None) self.assertEqual(f.ctype, IBlock) self.assertTrue(util.numpy.isclose(f(tri.points), values).all()) self.assertAlmostEqual(f([0, 0]), 0.0) self.assertAlmostEqual(f(util.numpy.array([0, 0])), 0.0) self.assertAlmostEqual(f([1, 1]), 1.0) self.assertAlmostEqual(f(util.numpy.array([1, 1])), 1.0) # # 3d points # vlist = variable_list( [variable(lb=0, ub=1), variable(lb=0, ub=1), variable(lb=0, ub=1)]) tri = util.generate_delaunay(vlist, num=10) x, y, z = tri.points.T values = x * y * z g = PiecewiseLinearFunctionND(tri, values) f = TransformedPiecewiseLinearFunctionND(g) self.assertTrue(f.parent is None) self.assertEqual(f.ctype, IBlock) self.assertTrue(util.numpy.isclose(f(tri.points), values).all()) self.assertAlmostEqual(f([0, 0, 0]), 0.0) self.assertAlmostEqual(f(util.numpy.array([0, 0, 0])), 0.0) self.assertAlmostEqual(f([1, 1, 1]), 1.0) self.assertAlmostEqual(f(util.numpy.array([1, 1, 1])), 1.0)