This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | tutorials:t19 [2019/08/02 15:06] – [Complimentary files] pwarczok | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== T19: Scripting precipitation calculations ===== | ||
+ | //This tutorial was tested on \\ | ||
+ | MatCalc version 6.02 rel 1.003 \\ | ||
+ | license: free \\ | ||
+ | database: mc_fe.tdb, mc_fe.ddb // | ||
+ | |||
+ | The use of **scripting** to help ensure repeatability of calculations and to simplify | ||
+ | |||
+ | ==== Complimentary files ==== | ||
+ | |||
+ | Click {{: | ||
+ | |||
+ | ==== Contents ==== | ||
+ | |||
+ | * Setting up precipitation domains | ||
+ | * Setting up precipitate phases | ||
+ | * Scripting a complex heat-treatment | ||
+ | * Modifying precipiation parameters during heat-treatment | ||
+ | * Plotting using scripts | ||
+ | |||
+ | The example used here uses the already familiar Fe-Nb-C system and considers a heat-treatment of an initially well-annealed ferritic microstructure with no primary precipitates. Cementite is initially allowed to nucleate on dislocations, | ||
+ | |||
+ | ===== Setting up the system and thermodynamics ===== | ||
+ | |||
+ | Start the script by with two lines to make sure the right module (the core module) is used, and to create a new workspace: | ||
+ | < | ||
+ | new-workspace </ | ||
+ | |||
+ | The following code can be used to check that the correct version of MatCalc is being used. This is useful when scripts rely on functionality that is only available in newer versions of the software. The code '' | ||
+ | |||
+ | < | ||
+ | if (matcalc_version< | ||
+ | send-dialog-string " | ||
+ | stop-run-script | ||
+ | endif</ | ||
+ | |||
+ | Scripts should be well commented to ensure that they can be easily understood later. See [[tutorials: | ||
+ | |||
+ | Some information on the physical situation to be modelled and the assumptions made can be inserted into the MatCalc workspace for future reference. | ||
+ | |||
+ | < | ||
+ | @$************************************ | ||
+ | $ enter workspace info | ||
+ | @$************************************ | ||
+ | |||
+ | @ set-workspace-info Script T19 | ||
+ | @ set-workspace-info +Calculation of precipitation | ||
+ | @ set-workspace-info +in Fe-0.1C-0, | ||
+ | @ set-workspace-info +during a complex heat treatment | ||
+ | @ set-workspace-info +with phases BCC_A2, FCC_A1 and CEMENTITE. | ||
+ | </ | ||
+ | |||
+ | The thermodynamic setup is then carried out. Firstly, the database is chosen and the selements and phases are selected. The database is then read. | ||
+ | |||
+ | < | ||
+ | open-thermodynamic-database mc_fe.tdb | ||
+ | select-elements FE C NB VA | ||
+ | select-phases BCC_A2 FCC_A1 CEMENTITE | ||
+ | read-thermodynamic-database | ||
+ | </ | ||
+ | |||
+ | Also, the mobility database is read in: | ||
+ | |||
+ | < | ||
+ | |||
+ | The composition is entered: | ||
+ | |||
+ | < | ||
+ | set-reference-element FE | ||
+ | enter-composition weight-percent C=0.1 NB=0.7 | ||
+ | </ | ||
+ | |||
+ | and an equilibrium is calculated, after setting automatic start values. | ||
+ | |||
+ | < | ||
+ | set-automatic-startvalues | ||
+ | set-temperature-celsius 1000 | ||
+ | calculate-equilibrium | ||
+ | |||
+ | ===== Setting up the precipitation domains ===== | ||
+ | |||
+ | We proceed by creating the precipitation domains. The calculation involves heat-treatment in both ferrite (BCC_A2) and austenite (FCC_A1) phase stability regions, so we start by creating these two domains. | ||
+ | |||
+ | < | ||
+ | create-precipitation-domain ferrite | ||
+ | create-precipitation-domain austenite | ||
+ | </ | ||
+ | |||
+ | We must then tell MatCalc with which matrix phases to associate these domains: | ||
+ | |||
+ | < | ||
+ | set-precipitation-parameter ferrite thermodynamic-matrix-phase=BCC_A2 | ||
+ | set-precipitation-parameter austenite thermodynamic-matrix-phase=FCC_A1 | ||
+ | </ | ||
+ | |||
+ | Structural parameters are then defined for ferrite (note comments describing the meanings of the commands): | ||
+ | |||
+ | < | ||
+ | set-precipitation-parameter ferrite equilibrium-dislocation-density=1e12 | ||
+ | set-precipitation-parameter ferrite initial-grain-diameter=100e-6 | ||
+ | set-precipitation-parameter ferrite initial-subgrain-diameter=10e-6 | ||
+ | set-precipitation-parameter ferrite subgrain-elongation-factor=10 | ||
+ | </ | ||
+ | |||
+ | and for austenite. Note that for ferrite, parameters characterising the subgrains are included because subgrain boundaries will be used as nucleation sites later in the calculation. In austenite, this is not the case so the parameters for this domain are not relevant and need not be set. | ||
+ | |||
+ | < | ||
+ | set-precipitation-parameter austenite equilibrium-dislocation-density=1e12 | ||
+ | set-precipitation-parameter austenite initial-grain-diameter=100e-6 </ | ||
+ | |||
+ | ===== Setting up the precipitate phases ===== | ||
+ | |||
+ | The next stage in the script is to set up the precipitates. Firstly, we need to create precipitate phases from the equilibrium phases. As two nucleation sites are to be used for FCC_A1# | ||
+ | |||
+ | < | ||
+ | create-new-phase CEMENTITE precipitate | ||
+ | create-new-phase FCC_A1#01 precipitate | ||
+ | create-new-phase FCC_A1#01 precipitate</ | ||
+ | |||
+ | Note that this latter phase is derived from the second FCC_A1 phase, FCC_A1#01, which is automatically generated by MatCalc, based on a command in the database, as a result of the presence of the MX carbonitride former, Nb, in the system. | ||
+ | |||
+ | The precipitate phase are initialised with 100 size classes each. | ||
+ | |||
+ | < | ||
+ | set-precipitation-parameter CEMENTITE_P0 number-of-size-classes=100 | ||
+ | set-precipitation-parameter FCC_A1# | ||
+ | set-precipitation-parameter FCC_A1# | ||
+ | </ | ||
+ | |||
+ | Then the nucleation sites are defined: | ||
+ | |||
+ | < | ||
+ | |||
+ | set-precipitation-parameter CEMENTITE_P0 nucleation-sites=dislocations | ||
+ | set-precipitation-parameter FCC_A1# | ||
+ | set-precipitation-parameter FCC_A1# | ||
+ | </ | ||
+ | |||
+ | The nucleation sites for FCC_A1# | ||
+ | The nucleus composition of the iron-rich cementite precipitate phase is set to para-equilibrium, | ||
+ | |||
+ | < | ||
+ | set-precipitation-parameter CEMENTITE_P0 nucleus-composition-model=para-composition | ||
+ | set-precipitation-parameter FCC_A1# | ||
+ | set-precipitation-parameter FCC_A1# | ||
+ | </ | ||
+ | |||
+ | ===== Heat-treatment ===== | ||
+ | |||
+ | For an isothermal precipitation simulation, we would now simply need to set the temperature and time and start the simulation. This procedure is described briefly [[tutorials: | ||
+ | |||
+ | The heat-treatment consists of two sections: | ||
+ | |||
+ | An **austenitisation and quenching** treatment consisting of: | ||
+ | * heating from room temperature to the austenitisation temperature; | ||
+ | * an isothermal hold at the austenitisation temperature | ||
+ | * quenching to room temperature; | ||
+ | |||
+ | A **tempering** treatment consisting of: | ||
+ | * heating from room temperature to the tempering temperature | ||
+ | * an isothermal hold at the tempering temperature | ||
+ | * cooling to room temperature | ||
+ | |||
+ | The tempering treatment is carried out entirely in the ferrite phase stability region, so no change of precipitation domain is necessary. | ||
+ | |||
+ | Start by creating a heat treatment sequence called '' | ||
+ | |||
+ | < | ||
+ | |||
+ | Heat- or thermomechanical treatments can consist of different types of segments. In this tutorial, we will use two of these: | ||
+ | |||
+ | * Definition with segment end temperature and a heating/ | ||
+ | * Definition with segment end temperature and a duration time. | ||
+ | |||
+ | We saw in [[tutorials: | ||
+ | |||
+ | < | ||
+ | set-variable-value f_a_temp 850 $ferrite-> | ||
+ | set-variable-value a_f_temp 600 $austenite-> | ||
+ | set-variable-value aus_temp 1100 $austenitisation temp. in C | ||
+ | set-variable-value temp_temp 600 $tempering temp. in C | ||
+ | set-variable-value rate_heat_to_aus 1 $rate of heating to aus_temp in K/s | ||
+ | set-variable-value rate_cool_from_aus -10 $rate of cooling from aus_temp in K/s | ||
+ | set-variable-value rate_heat_to_temp 1 $rate of heating to temp_temp in K/s | ||
+ | set-variable-value rate_cool_from_temp -1 $rate of cooling from temp_temp in K/s | ||
+ | set-variable-value aus_time 3600 $austenitisation time in seconds | ||
+ | set-variable-value temp_time 7200 $tempering time in seconds | ||
+ | </ | ||
+ | |||
+ | ==== Austenitisation and quenching treatment ==== | ||
+ | |||
+ | Start by adding the **first segment**, using the command | ||
+ | |||
+ | < | ||
+ | |||
+ | Then specify the [s]tart temperature. The notation [.] means **the current segment**. It is also possible to refer to the segments by number. | ||
+ | |||
+ | < | ||
+ | |||
+ | This first segment consists of heating, at a rate **rate_heat_to_aus** up to the temperature **f_a_temp** at which the ferrite-austenite phase transformation takes place. | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | The precipitation domain associated with this segment must now be set. | ||
+ | |||
+ | < | ||
+ | |||
+ | We then append a **new segment** to accommodate the remainder of the heating ramp to the austenitisation temperature. | ||
+ | |||
+ | < | ||
+ | |||
+ | This new segment now becomes the current segment, so we can modify //its// parameters using the [.] notation. The end temperature **aus_temp** and the same heating rate as before, **rate_heat_to_aus**, | ||
+ | |||
+ | < | ||
+ | |||
+ | We also need to change the precipitation domain to austenite: | ||
+ | |||
+ | < | ||
+ | |||
+ | The next stage is the isothermal hold. Add a **new segment**. | ||
+ | |||
+ | < | ||
+ | |||
+ | The isothermal hold is specified with end temperature aus_temp and hold time aus_time. | ||
+ | |||
+ | < | ||
+ | |||
+ | The precipitation domain remains austenite. | ||
+ | |||
+ | < | ||
+ | |||
+ | We next add two segments for cooling down from the austenitisation domain to room temperature. Add a **new segment** for the austenite domain part. Set the end temperature to the austenite-ferrite transformation temperature **a_f_temp** and the cooling rate to **rate_cool_from_aus**. Set the precipitation domain to austenite. | ||
+ | |||
+ | < | ||
+ | edit-tmt-segment sample_ht . T_end+T_dot a_f_temp rate_cool_from_aus | ||
+ | edit-tmt-segment sample_ht . precipitation-domain=austenite</ | ||
+ | |||
+ | Add a further **new segment** for the ferrite domain part. In this case, we set the end temperature to 20 and the cooling rate, as before, to **rate_cool_from_aus**. This time, the precipitation domain is set to **ferrite**. | ||
+ | |||
+ | < | ||
+ | edit-tmt-segment sample_ht . T_end+T_dot 20 rate_cool_from_aus | ||
+ | edit-tmt-segment sample_ht . precipitation-domain=ferrite | ||
+ | </ | ||
+ | |||
+ | In addition, since this ferrite is now quenched martensite, we make some modifications to the properties of the precipitation domain. As we saw in [[tutorials: | ||
+ | |||
+ | < | ||
+ | |||
+ | Similarly, in the following line, the nucleation sites of FCC_A1# | ||
+ | |||
+ | < | ||
+ | ==== Tempering treatment ==== | ||
+ | |||
+ | The structure of the tempering treatment is similar to that of the austenitisation treatment, but somewhat simpler, since no phase transformation needs to be considered. | ||
+ | |||
+ | The first part of this treatment is a heating segment with an end temperature of temp_temp and a heating rate of **rate_heat_to_temp**. The precipitation domain is left the same as in the previous segment. | ||
+ | |||
+ | < | ||
+ | edit-tmt-segment sample_ht . T_end+T_dot temp_temp rate_heat_to_temp | ||
+ | edit-tmt-segment sample_ht . precipitation-domain=ferrite </ | ||
+ | |||
+ | This is followed by an isothermal hold for **temp_time** at the tempering temperature **temp_temp**; | ||
+ | < | ||
+ | edit-tmt-segment sample_ht . T_end+delta_t temp_temp temp_time | ||
+ | edit-tmt-segment sample_ht . precipitation-domain=ferrite</ | ||
+ | |||
+ | Finally, a cooling segment returns the system to room temperature with a rate of **rate_cool_from_temp**. The precipitation domain is still ferrite. | ||
+ | |||
+ | < | ||
+ | edit-tmt-segment sample_ht . T_end+T_dot 20 rate_cool_from_temp | ||
+ | edit-tmt-segment sample_ht . precipitation-domain=ferrite </ | ||
+ | |||
+ | ===== Plots ===== | ||
+ | |||
+ | The final part of the setup before the calculation is run consists of setting up the plots. We will create four X-Y plots in a single plot window as well as a histogram of precipitate size distribution for each of the precipitate phases. | ||
+ | |||
+ | Start by creating a GUI window of type **p1** (X-Y plot) | ||
+ | |||
+ | < | ||
+ | |||
+ | Then set up the default x-axis so that it is used for all the plots in this windows, and has the properties specified below: | ||
+ | |||
+ | < | ||
+ | set-gui-window-property . default-x-axis-title=Time [h] | ||
+ | set-gui-window-property . default-x-axis-type=lin | ||
+ | set-gui-window-property . default-x-axis-factor=1/ | ||
+ | </ | ||
+ | |||
+ | The first plot will contain the temperature profile as determined by the heat-treatment. The y-axis is labeelled accordingly. | ||
+ | |||
+ | < | ||
+ | set-plot-option . y-axis-title=Temperature [°C] | ||
+ | </ | ||
+ | |||
+ | The legend box is removed because it is not necessary when only one series is plotted: | ||
+ | |||
+ | < | ||
+ | |||
+ | Major gridlines are switched on for both x- and y-axes. | ||
+ | |||
+ | < | ||
+ | set-plot-option . grid major enable-y-axis=yes | ||
+ | </ | ||
+ | |||
+ | A new plot is then created in the existing plot window [.] using the command: | ||
+ | |||
+ | < | ||
+ | |||
+ | This is set up to show the phase fractions of the two precipitate phases. (See [[tutorials: | ||
+ | |||
+ | < | ||
+ | set-plot-option . grid major enable-x-axis=yes | ||
+ | set-plot-option . grid major enable-y-axis=yes | ||
+ | set-plot-option . series new buffer f$cementite_p0 | ||
+ | set-plot-option . series new buffer f$fcc_a1# | ||
+ | set-plot-option . series new buffer f$fcc_a1# | ||
+ | </ | ||
+ | |||
+ | There are three series in this plot, so we label them. The three series here are referred to by number. The ordering number corresponds to the order in which they appear **in the plot**, not in the plot window, and begins at 0. | ||
+ | |||
+ | < | ||
+ | set-plot-option . series rename 1 NbC(gb) | ||
+ | set-plot-option . series rename 2 NbC(sgb) | ||
+ | </ | ||
+ | |||
+ | A further new plot is created, to plot the number density of precipitates. The series are renamed; note that the numbering starts at 0 again because we are now in a new plot. | ||
+ | |||
+ | < | ||
+ | set-plot-option . y-axis-title=N< | ||
+ | set-plot-option . y-axis-type=log | ||
+ | set-plot-option . grid major enable-x-axis=yes | ||
+ | set-plot-option . grid major enable-y-axis=yes | ||
+ | set-plot-option . series new buffer num_prec$cementite_p0 | ||
+ | set-plot-option . series new buffer num_prec$fcc_a1# | ||
+ | set-plot-option . series new buffer num_prec$fcc_a1# | ||
+ | set-plot-option . series rename 0 Cementite | ||
+ | set-plot-option . series rename 1 NbC(gb) | ||
+ | set-plot-option . series rename 2 NbC(sgb) | ||
+ | </ | ||
+ | |||
+ | The final of the four plots shows the mean precipitate radius. | ||
+ | |||
+ | < | ||
+ | set-plot-option . y-axis-title=R< | ||
+ | set-plot-option . y-axis-type=log | ||
+ | set-plot-option . grid major enable-x-axis=yes | ||
+ | set-plot-option . grid major enable-y-axis=yes | ||
+ | set-plot-option . series new buffer r_mean$cementite_p0 | ||
+ | set-plot-option . series new buffer r_mean$fcc_a1# | ||
+ | set-plot-option . series new buffer r_mean$fcc_a1# | ||
+ | set-plot-option . series rename 0 Cementite | ||
+ | set-plot-option . series rename 1 NbC(gb) | ||
+ | set-plot-option . series rename 2 NbC(sgb) | ||
+ | </ | ||
+ | |||
+ | The plots are arranged so that they occupy two columns: | ||
+ | |||
+ | < | ||
+ | |||
+ | A new GUI window of type p5 is created for the first histogram: | ||
+ | |||
+ | < | ||
+ | |||
+ | The default x-axis is set up, with the scaling factor used to give plotting in nanometres rather than metres. | ||
+ | |||
+ | < | ||
+ | set-gui-window-property . default-x-axis-title=Precipitate radius [nm] | ||
+ | set-gui-window-property . default-x-axis-factor=1e9 | ||
+ | </ | ||
+ | |||
+ | Options controlling the histogram are then set. | ||
+ | |||
+ | < | ||
+ | set-plot-option . plot-title=Precipitate distributions | ||
+ | set-plot-option . y-axis-title=Number density of precipitates [m< | ||
+ | </ | ||
+ | |||
+ | New series showing the precipitate distribution of the precipitate phases are plotted: | ||
+ | |||
+ | < | ||
+ | set-plot-option . series new precipitate-distribution FCC_A1# | ||
+ | set-plot-option . series new precipitate-distribution FCC_A1# | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Running the calculation ===== | ||
+ | |||
+ | We first save the workspace setup as it before the calculation. This enables us to easily revert to this pre-calculation state if necessary. | ||
+ | |||
+ | < | ||
+ | |||
+ | An isothermal calculation can be carried out as follows. This can be useful as a preliminary calculation to check that everything is working. | ||
+ | |||
+ | An end-time (in seconds) for the simulation is first set: | ||
+ | < | ||
+ | |||
+ | Then, the temperature control of the simulation is set to be isothermal and the required temperature specified. | ||
+ | |||
+ | < | ||
+ | |||
+ | A further line is added to specify that this temperature is in Celsius. | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | The calculation can then be executed using: | ||
+ | < | ||
+ | |||
+ | When this has been successfully carried out, the line specifying isothermal temperature control should be commented out by prepending a dollar sign so that it looks as shown: | ||
+ | |||
+ | < | ||
+ | |||
+ | The temperature control is instead set to be governed by the [h]eat treatment " | ||
+ | |||
+ | < | ||
+ | |||
+ | Again, the simulation is started using: | ||
+ | < | ||
+ | |||
+ | When the calculation is over, the workspace can be saved using: | ||
+ | < | ||
+ | |||
+ | In addition, we can export whole frames or individual plots: | ||
+ | |||
+ | < | ||
+ | export-frame-to-file 3 png t19_histo_cementite | ||
+ | export-plot-to-file 4 png t19_r_mean </ | ||
+ | |||
+ | The x-y plot window should look as follows after the calculation: | ||
+ | |||
+ | {{: | ||
+ | ===== Subsequent articles ===== | ||
+ | |||
+ | The tutorial is continued in [[tutorials: | ||
+ | |||
+ | Go to the [[: |