def test_add_phases_with_elements_of_right_use(): """Test the normal use of addAqueousPhaseWithElementsOf, addGaseousPhaseWithElementsOf and addMineralPhaseWithElementsOf.""" editor1 = ChemicalEditor() editor1.addAqueousPhaseWithElementsOf("H2O Ca") editor1.addGaseousPhaseWithElementsOf("CO2 H") editor1.addMineralPhaseWithElementsOf("CaCO3") editor2 = ChemicalEditor() editor2.addAqueousPhaseWithElementsOf(["H2O", "Ca"]) editor2.addGaseousPhaseWithElementsOf(["CO2", "H"]) editor2.addMineralPhaseWithElementsOf(["CaCO3"]) system1 = ChemicalSystem(editor1) system2 = ChemicalSystem(editor2) _check_equivalent_chemical_systems(system1, system2)
def equilibrium_problem_with_h2o_feoh2_feoh3_nh3_magnetite(): """ Build a problem with H2O, Fe(OH)2, Fe(OH)3, NH3 and Magnetite """ 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) problem = EquilibriumProblem(system) problem.add("H2O", 1, "kg") problem.add("Fe(OH)2", 1, "mol") problem.add("Fe(OH)3", 2, "mol") problem.add("NH3", 1, "mol") return (system, problem)
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()