コード例 #1
0
ファイル: test_decomposition.py プロジェクト: vova292/pyomo
    def simple_recycle_run(self, tear_method, tol_type):
        rel = tol_type == "rel"
        m = self.simple_recycle_model()

        def function(unit):
            unit.initialize()

        seq = SequentialDecomposition(tear_method=tear_method,
                                      tol_type=tol_type)
        tset = [m.stream_splitter_to_mixer]
        seq.set_tear_set(tset)
        splitter_to_mixer_guess = {
            "flow": {
                "A": 0,
                "B": 0,
                "C": 0
            },
            "temperature": 450,
            "pressure": 128
        }
        seq.set_guesses_for(m.mixer.inlet_side_2, splitter_to_mixer_guess)
        # need to set guesses for expression members by initializing those vars
        m.mixer.expr_var_idx_in_side_2["A"] = 0
        m.mixer.expr_var_idx_in_side_2["B"] = 0
        m.mixer.expr_var_idx_in_side_2["C"] = 0
        m.mixer.expr_var_in_side_2 = 0
        seq.run(m, function)

        self.check_recycle_model(m, rel=rel)
コード例 #2
0
ファイル: test_decomposition.py プロジェクト: vova292/pyomo
    def extensive_recycle_run(self, tear_method, tol_type):
        rel = tol_type == "rel"
        m = self.extensive_recycle_model()

        def function(unit):
            unit.initialize()

        seq = SequentialDecomposition(tear_method=tear_method,
                                      tol_type=tol_type)
        tset = [m.stream_splitter_to_mixer]
        seq.set_tear_set(tset)
        splitter_to_mixer_guess = {
            "flow": {
                "A": [(m.stream_splitter_to_mixer, 0)],
                "B": [(m.stream_splitter_to_mixer, 0)],
                "C": [(m.stream_splitter_to_mixer, 0)]
            },
            "mass": [(m.stream_splitter_to_mixer, 0)],
            "expr_idx": {
                "A": [(m.stream_splitter_to_mixer, 0)],
                "B": [(m.stream_splitter_to_mixer, 0)],
                "C": [(m.stream_splitter_to_mixer, 0)]
            },
            "expr": [(m.stream_splitter_to_mixer, 0)],
            "temperature": 450,
            "pressure": 128
        }
        seq.set_guesses_for(m.mixer.inlet, splitter_to_mixer_guess)
        seq.run(m, function)

        self.check_recycle_model(m, rel=rel)

        if rel:
            s = value(m.prod.inlet.mass)
            d = value(m.feed.outlet.mass)
            self.assertAlmostEqual((s - d) / s, 0, places=5)
        else:
            self.assertAlmostEqual(value(m.prod.inlet.mass),
                                   value(m.feed.outlet.mass),
                                   places=5)
コード例 #3
0
ファイル: test_decomposition.py プロジェクト: vova292/pyomo
    def test_select_tear_in_run(self):
        m = self.simple_recycle_model()

        def function(unit):
            unit.initialize()

        seq = SequentialDecomposition()
        tset = [m.stream_splitter_to_mixer]
        seq.set_tear_set(tset)
        splitter_to_mixer_guess = {
            "flow": {
                "A": 0,
                "B": 0,
                "C": 0
            },
            "temperature": 450,
            "pressure": 128
        }
        seq.set_guesses_for(m.mixer.inlet_side_2, splitter_to_mixer_guess)
        # need to set guesses for expression members by initializing those vars
        m.mixer.expr_var_idx_in_side_2["A"] = 0
        m.mixer.expr_var_idx_in_side_2["B"] = 0
        m.mixer.expr_var_idx_in_side_2["C"] = 0
        m.mixer.expr_var_in_side_2 = 0
        seq.run(m, function)

        # we shouldn't need to know which streams are torn since everything
        # should already have values set so we don't need guesses, but we
        # just make sure it is able to select a tear set on its own
        seq = SequentialDecomposition(tear_solver="gams",
                                      select_tear_method="mip")
        seq.run(m, function)
        self.check_recycle_model(m)

        seq = SequentialDecomposition(tear_solver="gams",
                                      select_tear_method="heuristic")
        seq.run(m, function)
        self.check_recycle_model(m)