Exemplo n.º 1
0
class HybridGSNewton(NonLinearSolver):
    def __init__(self):
        super(HybridGSNewton, self).__init__()

        self.nlgs = NLGaussSeidel()
        self.newton = Newton()

        self.nlgs.options['maxiter'] = 5
        self.newton.options['maxiter'] = 1
        self.nlgs.options['atol'] = 1e-10
        self.newton.options['atol'] = 1e-10

    def setup(self, sub):
        """ Initialize sub solvers.

        Args
        ----
        sub: `System`
            System that owns this solver.
        """
        self.nlgs.setup(sub)
        self.newton.setup(sub)

        # Declare to the world we need derivs
        self.ln_solver = self.newton.ln_solver

    def solve(self, params, unknowns, resids, system, metadata=None):

        self.nlgs.solve(params, unknowns, resids, system, metadata)
        self.newton.solve(params, unknowns, resids, system, metadata)
Exemplo n.º 2
0
    def __init__(self):
        super(HybridGSNewton, self).__init__()

        self.nlgs = NLGaussSeidel()
        self.newton = Newton()

        self.nlgs.options['maxiter'] = 5
Exemplo n.º 3
0
class GSNewtonHybrid(Newton):
    def __init__(self):
        super(GSNewtonHybrid, self).__init__()
        self.gs_solver = NLGaussSeidel()
        self.gs_solver.options["maxiter"] = 10
        self.gs_solver.options["iprint"] = 2

    def solve(self, params, unknowns, resids, system, metadata=None):
        self.gs_solver.solve(params, unknowns, resids, system, metadata)
        super(GSNewtonHybrid, self).solve(params, unknowns, resids, system, metadata)
Exemplo n.º 4
0
    def __init__(self):
        super(SellarDerivativesGrouped, self).__init__()

        self.add('px', IndepVarComp('x', 1.0), promotes=['*'])
        self.add('pz', IndepVarComp('z', np.array([5.0, 2.0])), promotes=['*'])

        mda = self.add('mda', Group(), promotes=['*'])
        mda.ln_solver = ScipyGMRES()
        mda.add('d1', SellarDis1withDerivatives(), promotes=['*'])
        mda.add('d2', SellarDis2withDerivatives(), promotes=['*'])

        self.add('obj_cmp',
                 ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
                          z=np.array([0.0, 0.0]),
                          x=0.0,
                          y1=0.0,
                          y2=0.0),
                 promotes=['*'])

        self.add('con_cmp1', ExecComp('con1 = 3.16 - y1'), promotes=['*'])
        self.add('con_cmp2', ExecComp('con2 = y2 - 24.0'), promotes=['*'])

        mda.nl_solver = NLGaussSeidel()
        mda.d1.fd_options['force_fd'] = True
        mda.d2.fd_options['force_fd'] = True

        self.ln_solver = ScipyGMRES()
Exemplo n.º 5
0
    def __init__(self):
        super(SellarDerivatives, self).__init__()

        self.add('px', IndepVarComp('x', 1.0), promotes=['x'])
        self.add('pz', IndepVarComp('z', np.array([5.0, 2.0])), promotes=['z'])

        self.add('d1',
                 SellarDis1withDerivatives(),
                 promotes=['x', 'z', 'y1', 'y2'])
        self.add('d2', SellarDis2withDerivatives(), promotes=['z', 'y1', 'y2'])

        self.add('obj_cmp',
                 ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
                          z=np.array([0.0, 0.0]),
                          x=0.0),
                 promotes=['obj', 'x', 'z', 'y1', 'y2'])

        self.add('con_cmp1',
                 ExecComp('con1 = 3.16 - y1'),
                 promotes=['con1', 'y1'])
        self.add('con_cmp2',
                 ExecComp('con2 = y2 - 24.0'),
                 promotes=['con2', 'y2'])

        self.nl_solver = NLGaussSeidel()
        self.ln_solver = ScipyGMRES()
Exemplo n.º 6
0
    def __init__(self):
        super(SellarNoDerivatives, self).__init__()

        self.add('px', IndepVarComp('x', 1.0), promotes=['x'])
        self.add('pz', IndepVarComp('z', np.array([5.0, 2.0])), promotes=['z'])

        cycle = self.add('cycle', Group(), promotes=['x', 'z', 'y1', 'y2'])
        cycle.ln_solver = ScipyGMRES()
        cycle.add('d1', SellarDis1(), promotes=['x', 'z', 'y1', 'y2'])
        cycle.add('d2', SellarDis2(), promotes=['z', 'y1', 'y2'])

        self.add('obj_cmp',
                 ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
                          z=np.array([0.0, 0.0]),
                          x=0.0),
                 promotes=['x', 'z', 'y1', 'y2', 'obj'])

        self.add('con_cmp1',
                 ExecComp('con1 = 3.16 - y1'),
                 promotes=['con1', 'y1'])
        self.add('con_cmp2',
                 ExecComp('con2 = y2 - 24.0'),
                 promotes=['con2', 'y2'])

        self.nl_solver = NLGaussSeidel()
        self.cycle.d1.deriv_options['type'] = 'fd'
        self.cycle.d2.deriv_options['type'] = 'fd'
Exemplo n.º 7
0
    def __init__(self):
        super(SellarDerivatives, self).__init__()

        self.add('px', ParamComp('x', 1.0), promotes=['*'])
        self.add('pz', ParamComp('z', np.array([5.0, 2.0])), promotes=['*'])

        self.add('d1', SellarDis1withDerivatives(), promotes=['*'])
        self.add('d2', SellarDis2withDerivatives(), promotes=['*'])

        self.add('obj_cmp', ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
                                     z=np.array([0.0, 0.0]), x=0.0, d1=0.0, d2=0.0),
                 promotes=['*'])

        self.add('con_cmp1', ExecComp('con1 = 3.16 - y1'), promotes=['*'])
        self.add('con_cmp2', ExecComp('con2 = y2 - 24.0'), promotes=['*'])

        self.nl_solver = NLGaussSeidel()
Exemplo n.º 8
0
    def test_run(self):

        root = ParallelGroup()

        root.nl_solver = NLGaussSeidel()

        root.add('C1', ParamComp('x', 5.))
        root.add('C2', ExecComp('y=x*2.0'))
        root.add('C3', ExecComp('y=x*2.0'))
        root.add('C4', ExecComp('y=x*2.0'))

        root.connect("C1.x", "C2.x")
        root.connect("C2.y", "C3.x")
        root.connect("C3.y", "C4.x")

        prob = Problem(root)
        prob.setup(check=False)
        prob.run()

        self.assertEqual(root.nl_solver.iter_count, 3)
        self.assertEqual(prob['C4.y'], 40.)
Exemplo n.º 9
0
 def __init__(self):
     super(GSNewtonHybrid, self).__init__()
     self.gs_solver = NLGaussSeidel()
     self.gs_solver.options['maxiter'] = 10
     self.gs_solver.options['iprint'] = 2