




























































































Étudies grâce aux nombreuses ressources disponibles sur Docsity
Gagnz des points en aidant d'autres étudiants ou achete-les avec un plan Premium
Cette page n'est pas visible dans l'aperçu
Ne manques pas les parties importantes!





























































































ONE
INSTALLATION GUIDE
This guide helps you to get a working TC-Python API installation. There is a PDF guide included with your installation. In the Thermo-Calc menu, select Help → Manuals Folder. Then double-click to open the Software Development Kits (SDKs) folder.
Note: A license is required to run TC-Python.
1.1 What type of installation should I choose?
There are two possibilities to install TC-Python:
1.2 Using the Python-interpreter bundled to Thermo-Calc
Note: A Python-interpreter is bundled to Thermo-Calc beginning with version 2021a.
The bundled Python 3.7.2 interpreter is containing the following major packages:
Package Version matplotlib 3.3. numpy 1.19. scikit-learn 0.23. scipy 1.5. TC-Python 2023a
TC-Python Documentation, Release 2023a
Now you are ready to start working with TC-Python. It is recommended that you open one or more of the included examples to both check that the installation has worked and to start familiarizing yourself with the code.
1.2.4.1 Open the TC-Python Project in PyCharm
When you first open the TC-Python project and examples, it can take a few moments for the Pycharm IDE to index before some of the options are available.
Operating sys- tem
Path to the TC-Python folder
Windows C:\Users\UserName\Documents\Thermo-Calc\2023a\SDK TC-Python Linux /home/UserName/Thermo-Calc/2023a/SDK/TC-Python MacOS /Users/Shared/Thermo-Calc/2023a/SDK/TC-Python
Note: If you are not following the recommended approach and create a new project ( File → New Project... ), you need to consider that by default the options to choose the interpreter are hidden within the Create Project window. So click on Project Interpreter: New Virtual Environment and in most cases choose your System Interpreter containing the Python bundled to Thermo-Calc instead of the default New Virtual Environment.
1.3 Installing TC-Python into the Python-interpreter of your choice
If you already have a Python distribution installation, version 3.5 or higher, skip this step. These instructions are based on using the Anaconda platform for the Python distribution. Install version 3.5 or higher to be able to work with TC-Python, although it is recommended that you use the most recent version.
1.3. Installing TC-Python into the Python-interpreter of your choice 3
TC-Python Documentation, Release 2023a
1.3.1.1 Install Anaconda
Note: TC-Python is available starting with Thermo-Calc version 2018a.
On Windows, it is recommended that you use the Python distribution prompt (i.e. Anaconda,... ), espe- cially if you have other Python installations. Do not use Virtual Environments unless you have a good reason for that.
pip install /TC_Python--py3-none- ↪→any.whl
Tip: Note that on Linux depending on the interpreter usually pip3 is used.
Operating sys- tem
Path to the TC-Python folder
Windows C:\Users\UserName\Documents\Thermo-Calc\2023a\SDK TC-Python Linux /home/UserName/Thermo-Calc/2023a/SDK/TC-Python MacOS /Users/Shared/Thermo-Calc/2023a/SDK/TC-Python
Note: If your computer is located behind a proxy-server, the default pip -command will fail with a network connection error. In that case you need to install the dependencies of TC-Python in a special configuration:
pip install -proxy user:password@proxy_ip:port py4j jproperties
4 Chapter 1. Installation Guide
TC-Python Documentation, Release 2023a
1.3.5.2 Fixing potential issues with the environment
In most cases you should run TC-Python within your global Python 3 interpreter and not use Virtual Environments unless you have a good reason to do so. A common problem on first usage of TC-Python is the error message “ No module named tc_python ”. You can resolve this and other problems with the interpreter settings as follows:
Note: If you are not following the recommended approach and create a new project ( File → New Project... ), you need to consider that by default the options to choose the interpreter are hidden within the Create Project window. So click on Project Interpreter: New Virtual Environment and in most cases choose your System Interpreter instead of the default New Virtual Environment.
Note: If you really need to use a Virtual Environment, please consider the hints given in the Python Virtual Environments chapter.
1.4 Updating to a newer version
When updating to a newer version of Thermo-Calc, you need to also install the latest version of TC- Python. This is not necessary if are using the bundled Python-interpreter that has it automatically installed. It is not sufficient to run the installer of Thermo-Calc:
pip install /TC_Python--py3-none-any.whl
Tip: Note that on Linux depending on the interpreter usually pip3 is used.
In case of problems you may wish to uninstall the previous version of TC-Python in advance:
pip uninstall TC-Python pip install /TC_Python--py3-none-any.whl
However, that should normally not be required. You can check the currently installed version of TC-Python by running:
pip show TC-Python
6 Chapter 1. Installation Guide
TWO
MAC OS: SETTING ENVIRONMENT VARIABLES
In order to use TC-Python on Mac you need to set some environment variables.
TC23A_HOME=/Applications/Thermo-Calc-2023a.app/Contents/Resources
If you use a license server:
LSHOST=
If you have a node-locked license:
LSHOST=NO-NET LSERVRC=/Users/Shared/Thermo-Calc/lservrc
In PyCharm, you can add environment variables in the configurations.
Select Run → Edit Configurations to open the Run/Debug Configurations window. Choose Templates and then Python. Enter the environment variable(s) by clicking the button to the right of the Environment Variables text field. Now the environment variables(s) will be set for each new configuration by default.
Note: Existing configurations need to be removed and recreated to obtain the environment variables in them.
The same way for configuring the environment variables can be used on other operating systems as if necessary.
THREE
ARCHITECTURE OVERVIEW
TC-Python contains classes of these types:
3.1 TCPython
This is the starting point for all TC-Python usage.
You can think of this as the start of a “wizard”.
You use it to select databases and elements. That will take you to the next step in the wizard, where you configure the system.
Example:
from tc_python import *
with TCPython() as start: start.select_database_and_elements(...
with TCPython(): SetUp().select_database_and_elements(...
Tip: If you use TC-Python from Jupyter Lab / Notebook, you should use TC-Python slightly different to be able to use multiple cells. See Using TC-Python within a Jupyter Notebook or the Python console for details.
Note: When your python script runs a row like this:
with TCPython() as start:
TC-Python Documentation, Release 2023a
a process running a calculation server starts. Your code, via TC-Python, uses socket communication to send and receive messages to and from that server.
When your Python script has run as far as this row:
the calculation server automatically shuts down, and all temporary files are deleted. It is important to ensure that this happens by structuring your Python code using a with() clause as in the above example.
Note: To re-use results from previous calculations, set a folder where TC-Python saves results, and looks for previous results.
This is done with the function set_cache_folder().
from tc_python import *
with TCPython() as start: start.set_cache_folder("cache")
This folder can be a network folder and shared by many users. If a previous TC-Python calculation has run with the same cache_folder and EXACTLY the same system and calculation settings, the calculation is not re-run. Instead the result is automatically loaded from disk.
It is also possible to explicitly save and load results.
from tc_python import *
with TCPython() as start: #... diffusion calculation (could be any calculation type) calculation_result.save_to_disk('path to folder') #... loaded_result = start.load_result_from_disk().diffusion('path to folder')
3.2 SystemBuilder and System
A SystemBuilder is returned when you have selected your database and elements in TCPython.
The SystemBuilder lets you further specify your system, for example the phases that should be part of your system.
Example:
from tc_python import *
with TCPython() as start: start.select_database_and_elements("ALDEMO", ["Al", "Sc"])
When all configuration is done, you call get_system() which returns an instance of a System class. The System class is fixed and cannot be changed. If you later want to change the database, elements or something else, change the SystemBuilder and call get_system() again, or create a new SystemBuilder and call get_system().
From the System you can create one or more calculations, which is the next step in the “wizard”.
10 Chapter 3. Architecture overview
TC-Python Documentation, Release 2023a
Batch equilibrium calculations are used when you want to do many single equilibrium calculations and it is known from the beginning which result values are required from the equilibrium. This is a vectorized type of calculation that can reduce the overhead from Python and TC-Python similar to the approach used in numpy -functions for example.
Tip: The performance of batch equilibrium calculations can be significantly better than looping and using single equilibrium calculations if the actual Thermo-Calc calculation is fast. There is little advantage if the Thermo-Calc equilibrium calculations take a long time (typically for large systems and databases).
Example:
from tc_python import *
with TCPython() as start: calculation = ( start .set_cache_folder(os.path.basename(file) + "_cache") .select_database_and_elements("NIDEMO", ["Ni", "Al", "Cr"]) .get_system() .with_batch_equilibrium_calculation() .set_condition("T", 800.1) .set_condition("X(Al)", 1E-2) .set_condition("X(Cr)", 1E-2) .disable_global_minimization() )
list_of_x_Al = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] list_of_x_Cr = [3, 5, 7, 9, 11, 13, 15] lists_of_conditions = [] for x_Al in list_of_x_Al: for x_Cr in list_of_x_Cr: lists_of_conditions.append([ ("X(Al)", x_Al / 100), ("X(Cr)", x_Cr / 100)]) calculation.set_conditions_for_equilibria(lists_of_conditions)
results = calculation.calculate(["BM", "VM"])
masses = results.get_values_of("BM") volumes = results.get_values_of('VM')
print(masses) print(volumes)
12 Chapter 3. Architecture overview
TC-Python Documentation, Release 2023a
All that can be configured in the Precipitation Calculator in Graphical Mode can also be done here in this calculation. However, you must at least enter a matrix phase, a precipitate phase, temperature, simulation time and compositions.
Example:
from tc_python import *
with TCPython() as start: precipitation_curve = ( start. select_thermodynamic_and_kinetic_databases_with_elements("ALDEMO", "MALDEMO", ↪→ ["Al", "Sc"]). get_system(). with_isothermal_precipitation_calculation(). set_composition("Sc", 0.18). set_temperature(623.15). set_simulation_time(1e5). with_matrix_phase(MatrixPhase("FCC_A1"). add_precipitate_phase(PrecipitatePhase("AL3SC"))). calculate() )
All Scheil calculations available in Graphical Mode or Console Mode can also be done here in this calculation. The minimum you need to specify are the elements and compositions. Everything else is set to a default value.
Example:
from tc_python import *
with TCPython() as start: temperature_vs_mole_fraction_of_solid = ( start. select_database_and_elements("FEDEMO", ["Fe", "C"]). get_system(). with_scheil_calculation(). set_composition("C", 0.3). calculate(). get_values_of(ScheilQuantity.temperature(), ScheilQuantity.mole_fraction_of_all_solid_phases()) )
3.3. Calculation 13
TC-Python Documentation, Release 2023a
(continued from previous page) set_condition(ThermodynamicQuantity.mole_fraction_of_a_component("C"), 0. ↪→01). calculate(). get_values_grouped_by_stable_phases_of(ThermodynamicQuantity.mass_ ↪→fraction_of_a_component("C"), ThermodynamicQuantity. ↪→temperature()) )
For diffusion calculations, everything that you can configure in the Diffusion Calculator can also be configured in this calculation. The minimum you need to specify are elements, temperature, simulation time, a region with a grid and width, a phase and an initial composition.
Example:
from tc_python import *
with TCPython() as start: diffusion_result = ( start. select_thermodynamic_and_kinetic_databases_with_elements("FEDEMO", "MFEDEMO", ↪→ ["Fe", "Ni"]). get_system(). with_isothermal_diffusion_calculation(). set_temperature(1400.0). set_simulation_time(108000.0). add_region(Region("Austenite"). set_width(1E-4). with_grid(CalculatedGrid.linear().set_no_of_points(50)). with_composition_profile(CompositionProfile(). add("Ni", ElementProfile.linear(10.0, 50.0)) ). add_phase("FCC_A1")). calculate())
distance, ni_fraction = diffusion_result.get_mass_fraction_of_component_at_time("Ni", ↪→ 108000.0)
For Property Model calculations, everything that you can configure in the Property Model Calculator in Graphical Mode can also be configured in this calculation. The minimum you need to specify are elements, composition and which Property Model you want to use.
Example:
from tc_python import *
with TCPython() as start: (continues on next page)
3.3. Calculation 15
TC-Python Documentation, Release 2023a
(continued from previous page) print("Available Property Models: {}".format(start.get_property_models())) property_model = ( start. select_database_and_elements("FEDEMO", ["Fe", "C"]). get_system(). with_property_model_calculation("Driving force"). set_composition("C", 1.0). set_argument("precipitate", "GRAPHITE"))
print("Available arguments: {}".format(property_model.get_arguments())) result = property_model.calculate()
print("Available result quantities: {}".format(result.get_result_quantities())) driving_force = result.get_value_of("normalizedDrivingForce")
Material to Material calculations are generally regular single equilibrium, property diagram or phase diagram calcu- lations but they are specialised to handle the mixture of two materials A and B. Everything that you can configure in the Material to Material Calculator in Graphical Mode can also be configured in this calculation. The minimum required configuration is shown below for a Property diagram calculation for varying amount of material B. The other calculators (single fraction of material B and phase diagram calculations) are configured in a similar way.
Example:
from tc_python import *
with TCPython() as start: material_to_material_property_diagram = ( start. select_database_and_elements("FEDEMO", ["Fe", "Cr", "Ni", "C"]). get_system(). with_material_to_material(). with_property_diagram_calculation(). set_material_a({"Cr": 10.0, "Ni": 15.0}, "Fe"). set_material_b({"Cr": 15.0, "Ni": 10.0}, "Fe"). set_activities({"C": 0.1}). with_constant_condition(ConstantCondition.temperature(800 + 273.15)). with_axis(MaterialToMaterialCalculationAxis.fraction_of_material_b(from_ ↪→fraction=0.0, to_ ↪→fraction=1.0, start_ ↪→fraction=0.5)) )
result = material_to_material_property_diagram.calculate() data = result.get_values_grouped_by_quantity_of(MATERIAL_B_FRACTION, ThermodynamicQuantity.volume_ ↪→fraction_of_a_phase(ALL_PHASES))
(continues on next page)
16 Chapter 3. Architecture overview