Пример #1
0
def test_equilibrium_solver_with_equilibrium_problem(
        partition_with_inert_gaseous_phase, chemical_system):
    problem = _create_equilibrium_problem(partition_with_inert_gaseous_phase)
    state = _create_chemical_state(chemical_system)

    # Compute equilibrium state; the amounts of CO2(g) and H2O(g) should remain the same
    solver = EquilibriumSolver(chemical_system)
    solver.setPartition(problem.partition())
    solver.solve(state, problem)

    # Assert the amounts of CO2(g) and H2O(g) are the same as initially set
    assert state.speciesAmount('CO2(g)') == 1.0
    assert state.speciesAmount('H2O(g)') == 0.001
Пример #2
0
def test_equilibrium_solver_with_chemical_state(
        partition_with_inert_gaseous_phase, chemical_system):
    state = _create_chemical_state(chemical_system)

    # Compute equilibrium state; the amounts of CO2(g) and H2O(g) should remain the same
    solver = EquilibriumSolver(chemical_system)
    solver.setPartition(partition_with_inert_gaseous_phase)

    # Set the amounts of H2O(l) and CO2(aq)
    state.setSpeciesMass('H2O(l)', 55, 'kg')
    state.setSpeciesAmount('CO2(aq)', 1, 'mol')

    # Check inert elements are taken care of when solving with state input
    solver.solve(state)

    # Assert the amounts of CO2(g) and H2O(g) are the same as initially set
    assert state.speciesAmount('CO2(g)') == 1.0
    assert state.speciesAmount('H2O(g)') == 0.001
Пример #3
0
def test_different_results(state_regression):
    from reaktoro import ChemicalEditor, ChemicalState, ChemicalSystem, Database, EquilibriumProblem, EquilibriumSolver, Partition

    database = Database('supcrt07.xml')
    editor = ChemicalEditor(database)

    aqueous_elements = ["C", "Ca", "Cl", "Fe", "H", "Na", "O", "S", "Ba", "Sr"]
    aqueous_phase = editor.addAqueousPhaseWithElements(aqueous_elements)
    assert aqueous_phase.name() == 'Aqueous'

    mineral_species = [
        "Anhydrite", "Barite", "Calcite", "Celestite", "Siderite", "Pyrrhotite"
    ]
    for mineral in mineral_species:
        editor.addMineralPhase(mineral)

    gaseous_species = ["CO2(g)", "H2S(g)", "CH4(g)"]
    editor.addGaseousPhase(gaseous_species)

    chemical_system = ChemicalSystem(editor)

    element_index = {
        e.name(): index
        for index, e in enumerate(chemical_system.elements())
    }
    species_index = {
        s.name(): index
        for index, s in enumerate(chemical_system.species())
    }
    phase_index = {
        p.name(): index
        for index, p in enumerate(chemical_system.phases())
    }

    reaktoro_case = get_reaktoro_case()

    equilibrium_problem = EquilibriumProblem(chemical_system)
    equilibrium_problem.setTemperature(reaktoro_case.temperature_in_K)
    equilibrium_problem.setPressure(reaktoro_case.pressure_in_Pa)

    partition = Partition(chemical_system)
    partition.setInertPhases([phase_index['Gaseous']])

    equilibrium_problem.setPartition(partition)

    chemical_state = ChemicalState(chemical_system)
    for name, index, molar_amount in reaktoro_case.species_amounts:
        assert index == species_index[name]
        chemical_state.setSpeciesAmount(index, molar_amount)

    equilibrium_problem.addState(chemical_state)

    solver = EquilibriumSolver(chemical_system)
    solver.setPartition(partition)

    result = solver.solve(chemical_state, equilibrium_problem)

    assert result.optimum.succeeded

    state_regression.check(chemical_state,
                           default_tol=dict(atol=1e-5, rtol=1e-14))