Beispiel #1
0
            def configure(self):

                self.add('comp', TestComponent())
                self.add('brent', Brent())

                self.brent.workflow.add(['comp'])
                self.driver.workflow.add(['brent'])

                # connections to comp
                self.connect('a', 'comp.a')
                self.connect('ap', 'comp.ap')
                self.connect('lambda_r', 'comp.lambda_r')

                # setup Brent
                eps = 1e-6
                self.brent.lower_bound = eps
                self.brent.upper_bound = pi/2 - eps
                self.brent.add_parameter('comp.phi')
                self.brent.add_constraint('comp.residual = 0')

                def resize(lower, upper, iter):
                    if lower == eps and upper == pi/2 - eps:
                        return -pi/4, -eps, True
                    elif lower == -pi/4 and upper == -eps:
                        return pi/2+eps, pi-eps, True
                    else:
                        return lower, upper, False

                self.brent.f_resize_bracket = resize

                # connect outputs
                self.connect('comp.phi', 'phi_star')
Beispiel #2
0
 def test_errors(self):
     a = set_as_top(Assembly())
     comp = a.add('comp', ExecComp(exprs=["f=x"]))
     driver = a.add('driver', Brent())
     driver.add_parameter('comp.x')
     driver.add_constraint('comp.f=0')
     comp.n = 1.0
     comp.c = 0
     driver.lower_bound = 1.0
     try:
         a.run()
     except Exception as err:
         self.assertEqual(str(err), "driver: bounds (low=1.0, high=100.0) do not bracket a root")
     else:
         self.fail("Exception expected")
Beispiel #3
0
    def test_brent_converge(self):

        a = set_as_top(Assembly())
        comp = a.add('comp', ExecComp(exprs=["f=a * x**n + b * x - c"]))
        comp.n = 77.0/27.0
        comp.a = 1.0
        comp.b = 1.0
        comp.c = 10.0

        driver = a.add('driver', Brent())
        driver.add_parameter('comp.x', 0, 100)
        driver.add_constraint('comp.f=0')

        a.run()

        assert_rel_error(self, a.comp.x, 2.06720359226, .0001)
        assert_rel_error(self, a.comp.f, 0, .0001)

        self.assertTrue(has_interface(driver, ISolver))
Beispiel #4
0
            def configure(self):

                self.add('comp', TestComponent())
                self.add('brent', Brent())

                self.brent.workflow.add(['comp'])
                self.driver.workflow.add(['brent'])

                # connections to comp
                self.connect('V', 'comp.V')
                self.connect('P', 'comp.P')
                self.connect('Prated', 'comp.Prated')

                # setup Brent
                self.connect('Vin', 'brent.lower_bound')
                self.connect('Vout', 'brent.upper_bound')
                self.brent.add_parameter('comp.Vrated')
                self.brent.add_constraint('comp.residual = 0')
                self.connect('invalid_bracket_return', 'brent.invalid_bracket_return')

                # connect outputs
                self.connect('comp.Vrated', 'Vrated')
    def test_initial_run(self):
        class MyComp(Component):

            x = Float(0.0, iotype='in', low=-100000, high=100000)
            xx = Float(0.0, iotype='in', low=-100000, high=100000)
            f_x = Float(iotype='out')
            y = Float(iotype='out')

            def execute(self):
                if self.xx != 1.0:
                    self.raise_exception(
                        "xx should be 1.0, but it's %s" % self.xx,
                        RuntimeError)
                self.f_x = 2.0 * self.x
                self.y = self.x

        @add_delegate(HasParameters)
        class SpecialDriver(Driver):

            implements(IHasParameters)

            def execute(self):
                self.set_parameters([1.0])
                self.workflow.run()

        top = set_as_top(Assembly())
        top.add('comp', MyComp())
        top.add('driver', Brent())
        top.add('subdriver', SpecialDriver())
        top.driver.workflow.add('subdriver')
        top.subdriver.workflow.add('comp')

        top.subdriver.add_parameter('comp.xx')
        top.driver.add_parameter('comp.x')
        top.driver.add_constraint('comp.y = 1.0')

        top.run()