コード例 #1
0
def test_equilibrium_solver_approx_overload_3(setup, state_regression):
    """
    An integration test that checks result's reproducibility of
    the calculation of an equilibrium of a state using
    EquilibriumSolver::approximate(ChemicalState& state, double T, double P, VectorConstRef be)
    @param setup
        a tuple that has some objects from problem setup
        (system, problem)
    """
    (system, problem) = setup

    state = ChemicalState(system)

    solver = EquilibriumSolver(system)

    T = problem.temperature()
    P = problem.pressure()
    b = problem.elementAmounts()

    solver.approximate(state, T, P, b)

    exclude = ['pH [-]']

    state_regression.check(state,
                           default_tol=dict(atol=1e-5, rtol=1e-14),
                           exclude=exclude)
コード例 #2
0
def test_equilibrium_solver_approx_overload_2(setup, state_regression):
    """
    An integration test that checks result's reproducibility of 
    the calculation of an equilibrium of a state using 
    EquilibriumSolver::approximate(ChemicalState& state, const EquilibriumProblem& problem)
    @param setup
        a tuple that has some objects from problem setup
        (system, problem)
    """
    (system, problem) = setup

    state = ChemicalState(system)

    solver = EquilibriumSolver(system)

    solver.approximate(state, problem)

    state_regression.check(state, default_tol=dict(atol=1e-5, rtol=1e-16))
コード例 #3
0
def test_equilibrium_solver_approx_overload_3(setup, num_regression):
    """
    An integration test that checks result's reproducibility of 
    the calculation of an equilibrium of a state using 
    EquilibriumSolver::approximate(ChemicalState& state, double T, double P, VectorConstRef be)
    @param setup
        a tuple that has some objects from problem setup
        (system, problem)
    """
    (system, problem) = setup

    state = ChemicalState(system)

    solver = EquilibriumSolver(system)

    solver.approximate(state, problem.temperature(), problem.pressure(),
                       problem.elementAmounts())

    stateDict = convert_reaktoro_state_to_dict(state)

    num_regression.check(stateDict,
                         default_tolerance=dict(atol=1e-5, rtol=1e-16))
コード例 #4
0
def test_equilibrium_solver_approx_overload_1(setup, state_regression):
    """
    An integration test that checks result's reproducibility of
    the calculation of an equilibrium of a state using
    EquilibriumSolver::approximate(ChemicalState& state)
    @param setup
        a tuple that has some objects from problem setup
        (system, problem)
    """
    (system, problem) = setup

    state = equilibrate(problem)
    state.setTemperature(problem.temperature() + 10)
    state.setPressure(problem.pressure() + 10)

    solver = EquilibriumSolver(system)

    solver.approximate(state)

    exclude = ['pH [-]']

    state_regression.check(state,
                           default_tol=dict(atol=1e-5, rtol=1e-14),
                           exclude=exclude)
コード例 #5
0
ファイル: CubicEOS-test.py プロジェクト: qize/reaktoro
def test_CubicEOS_multiple_roots():
    """
    This problem leads to the following CubicEOS roots
    PR - Z1 = 1.00027728
         Z2 = 0.0001655
         Z3 = -0.0011024
    since bmix = 1.635e-05 -> Z3 is an invalid root 
    and since Z3 < Z2 < Z1 -> Z2 is an invalid root.
    Reaktoro should remove Z3, Z2 and proceed instead of removing only Z3 and
    raising the exception "Logic error: it was expected Z roots of size 3, but
    got: 2".
    """
    database = Database("supcrt98.xml")

    editor = ChemicalEditor(database)
    editor.addAqueousPhaseWithElementsOf("H2O Fe(OH)2 Fe(OH)3 NH3")
    editor.addGaseousPhaseWithElementsOf("NH3")
    editor.addMineralPhase("Magnetite")

    system = ChemicalSystem(editor)

    state = ChemicalState(system)

    solver = EquilibriumSolver(system)

    temperature = 298.15
    pressure = 1e5
    b = [
        3.0,
        122.01687012,
        1.0,
        63.50843506,
        0.0,
    ]

    result = solver.approximate(state, temperature, pressure, b)
    assert result.optimum.succeeded

    # check that it doesn't raise an exception
    state.properties()