Ejemplo n.º 1
0
def test_equilibrium_CH4_CO2_H2S_liq_gas(temperature, pressure,
                                         num_regression):
    """
    This test checks the capability of solving a ternary mixture with
    @param Temperature
        temperature in Kelvin which will be used to compute equilibrium
    @param Pressure
        pressure in bar which will be used to compute equilibrium
    """

    db = Database("supcrt98.xml")

    editor = ChemicalEditor(db)

    eos_params = CubicEOSParams(
        phase_identification_method=PhaseIdentificationMethod.
        GibbsEnergyAndEquationOfStateMethod, )

    editor.addGaseousPhase(["CH4(g)", "H2S(g)",
                            "CO2(g)"]).setChemicalModelPengRobinson(eos_params)
    editor.addLiquidPhase(["CH4(liq)", "H2S(liq)", "CO2(liq)"
                           ]).setChemicalModelPengRobinson(eos_params)

    system = ChemicalSystem(editor)

    problem = EquilibriumProblem(system)

    problem.setTemperature(temperature, "K")
    problem.setPressure(pressure, "bar")
    problem.add("CH4(g)", 0.60, "mol")
    problem.add("H2S(g)", 0.35, "mol")
    problem.add("CO2(g)", 0.05, "mol")

    solver = EquilibriumSolver(problem.system())

    options = EquilibriumOptions()
    options.hessian = GibbsHessian.Exact
    options.nonlinear.max_iterations = 100
    options.optimum.max_iterations = 200
    options.optimum.ipnewton.step = StepMode.Conservative

    solver.setOptions(options)

    state = ChemicalState(system)

    result = solver.solve(state, problem)

    assert result.optimum.succeeded

    species_amount = {
        "CH4(g)": np.asarray([state.speciesAmount("CH4(g)")]),
        "H2S(g)": np.asarray([state.speciesAmount("H2S(g)")]),
        "CO2(g)": np.asarray([state.speciesAmount("CO2(g)")]),
        "CH4(liq)": np.asarray([state.speciesAmount("CH4(liq)")]),
        "H2S(liq)": np.asarray([state.speciesAmount("H2S(liq)")]),
        "CO2(liq)": np.asarray([state.speciesAmount("CO2(liq)")]),
    }

    num_regression.check(species_amount)
Ejemplo n.º 2
0
def test_equilibrium_H2S_liq_gas(temperature, pressure, num_regression):
    db = Database("supcrt98.xml")

    editor = ChemicalEditor(db)

    eos_params = CubicEOSParams(
        model=CubicEOSModel.PengRobinson,
        phase_identification_method=PhaseIdentificationMethod.
        GibbsEnergyAndEquationOfStateMethod,
    )

    editor.addGaseousPhase(["H2S(g)"]).setChemicalModelCubicEOS(eos_params)
    editor.addLiquidPhase(["H2S(liq)"]).setChemicalModelCubicEOS(eos_params)

    system = ChemicalSystem(editor)

    problem = EquilibriumProblem(system)

    problem.setTemperature(temperature, "K")
    problem.setPressure(pressure, "Pa")
    problem.add("H2S(g)", 1.0, "mol")

    solver = EquilibriumSolver(problem.system())

    options = EquilibriumOptions()
    options.hessian = GibbsHessian.Exact
    options.nonlinear.max_iterations = 100
    options.optimum.max_iterations = 200
    options.optimum.ipnewton.step = StepMode.Conservative
    options.optimum.tolerance = 1e-17
    solver.setOptions(options)

    state = ChemicalState(system)

    result = solver.solve(state, problem)

    assert result.optimum.succeeded

    species_amounts = {
        "H2S(g)": np.asarray([state.speciesAmount("H2S(g)")]),
        "H2S(liq)": np.asarray([state.speciesAmount("H2S(liq)")]),
    }

    num_regression.check(species_amounts)
Ejemplo n.º 3
0
def test_equilibrium_CH4_H2S_CO2_H2O_liq_gas_aq(temperature, pressure,
                                                num_regression):
    """
    This test checks the capability of solving a system that has CH4, H2S,
    CO2, H2O with
    @param Temperature
        temperature in Kelvin which will be used to compute equilibrium
    @param Pressure
        pressure in bar which will be used to compute equilibrium
    """

    db = Database("supcrt98.xml")

    editor = ChemicalEditor(db)

    eos_params = CubicEOSParams(
        phase_identification_method=PhaseIdentificationMethod.
        GibbsEnergyAndEquationOfStateMethod, )

    editor.addAqueousPhase(["CO2(aq)", "H2S(aq)", "H2O(l)"])
    editor.addGaseousPhase(["CH4(g)", "CO2(g)", "H2S(g)",
                            "H2O(g)"]).setChemicalModelCubicEOS(eos_params)
    editor.addLiquidPhase(["CH4(liq)", "CO2(liq)", "H2S(liq)",
                           "H2O(liq)"]).setChemicalModelCubicEOS(eos_params)

    system = ChemicalSystem(editor)

    problem = EquilibriumProblem(system)

    problem.setTemperature(temperature, "K")
    problem.setPressure(pressure, "bar")
    problem.add("H2O(g)", 0.50, "mol")
    problem.add("CO2(g)", 0.05, "mol")
    problem.add("H2S(g)", 0.40, "mol")
    problem.add("CH4(g)", 0.05, "mol")

    # This is a workaround to avoid an Eigen assertion when in Debug:
    # `DenseBase::resize() does not actually allow to resize.`, triggered by `y(iee) = optimum_state.y * RT;`
    problem.add("Z", 1e-15, "mol")

    solver = EquilibriumSolver(problem.system())

    options = EquilibriumOptions()
    options.hessian = GibbsHessian.Exact
    options.nonlinear.max_iterations = 100
    options.optimum.max_iterations = 200
    options.optimum.ipnewton.step = StepMode.Conservative
    options.optimum.tolerance = 1e-14
    solver.setOptions(options)

    state = ChemicalState(system)

    result = solver.solve(state, problem)

    assert result.optimum.succeeded

    species_amount = {
        "CO2(aq)": np.asarray([state.speciesAmount("CO2(g)")]),
        "H2S(aq)": np.asarray([state.speciesAmount("H2S(aq)")]),
        "H2O(l)": np.asarray([state.speciesAmount("H2O(l)")]),
        "CH4(g)": np.asarray([state.speciesAmount("CH4(g)")]),
        "CO2(g)": np.asarray([state.speciesAmount("CO2(g)")]),
        "H2S(g)": np.asarray([state.speciesAmount("H2S(g)")]),
        "H2O(g)": np.asarray([state.speciesAmount("H2O(g)")]),
        "CH4(liq)": np.asarray([state.speciesAmount("CH4(liq)")]),
        "CO2(liq)": np.asarray([state.speciesAmount("CO2(liq)")]),
        "H2S(liq)": np.asarray([state.speciesAmount("H2S(liq)")]),
        "H2O(liq)": np.asarray([state.speciesAmount("H2O(liq)")]),
    }

    num_regression.check(species_amount)