Tutorials --------- This section provides examples to show you how to use the ChemApp for Python ``friendly`` module function groups. The examples are small bits of code that you can use to build a full size investigation. Working with ``Info`` Functions ******************************* The easiest way to get all the information about ChemApp, is by requesting a ``ChemAppInfo`` object, and printing it. Here is an example, code: ``30-friendly/Info/01-basic-use.py`` .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/Info/01-basic-use.py Here is the result: .. code-block:: none ======================================================================== ChemApp Information ------------------------------------------------------------------------ Class: ChemAppInfo Program ID: CAFU Version: 816 Is Light: False Expiration date: 2022/7 User ID: 1234 User Name: Acme Ltd. Dongle Type: Dongle ID: 0 Copyright: This program contains ChemApp. Copyright GTT-Technologies, Kaiserstrasse 103, D-52134 Herzogenrath, Germany. http://www.gtt-technologies.de ------------------------------------------------------------------------- Array Sizes: Item Maximum Used Description na 3000 3000 Number of constituents nb 48 48 Number of system components nc 150 150 Number of mixture phases nd 2000 2000 Number of excess Gibbs energy coefficients for a mixture phase ne 500 500 Number of excess magnetic coefficients for a mixture phase nf 5 5 Number of sublattices for a mixture phase ng 3000 3000 Number of constituents of a sublattice nh 48 48 Number of oxide constituents of a phase described by the Gaye-Kapoor-Frohberg or modified quasichemical formalisms ni 20 20 Number of Gibbs energy/heat capacity equations for a constituent nj 20000 20000 Number of Gibbs energy/heat capacity equations nk 3000 3000 Number of constituents with P,T-dependent molar volumes =========================================================================== You can also use individual functions in the ``Info`` group, and you can use individual properties of ``ChemAppInfo`` objects that you obtain from the Info group. This provides ample flexibility for doing what you need. You can use the help function in python to find other functions of the ``Info`` functions. Working with ``Units`` Functions ******************************** Checking Units ^^^^^^^^^^^^^^ It is good practise to check the current units in ChemApp for Python before doing calculations. This can be done by printing them. Here is an example based on this example code: ``30-friendly/Units/01-basic-use.py`` .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/Units/01-basic-use.py Here is the result: .. code-block:: none Units Currently Used by ChemApp =============================== Pressure: bar Volume: dm3 Temperature: K Energy: J Amount: mol Changing Units ^^^^^^^^^^^^^^ It is simple to change any of the units in ChemApp for Python. To change the pressure unit, here is an example, the code is found here: ``30-friendly/Units/02-change-unit.py`` .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/Units/02-change-unit.py To check that the units are now correct you can print the unit again. The result is: .. code-block:: none PressureUnit.atm Working with ``Thermochemical`` Functions ***************************************** Load thermochemical datafile ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Before being able to do equilibrium calculations with ChemApp for Python you need to create a thermochemical system. You do this by loading a thermochemical data file, see the example below. This refers to ``30-friendly/ThermochemicalSystem/01-basic-use.py`` .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/ThermochemicalSystem/01-basic-use.py To check if the thermochemical data file was loaded you can print it. It is useful to save the printed information in a text file so that you can refer to it later. Getting the molar mass ^^^^^^^^^^^^^^^^^^^^^^ You can get the molar mass of a particular phase, phase constituent or system component. This example is for a phase constituent, and the example code can be found here: ``30-friendly/ThermochemicalSystem/055-get-molar-mass.py``. .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/ThermochemicalSystem/05-get-molar-mass.py The molar mass is: .. code-block:: none 12.010700000000002 Get Y (mass fraction) of a system component or phase constituent ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can get the mass fraction of a phase constituent in a phase or the mass fraction of a system component in a phase constituent. The example below shows how to calculate the mass fraction of carbon in carbon monoxide in the gas phase. This example refers to ``30-friendly/ThermochemicalSystem/03-get-mass-fraction.py``: .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/ThermochemicalSystem/03-get-mass-fraction.py Result: .. code-block:: none 0.42880501528003884 Set the status of a phase ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Before running a calculation, you can set the status of a particular phase or phase constituent. The options are ENTERED, ELIMINTATED or DORMANT. Here is an example. The code is: ``30-friendly/ThermochemicalSystem/04-set-phase-status.py`` .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/ThermochemicalSystem/04-set-phase-status.py The result: .. code-block:: none Status.ENTERED Working with ``EquilibriumCalculation`` Functions ************************************************** Equilibrium calculation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ One can do simple equilibrium calculation in ChemApp for Python. The example below shows how to calculate the mass of liquid alloy formed when heating up cementite with pure carbon. Here is an example, the code is here: ``30-friendly/EquilibriumCalculation/01-basic-use.py``. .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/EquilibriumCalculation/01-basic-use.py The mass of liquid alloy formed is: .. code-block:: none Liquid-alloy: 493.640494 kg Target equilibrium calculation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It is also possible to set the target formation phase for the calculation. Here is an example to do this, code: ``30-friendly/EquilibriumCalculation/02-set-target-eq-condition.py`` In this example we calculate the temperature at which liquid alloy starts forming: .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/EquilibriumCalculation/02-set-target-eq-condition.py Result: .. code-block:: none 1153.4357094806123 C Working with ``StreamCalculation`` Functions ************************************************** Equilibrium calculation with two streams ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ An example of a simple stream calculation is to calculate the amount of energy required or change in energy when smelting iron oxide with graphite at a high temperature. Here is an example, see code: ``30-friendly/StreamCalculation/01-basic-use.py`` .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/StreamCalculation/01-basic-use.py Results: .. code-block:: none dH reaction: 73.290423 kWh Target calculation with stream calculation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can also calculate the equilibrium by seting a formation or precipitation phase target. This is an example of a target precipitation phase, ``30-friendly/StreamCalculation/02-set-target-eq-condition.py`` .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/StreamCalculation/02-set-target-eq-condition.py The result: .. code-block:: none 1153.4358038309547 Working with ``PhaseMap`` Functions ************************************ These functions allow one-dimensional phase mapping. To use these functions, one of three variables can be adjusted; pressure, temperature or composition. Equilibrium calculation with two streams ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Phase transitions can be determined by varying the temperature. See the example, ``30-friendly/PhaseMapCalculation/01-basic-use.py``. .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/PhaseMapCalculation/01-basic-use.py .. code-block:: none Temperature (K) Stable Phases Amount (mol) 300.000000 BCT_A5#1 0.178784 FCC_A1 0.821216 454.561924 BCT_A5#1 0.038190 FCC_A1 0.961810 541.876513 LIQUID 1.000000 700.000000 LIQUID 1.000000 Vary incoming amounts to get phase transition ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can use composition to find the phase transitions as well. In this case you will keep temperature and pressure constant. See this example, ``30-friendly/PhaseMapCalculation/02-incoming-amounts-variation.py`` .. literalinclude:: C:\Users\Florian Tang\ChemAppDoc\build\factsage\1.0.4\source\examples/30-friendly/PhaseMapCalculation/02-incoming-amounts-variation.py The result: .. code-block:: none X(Fe2SiO4) X(Mg2SiO4) Stable Phases Amount (mol) 0.000000 1.000000 Olivine 1.000000 0.200000 0.800000 Olivine 1.000000