Phase transitions and phase fraction calculations in Pb-Sn

To plot and investigate the phase transitions and phase fraction calculations in the Pb-Sn system, a vertical section of the phase diagram is analysed at 30%wt Sn and 70%wt Pb.

The necessary thermodynamic data is stored in the file pbsn.dat.

Loading datafile and preparing the calculation

A ThermochemicalSystem is typically instantiated by loading a .dat or .cst file.

To set the units is a good precaution. The inputs to the settings are 'guarded' by using enumerations that only allow certain limits of inputs. Therefore, we need to import the respective enums for pressure, volume, temperature, energy and amounts.

Performing a one-dimensional phase mapping

To find the phase transitions and mixture of phase components, we want to look at the vertical section at 30wt% Sn and 70wt% of Pb, so we set these as incoming amounts (notice that we changed the units to 'gram' accordingly.)

We will use the PhaseMapCalculation object for this.

Now, doing the phase mapping is a s simple as just calling the calculate_ph_txs_T routine, which finds all phase status changes in a given temperature range.

Similarly, calculate_ph_txs_P would do the same with pressure, and calculate_ph_txs_IA with changes in composition.

It returns a list of ResultObjects, which have some nice properties we will explore next.

Inquiring the CalculationResult object

The results object is a somewhat rich collection of results that can be accessed by properties and routines.

We are iterating over the reversed list of results, so that higher temperatures are at the top.

To get a glimpse at the data, we look at the phases that have an activity of 1 and an amount greater than 0, so all stable phases.

We use some simple print commands to inquire about the data. There are two transition points in the calculated range, so the results should show these, and further include the start and end of the investigated range.

Since we are interested to find the exact transition temperatures, we can iterate over the T property of the Result object. This gives us a simple python list.

Now to do some more calculations for the cooling and phase transitions, we will generate a list of temperatures in the temperature range, and explicitly add the transition temperatures.

It is simply a matter of iterating over the generated temperatures to collect all the necessary data. ChemApp for Python would typically remove old calculation results when doing a new calculation. Therefore, we explicitly use the get_result_object() routine to keep a persistent copy of the result.

Notably, now we use functions from the EquilibriumCalculation class, and not the PhaseMapCalculation anymore. This is possible since the underlying thermodynamic system hasn't changed, and the underlying instance of ChemAppBasic maintains this state.

Using pandas to quickly get beautiful plots

To plot the different stable phases and their phase amounts over the temperature range, we resort to the pandas module library. We simply fill a DataFrame with the respective data.

Now, plotting the data is as easy as calling one of the plotting routines of DataFrames, namely in this case, an area plot which automatically colors the area under the plot.

This is okay, but looks much better and comprehensible when we add the stacked=False parameter to it. To show the significant transition points, we will also add these as markers on the x axis, with the exact numbers as labels.