This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | tutorials:t13 [2019/08/02 15:11] – [Calculating an equilibrium] pwarczok | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== T13: Introduction to scripting - Equilibrium calculations ===== | ||
+ | //This tutorial was tested on\\ | ||
+ | MatCalc version 6.01 rel 1.003\\ | ||
+ | license: free\\ | ||
+ | database: mc_fe.tdb// | ||
+ | |||
+ | ==== Complimentary files ==== | ||
+ | |||
+ | Click {{: | ||
+ | |||
+ | ==== Contents: ==== | ||
+ | |||
+ | * Purpose of scripts | ||
+ | * Writing a script to perform a stepped calculation and display the results | ||
+ | |||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | ==== Utility of scripts ==== | ||
+ | |||
+ | A script is a text file, containing a list of commands to be executed in order from top to bottom. They are particularly useful to speed up routine or repetitive operations. Once a script file has been created, it can easily be modified to serve a new purpose, for example by changing the elements or phases in the system. Script files, consisting only of text, are also much smaller in size than MatCalc workspace files, especially those resulting from precipitation calculations.\\ | ||
+ | Individual scripts can also be grouped into master-scripts; | ||
+ | |||
+ | ==== Creating a script ==== | ||
+ | |||
+ | There are two ways of creating a script: | ||
+ | - In MatCalc, choose **' | ||
+ | - Alternatively, | ||
+ | |||
+ | **N.B.- The MatCalc scripts have ' | ||
+ | |||
+ | ==== Writing a script ==== | ||
+ | |||
+ | The scripts are written by typing in the commands used in the console. Similar as in the console, a suggester functionality is present in the script window which improves the script writing process. Each line might contain only one command. Empty lines will improve the readability of the script file in an editor, otherwise these do not influence the execution of the script. | ||
+ | ==== Editing a script ==== | ||
+ | |||
+ | There are also two ways of editing an existing script: | ||
+ | - In MatCalc, using **' | ||
+ | - Alternatively, | ||
+ | |||
+ | ==== Executing a script ==== | ||
+ | |||
+ | And again, there are two ways of executing a script in MatCalc: | ||
+ | - Using **' | ||
+ | - Double-clicking on the **' | ||
+ | |||
+ | ===== Example: a stepped equilibrium ===== | ||
+ | |||
+ | This example will show how to write a script to perform the stepped calculation in [[tutorials: | ||
+ | |||
+ | ==== Comments ==== | ||
+ | |||
+ | It is always advisable to comment the script extensively so as to help other users (or oneself several months later!) to understand the aim of the calculation, | ||
+ | Any line prefixed with a **' | ||
+ | |||
+ | < | ||
+ | $ This whole line is a comment. | ||
+ | new-workspace | ||
+ | </ | ||
+ | |||
+ | Both comments and commands are shown line-by-line in the console when the script is executed, but prefixing a comment or a command with the **' | ||
+ | At the beginning of the script, enter some preliminary comments, containing such information as: the name of the file, the current version of MatCalc (available from Help > About), the current version of the scripting language and a brief summary of the purpose of the script. | ||
+ | |||
+ | < | ||
+ | $ Script T13 | ||
+ | $ This is a script for MatCalc version 5.41 | ||
+ | $ MatCalc script version 1 | ||
+ | $ Calculating equilibrium phase stability in Fe-0.4C wt.% | ||
+ | </ | ||
+ | |||
+ | Save the file as **' | ||
+ | |||
+ | ==== Calculating an equilibrium ==== | ||
+ | |||
+ | The first executable line in the script creates a new workspace (**N.B.- Any previously open workspace will be closed without warning.**) | ||
+ | |||
+ | ''< | ||
+ | $ Create a new workspace file\\ | ||
+ | @$< | ||
+ | new-workspace | ||
+ | |||
+ | The next lines are to enter some workspace information to describe the ideas, assumptions etc. used in the calculation. This information can be found in **' | ||
+ | |||
+ | ''< | ||
+ | $ enter workspace info\\ | ||
+ | < | ||
+ | @ set-workspace-info Script T13\\ | ||
+ | @ set-workspace-info +Calculation of equilibrium phase stability\\ | ||
+ | @ set-workspace-info +in Fe-0.4C wt.% system\\ | ||
+ | @ set-workspace-info +with phases LIQUID, BCC_A2, FCC_A1 and CEMENTITE.'' | ||
+ | |||
+ | Next, add the command-line to open the thermodynamic database. | ||
+ | |||
+ | ''< | ||
+ | $ open the thermodynamic database\\ | ||
+ | < | ||
+ | open-thermodyn-database'' | ||
+ | |||
+ | If the line is put in as above, the script will stop at this point and prompt the user for the name of a thermodynamic database. The output in the console window is as follows: | ||
+ | |||
+ | ''< | ||
+ | < | ||
+ | name for thermodynamic database / | ||
+ | |||
+ | (Press **' | ||
+ | |||
+ | '' | ||
+ | |||
+ | The next parts of the script are to set up the system, set the temperature and calculate an equilibrium. These commands have already been seen in [[tutorials: | ||
+ | |||
+ | ''< | ||
+ | $ select elements and phases\\ | ||
+ | < | ||
+ | select-elements c fe\\ | ||
+ | select-phases liq bcc_a2 fcc cem\\ | ||
+ | < | ||
+ | $ read in the thermodynamic data\\ | ||
+ | < | ||
+ | read-thermodynamic-database\\ | ||
+ | < | ||
+ | $ enter the composition\\ | ||
+ | < | ||
+ | enter-composition weight-percent c=0.4\\ | ||
+ | < | ||
+ | $ set the temperature and calculate an equilibrium\\ | ||
+ | < | ||
+ | set_automatic_startvalues\\ | ||
+ | set_temperature_celsius 700\\ | ||
+ | calculate_equilibrium'' | ||
+ | |||
+ | ==== Stepped calculation ==== | ||
+ | |||
+ | In the line below, after the argument **' | ||
+ | ''< | ||
+ | $ define step parameters and make stepped calculation\\ | ||
+ | < | ||
+ | set-step-option range 400 1600 lin 25\\ | ||
+ | step-equilibrium'' | ||
+ | |||
+ | ==== Graphical output ==== | ||
+ | |||
+ | The final part of the script is concerned with graphical presentation of results. The following line creates a new GUI window to contain the plot. As was seen in [[tutorials: | ||
+ | |||
+ | ''< | ||
+ | $ graphical output\\ | ||
+ | < | ||
+ | new-gui-window p1'' | ||
+ | |||
+ | The following three lines change the default x-data from **' | ||
+ | |||
+ | '' | ||
+ | set-gui-window-property . default-x-axis-for-all-plots=yes\\ | ||
+ | set-gui-window-property . default-x-axis-title=Temperature [°C]'' | ||
+ | |||
+ | The line below adds a title to the diagram. This first diagram is to be a plot of phase fraction versus temperature. | ||
+ | |||
+ | '' | ||
+ | |||
+ | The following lines label the y-axis, change the ' | ||
+ | |||
+ | '' | ||
+ | set-plot-option . y-axis-factor=100\\ | ||
+ | set-plot-option . y-axis-type=log\\ | ||
+ | set-plot-option . y-axis-scaling=1..100'' | ||
+ | |||
+ | Next, the first series **' | ||
+ | |||
+ | '' | ||
+ | set-plot-option . series rename -1 f$liquid Liquid'' | ||
+ | |||
+ | These commands are repeated for the other phases. Note the use of the HTML markup tags to give the subscript in **' | ||
+ | |||
+ | '' | ||
+ | set-plot-option . series rename -1 f$bcc_a2 Ferrite \\ | ||
+ | set-plot-option . series new buffer f$fcc_a1 \\ | ||
+ | set-plot-option . series rename -1 f$fcc_a1 Austenite \\ | ||
+ | set-plot-option . series new buffer f$cementite \\ | ||
+ | set-plot-option . series rename -1 f$cementite Fe%%< | ||
+ | |||
+ | The major grid lines for x- and y-axis are displayed by these commands: | ||
+ | |||
+ | '' | ||
+ | set-plot-option . grid major enable-y-axis=yes'' | ||
+ | |||
+ | The three lines below move and resize the window, update its contents and set the style-sheet to coloured with no symbols. In the first of these lines, the first two numbers define the position of the window, the second two define the width and height. | ||
+ | |||
+ | '' | ||
+ | update-gui-window .\\ | ||
+ | set-gui-window-property . style-sheet=col_no_symb'' | ||
+ | |||
+ | Another plot can be added in the current window as shown below | ||
+ | |||
+ | '' | ||
+ | |||
+ | The newly created plot now becomes the **' | ||
+ | |||
+ | '' | ||
+ | set-plot-option . y-axis-title=Carbon content [wt.%] \\ | ||
+ | set-plot-option . series new buffer x$liquid$c$wp \\ | ||
+ | set-plot-option . series rename -1 x$liquid$c$wp Liquid \\ | ||
+ | set-plot-option . series new buffer x$bcc_a2$c$wp \\ | ||
+ | set-plot-option . series rename -1 x$bcc_a2$c$wp Ferrite \\ | ||
+ | set-plot-option . series new buffer x$fcc_a1$c$wp \\ | ||
+ | set-plot-option . series rename -1 x$fcc_a1$c$wp Austenite \\ | ||
+ | set-plot-option . series new buffer x$cementite$c$wp \\ | ||
+ | set-plot-option . series rename -1 x$cementite$c$wp Fe%%< | ||
+ | set-plot-option . grid major enable-x-axis=yes \\ | ||
+ | set-plot-option . grid major enable-y-axis=yes'' | ||
+ | |||
+ | The script can be concluded with the following line, which should appear in the console when the script has been executed without any errors. | ||
+ | |||
+ | ''< | ||
+ | |||
+ | The final diagrams should look like this: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | ===== Consecutive articles ===== | ||
+ | |||
+ | The tutorial is continued in article [[tutorials: | ||
+ | |||
+ | Go to [[: |