Skip to main content

Flexible Model Development with the TC-Python Property Model Framework

The Property Model Calculator within Thermo-Calc offers predictive models for material properties based on their chemical composition and temperature. It is included with all Thermo-Calc installations. This article will demonstrate how to set up a custom model, based on literature or in-house information into the Property Model Framework.

Create User-Defined Property Models with Thermo-Calc

With the TC-Python Property Model Framework, you can develop your own models and customize the software to meet your specific needs. This is particularly useful if you want to couple results from a Thermo-Calc calculation to a literature or in-house model to calculate a specific material property that is not natively available in the software.

The user-defined models are developed using the easy-to-learn programming language Python™, and with the TC-Python Property Model Framework, they automatically populate in Thermo-Calc where they can be configured and run in the Graphical User Interface. This gives you access to all the powerful features and calculation types available in Thermo-Calc.

Additionally, because this program uses the Python language, users can use any Python library, such as numpy, scipy, or scikit-learn, within the Property Models, making model development quite powerful.

The TC-Python Property Model Framework is available with TC-Python, an SDK available for purchase with Thermo-Calc.

Example: Pitting Resistance Equivalent Number (PREN)

Duplex stainless steels are commonly used in corrosive environments due to their excellent corrosion resistance. However, these alloys are susceptible to pitting, a form of very localized corrosion. Therefore, it is important to take corrosion resistance into account when designing duplex stainless steels. The pitting resistance equivalent number (PREN) is one method of estimating the corrosion resistance of these alloys. The following equation is widely used to calculate the PREN [1]: 

PREN =  wt.%Cr + 3.3 wt.%Mo + 16 wt.%N

This example will use the above equation. There are a number of subsequent modifications in the literature to this equation that take into account other elements that are known to have an effect, like tungsten, that should be evaluated for your specific use case.

Since Duplex stainless steels are normally designed towards a roughly 50/50 balance of ferrite and austenite to achieve optimal mechanical properties, it is desirable to balance the PREN in each of the phases to avoid preferential pitting. However, these phases have different chemical compositions and can therefore differ in corrosion behavior in each phase [1]. By calculating the PREN for each phase based on its equilibrium composition, it is then possible to optimize the chemistry to ensure good pitting corrosion resistance in each phase. 

For this, we have used the TC-Python Property Model Framework to create and implement a user-defined PRE model in Thermo-Calc. This way we are able to use the phase compositions generated by Thermo-Calc directly in our model.

The figure below shows the calculated PRE value for FCC and BCC separately. As shown in the PREN equation, nitrogen has a big impact on the pitting resistance. By plotting PREN against the nitrogen content, we can find the optimal nitrogen content for this alloy. 

PREN_BCC_FCC_duplex-stainless-steel

Result of the calculation using a user defined model in Thermo-Calc, showing how PREN changes with nitrogen content in BCC and FCC respectively. The red line shows the temperature where equal amounts of FCC and BCC are achieved.

Write Your Own Model

To write your own model, you need to have a license for TC-Python and an integrated development environment (IDE) installed. We recommend using PyCharm but any IDE will work. If you need help installing TC-Python, please refer to the TC-Python installation guide

When writing your own model, it is important that you use the correct naming of your model. The Python file should end with PythonModel and the folder should have the same name as the Python file but without Model at the end. 

For example, the Python code for our user defined PRE model is named PREPythonModel.py and the folder is named PREPython.

The code should be placed in the correct folder – the PropertyModels folder. To find the folder location, open Thermo-Calc and go to Tools > Options > Model directory. The folder path is usually C:\Users\Public\Documents\Thermo-Calc\2023b\PropertyModels, where 2023b is the version number, so make sure to use the version number of your installation.

file-path-model-library

The path to the correct folder can be found under Tools > Options in the Thermo-Calc application.

folder-and-file-names

The folder name should end with Python and the file name should end with PythonModel.

There are non-encrypted models available with your Thermo-Calc installation, which might be helpful to look at while writing your own models. One of those models is the Driving Force model. The code for that model can be found in the PropertyModels folder (mentioned above) where all the other property models are stored.

Before you start writing your code, you need to import the TC-Python library:

from tc_python import *

You also need to make your model uses the PropertyModel class.

class PREPythonModel(PropertyModel):

Write your code using the Python language and whatever Python library you like. There are some methods that you need to implement in your property model Python code. These are:

  • provide_calculation_result_quantities: Define which result quantities you want to generate.
  • provide_model_category: Define in which model category/folder you want the model to appear in. In Thermo-Calc, the models are divided into three categories: General Models, Nickel Models, and Steel Models.
  • provide_model_name: The name of your model. This name will be displayed in the model library list within Thermo-Calc.
  • provide_model_description: Write a short description of the model.
  • provide_ui_panel_components: Define which components you want in the graphical user interface (GUI) for the model. For example, if you want to be able to set the ratio between different phases in the GUI.
  • before_evaluations: Set which calculators to use before the model evaluation.
  • evaluate_model: Define what you want your model to do. For example, take values from GUI input, set conditions, extract phase compositions, and set result quantities.

The model should be tested after implementing each of these methods to make the debugging easier. Do this by clicking Run in PyCharm or the equivalent in the IDE that you are using.

Once the code runs without errors in the IDE, save it in the correct folder as described above, and test it with Thermo-Calc.

Access the PREN Model Python Code

Fill out the short form below to access the code. If you do not see the form below, it may be due to an ad blocker. Please try opening this page in another browser or turning off your ad blocker on this page.

Learn about the Property Model Calculator in Thermo-Calc 

The Property Model Calculator within Thermo-Calc offers predictive models for material properties based on their chemical composition and temperature and is included with all Thermo-Calc installations. This article is part of a series of blog posts that take a deeper dive into the different calculation types included in the Property Model Calculator and how they can be applied to materials design, process optimization, and ICME frameworks.

Reference: 

[1] D.H. Kang, H.W. Lee, “Study of the correlation between pitting corrosion and the component ratio of the dual phase in duplex stainless steel welds”. Corrosion Science, Volume 74, 2013, p. 396-407. Read this reference

Let Us Help You

Is Thermo-Calc Right for You?

Talk to one of our experts to learn whether our tools fit your needs.