Optimization of Model Parameters in KDB

This example demonstrates how to use PanPython SDK to optimize the kinetic parameters in the precipitation data file (*.kdb) needed by precipitation simulation. The precipitation data file (*.kdb) adopts the XML format, which defines the kinetic model for each precipitate phase and the corresponding model parameters. In this example, interfacial energy and nucleation site parameter are optimized simultaneously for aluminum alloys AA6xxx using experimental data.

Step-by-step guide

Note

A video guide will be available very soon.

  1. Open the “Solution Examples” folder

    /Solution Examples/kopt_precipitation/” from PyCharm IDE. See Installation to setup the IDE environment.

  2. Build a task script

    An example script kopt_test.py has already been included. Following the steps the create your script:

    Import packages
    import os
    from panpython.system import System
    from panpython.task.kopt import KOpt
    
    Setup Pandat.exe path:
    pandat = "YOUR_PATH_TO_PANDAT_EXE/Pandat.exe"
    
    Setup working folders and input files:
    dir_name = os.path.abspath(__file__)
    file_name = os.path.basename(__file__)
    task_path = dir_name[:-len(file_name)]
    
    dump_path = os.path.join(task_path, "output")
    opt_file = os.path.join(task_path, "resource", "PanAl.opt")
    

    Note

    The batchfile is specified in the *.opt file. The calculation type in the batch file template must be “precipitation”:

    <calculation name="AA6xxx_6005_precipitation" type="precipitation">
    

    Note

    A .KDB file with special format is used for specifying optimization parameters. Please see KDB file for optimization for details. The tdb and kdb file is set in the batch file template AA6xxx_6005_opt.pbfx. :

    <databases>
       <database type="kdb" file_name="AA6xxx_opt.kdb"/>
       <database type="tdb" file_name="AlMgSi.tdb"/>
    </databases>
    

    The kdb file is also specified in *.opt file. Both the *.kdb specified in *.opt and *.pbfx should be consistent.

    Note

    Experimental data used for optimization can also be declared in batch file template. It will be easier to compare the experimental data with the calculation if it is specified in the batchfile. An example of the data declaration is:

    <tables>
        <table source="..\resource\size_exp.dat" name="size_exp"/>
        <table source="..\resource\nd_exp.dat" name="nd_exp"/>
        <table source="..\resource\hv_exp.dat" name="hv_exp"/>
    </tables>
    

    The experimental data for optimization is directly read from the text file specified in *.opt file. See Configuration file of kinetic optimization for details. The data is declared in the *.opt file as:

    <TargetProperty filename="size_exp.dat" type="kinetic">
        <property condition="log10(t)" value="log10(s(*)*1e10)"/>
    </TargetProperty>
    <TargetProperty filename="nd_exp.dat" type="kinetic">
        <property condition="log10(t)" value="log10(nd(*))"/>
    </TargetProperty>
    <TargetProperty filename="hv_exp.dat" type="strength">
        <property condition="log10(t)" value="hv(*)"/>
    </TargetProperty>
    

    If the experimental data to be optimized correspond to different experimental conditions, they can be specified through the template batchfile for each data as shown below:

    <TargetProperty filename="Ni_RX_1193K_d001.txt" type="kinetic">
    <!-- Data for strain rate = 0.001/sec -->
               <property condition="true_strain" value="sigma_m(@Grain)"/>
               <batchfile name="Ni_RX_1193K_d001.pbfx" />
        </TargetProperty>
    <!-- Data for strain rate = 0.1/sec -->
    <TargetProperty filename="Ni_RX_1193K_d1.txt" type="kinetic">
        <property condition="true_strain" value="sigma_m(@Grain)"/>
        <batchfile name="Ni_RX_1193K_d1.pbfx" />
    </TargetProperty>
    

    Please refer to the solution example “kopt_microstructure” for more details.

    Note

    Format of *.opt file (PanAl.opt) is explained in Configuration file of kinetic optimization. The *.opt file defines parameter initial value, upper and lower bounds, and experimental data.

    Initialize the kinetic optimization task instance:
    #################
    m_system = System(pandat=pandat, dump_path=dump_path)
    
    ##################
    m_system.add_task(task_instance=KOpt(opt_file=opt_file))
    
    Run the kinetic optimization task instance:
    ##################
    if __name__ == '__main__':
        m_system.run()
    
  3. Run the script

    After the kinetic optimization is finished, KDB file with optimized parameters is available as /output/kopt_result_TIME_STAMP/*.kdb. See Inputs and outputs of this kinetic optimization for details.

Inputs and outputs of this kinetic optimization

The following figure displays inputs and outputs of this kinetic optimization.

cKOPT diagram
  • File structure

    The follow diagram displays the file structure used by this kinetic optimization:

kopt_precipitation
 |- output  # outputs
 |    |- intermediate
 |    |   |- *.kdb    # .KDB file for each step of optimization
 |    |   └─ *.table  # Result Table from each step of optimization
 |    |
 |    └─ kopt_result_TIME_STAMP
 |        |- *.kdb       # final .KDB file with optimized parameters
 |        └─ report.txt  # A summary of optimization, for example value of optimized parameters, standard deviation and predictions
 |
 └─ resource  # inputs
      |- AlMgSi.tdb         # Thermodynamic database to be used
      |- AA6xxx_opt.kdb     # Kinetic database (with special format) to be used
      |- PanAl.opt          # A Config. file for kinetic optimization
      |- AA6xxx_6005_opt.pbfx  # A template of batch file
      |- size_exp.dat          # Experimental data of particle size
      |- nd_exp.dat            # Experimental data of particle number density
      └─ AA6xxx_6005_opt.dat   # Experimental data of particle number density
  • Inputs

    The input files are under /resource folder.

    • Configuration file of kinetic optimization: A Configuration file for kinetic optimization. The file name is /resource/PanAl.opt.

    • KDB file for optimization: A .KDB file with special format for optimization. The file name is /resource/*.kdb

    • Thermodynamic Database: A .tdb or .pdb file. The file name is /resource/*.tdb or /resource/*.pdb.

    • Batch file: A template of batch file for precipitation calculation. The file name is /resource/*.pbfx.

    • Experimental data for optimization: Experimental data which are used to perform regression analysis. The file name is /resource/*.dat

  • Outputs

    The output files are under /output folder.

    • .KDB file with optimized parameters: the final .KDB file from kinetic optimization. The final .KDB file name is /output/kopt_result_TIME_STAMP/*.kdb.

    • Summary of optimization: a txt file containing parameter value, deviation, and prediction from the final step of optimization. The file name is /output/kopt_result_TIME_STAMP/report.txt.

    • Tables from Pandat calculation: The original tables from Pandat. The tables are stored under /output/intermediate/ folder.

    • .KDB files for each step of optimization: the .KDB file for each step is recorded under intermediate folder for easily retrieving calculation conditions. The .KDB files are stored under /output/intermediate/ folder.

Configuration file of kinetic optimization

One of the input files. The file name is /resource/PanAl.opt. An example of Config. file as an input to HTC:

<?xml version="1.0" encoding="iso-8859-1"?>
<PanPython_Optimization version="1.0">

    <Header copyright="CompuTherm, LLC">
        <!-- example syntax for optimization of model parameters by using PanPython -->
        <Application name="PanPython" version="2023" />
    </Header>
    <batchfile name="AA6xxx_6005_opt.pbfx" />
    <TargetDatabase filename="AA6xxx_opt.kdb">
        <optimization name="opt_activation_Energy_factor" value="4.5e12" lb="1e10" ub="4.5e13"/>
        <optimization name="opt_Interfacial_Energy" value="0.1" lb="0.1" ub="0.5"/>
        <optimization name="opt_Nucleation_Site_Parameter" value="1e-7" lb="1e-7" ub="1e-5"/>
        <optimization name="opt_Strength_Parameter" value="5.0e-5" lb="1e-7" ub="1e-4"/>
        <optimization name="opt_Shearing_Critical_Radius" value="9.0e-9" lb="2.0e-9" ub="10.0e-9"/>
    </TargetDatabase >

    <TargetProperty filename="size_exp.dat" type="kinetic">
        <property condition="log10(t)" value="log10(s(*)*1e10)"/>
    </TargetProperty>

    <TargetProperty filename="nd_exp.dat" type="kinetic">
        <property condition="log10(t)" value="log10(nd(*))"/>
    </TargetProperty>

    <TargetProperty filename="hv_exp.dat" type="strength">
        <property condition="log10(t)" value="hv(*)"/>
    </TargetProperty>

</PanPython_Optimization>
The tags of the xml file is defined in the following table:

Tag

Definition

TargetDatabase

Name of kinetic database to be optimized.

optimization

Optimization setting for a parameter.

TargetProperty

Experimental data for optimization.

property

The properties from experimental data to be used fo optimization.

batchfile

To specify the batchfile that correspond to the experimental condition.

The “properties” of “optimization” tag is defined in the following table:

Property

Definition

name

Name of parameter

value

Initial value of parameter

lb

Lower bound of parameter

ub

Upper bound of parameter

Note

Initial value and bounds of parameter are based on domain knowledge of the materials. A bad guess would trigger meaningless result of optimization. Make sure that the parameters are always positive real numbers.

The properties of TargetProperty tag is defined in the following table:

Property

Definition

filename

File name of experimental data

type

Type of experimental data


Note

The type of TargetProperty decides which data would be optimized together. Generally, type=kinetic would be used for the optimization. All experimental of this type would be specified first. If you prefer to use this optimized data as the initial condition to perform a second set of optimization use the type=strength. In the example “kopt_precipitation”, ‘size_exp.dat’ and ‘nd_exp.dat’ are optimized firstly belonging to type=kinetic. Then the optimized parameters are used to perform a second step optimization for the data ‘hv_exp.dat’ using the type=strength. This two step optimization avoids overfitting. It makes sure that kinetic properties such as particle size and particle number density are the primary data. Strength data such as hardness is only fitted when kinetic data are well fitted.

The properties of property tag is defined in the following table:

Property

Definition

condition

The independent dimension of the property (Usually be time)

value

The dependent dimension of the property

KDB file for optimization

In order to use PanPython to optimize interfacial energy and nucleation site parameter, in /resource/AA6xxx_opt.kdb values of corresponding parameters are replaced by optimization parameters from /resource/PanAl.opt. In the following block from /resource/AA6xxx_opt.kdb:

<ParameterTable type="kinetic" name="Parameters for kinetic model">
<Parameter type="Molar_Volume" value="3.9e-5" description="Molar Volume" />
<Parameter type="Interfacial_Energy" value="opt_Interfacial_Energy" description="Interfacial Energy" />
<Parameter type="Atomic_Spacing" value="4.05E-10" description="Atomic Spacing" />
<Parameter type="Nucleation_Site_Parameter" value="opt_Nucleation_Site_Parameter" description="Nucleation Site Parameter" />
<Parameter type="Steady_State_Nucleation_Rate" value="1" description="Indicate whether or not steady state nucleation rate" />
<Parameter type="Driving_Force_Factor" value="1.0" description="Driving Force Factor" />
<Parameter type="Kinetic_Parameter_Factor" value="3.0" description="a factor for kinetic parameter" />
<Parameter type="Effective_Diffusivity_Factor" value="3" description="a factor for effective diffusivity" />
</ParameterTable >

The key “value” in the two highlighted lines are replace by optimization parameters “opt_Interfacial_Energy” and “opt_Nucleation_Site_Parameter”. These two optimization parameters have been defined in /resource/PanAl.opt:

  <TargetDatabase filename="AA6xxx_opt.kdb">
      <optimization name="opt_activation_Energy_factor" value="4.5e12" lb="1e10" ub="4.5e13"/>
      <optimization name="opt_Interfacial_Energy" value="0.1" lb="0.1" ub="0.5"/>
      <optimization name="opt_Nucleation_Site_Parameter" value="1e-7" lb="1e-7" ub="1e-5"/>
      <optimization name="opt_Strength_Parameter" value="5.0e-5" lb="1e-7" ub="1e-4"/>
      <optimization name="opt_Shearing_Critical_Radius" value="9.0e-9" lb="2.0e-9" ub="10.0e-9"/>
  </TargetDatabase >

Experimental data for optimization

In order to use experimental data to optimize interfacial energy and nucleation site parameter, experimental data must be defined in /resource/PanAl.opt. In /resource/PanAl.opt, the experimental data is defined as:

<TargetProperty filename="size_exp.dat" type="kinetic">
    <property condition="log10(t)" value="log10(s(*)*1e10)"/>
</TargetProperty>
<TargetProperty filename="nd_exp.dat" type="kinetic">
    <property condition="log10(t)" value="log10(nd(*))"/>
</TargetProperty>
<TargetProperty filename="hv_exp.dat" type="strength">
    <property condition="log10(t)" value="hv(*)"/>
</TargetProperty>

In /resource/AA6xxx_6005_opt.pbfx, the experimental data can be mentioned as:

<tables>
    <table source="..\resource\size_exp.dat" name="size_exp"/>
    <table source="..\resource\nd_exp.dat" name="nd_exp"/>
    <table source="..\resource\hv_exp.dat" name="hv_exp"/>
</tables>

Format of experimental data is tab delimited text file. Second line is assumed to have units to make it compatible with table format of Pandat. The experimental data can have more columns. Only the columns specified in the “*.opt” file will be used for optimization. Each set of experimental data to optimized should be stored in a seperate file. For example, the size_exp.dat file is:

log10(t)    log10(s(*)*1e10)

3.257923344 1.523540202
3.556580792 1.600797312
4.161301119 1.674385599
4.474345776 1.708836949
4.7804256   1.700406282
5.44081375  2.13133624
-3.0        1.3
-3.0        1.3
-3.0        1.3
-3.0        1.3
4.161301119 1.674385599
4.474345776 1.708836949
4.161301119 1.674385599
4.474345776 1.708836949