Module “server”¶
-
class
tc_python.server.
LoggingPolicy
(value)¶ Bases:
enum.Enum
Logging policy that determines how the TC-Python logs are presented to the user.
-
FILE
= 1¶ Logging to a file.
-
NONE
= 2¶ No logging at all.
-
SCREEN
= 0¶ Logging to the screen.
-
-
class
tc_python.server.
MetallurgyCalculations
(metallurgy_calculations)¶ Bases:
object
Provides access to the calculation objects for all Process Metallurgy calculations.
These are specialised calculations for working with metallurgical processes. Both equilibrium calculations and kinetic process simulations (Effective Equilibrium Reaction Zone model) are available.
-
with_adiabatic_equilibrium_calculation
(database: tc_python.process_metallurgy.base.ProcessDatabase) → tc_python.process_metallurgy.equilibrium.AdiabaticEquilibriumCalculation¶ Creates an adiabatic equilibrium calculation for Process Metallurgy.
- Parameters
database – The thermodynamic database used in the calculation
- Returns
A new
AdiabaticEquilibriumCalculation
object
-
with_adiabatic_process_calculation
(database: tc_python.process_metallurgy.base.ProcessDatabase) → tc_python.process_metallurgy.process.ProcessSimulationCalculation¶ Creates an adiabatic kinetic process simulation (EERZ, i.e. Effective Equilibrium Reaction Zone model).
- Parameters
database – The thermodynamic database used in the calculation
- Returns
A new
ProcessSimulationCalculation
object
-
with_isothermal_equilibrium_calculation
(database: tc_python.process_metallurgy.base.ProcessDatabase) → tc_python.process_metallurgy.equilibrium.IsoThermalEquilibriumCalculation¶ Creates an isothermal equilibrium calculation for Process Metallurgy.
- Parameters
database – The thermodynamic database used in the calculation
- Returns
A new
IsoThermalEquilibriumCalculation
object
-
-
class
tc_python.server.
ResultLoader
(result_loader)¶ Bases:
object
Contains methods for loading results from previously done calculations.
-
diffusion
(path: str) → tc_python.diffusion.DiffusionCalculationResult¶ Loads a
DiffusionCalculationResult
from disc.- Parameters
path – path to the folder where result was previously saved.
- Returns
A new
DiffusionCalculationResult
object which later can be used to get specific values from the calculated result
-
phase_diagram
(path: str) → tc_python.step_or_map_diagrams.PhaseDiagramResult¶ Loads a
PhaseDiagramResult
from disc.- Parameters
path – path to the folder where result was previously saved.
- Returns
A new
PhaseDiagramResult
object which later can be used to get specific values from the calculated result
-
precipitation_TTT_or_CCT
(path: str) → tc_python.precipitation.PrecipitationCalculationTTTorCCTResult¶ Loads a
PrecipitationCalculationTTTorCCTResult
from disc.- Parameters
path – path to the folder where result was previously saved.
- Returns
A new
PrecipitationCalculationTTTorCCTResult
object which later can be used to get specific values from the calculated result
-
precipitation_single
(path: str) → tc_python.precipitation.PrecipitationCalculationSingleResult¶ Loads a
PrecipitationCalculationSingleResult
from disc.- Parameters
path – path to the folder where result was previously saved.
- Returns
A new
PrecipitationCalculationSingleResult
object which later can be used to get specific values from the calculated result
-
property_diagram
(path: str) → tc_python.step_or_map_diagrams.PropertyDiagramResult¶ Loads a
PropertyDiagramResult
from disc.- Parameters
path – path to the folder where result was previously saved.
- Returns
A new
PropertyDiagramResult
object which later can be used to get specific values from the calculated result
-
property_model
(path: str) → tc_python.propertymodel.PropertyModelResult¶ Loads a
PropertyModelResult
from disc.- Parameters
path – path to the folder where result was previously saved.
- Returns
A new
PropertyModelResult
object which later can be used to get specific values from the calculated result
-
scheil
(path: str) → tc_python.scheil.ScheilCalculationResult¶ Loads a
ScheilCalculationResult
from disc.- Parameters
path – path to the folder where result was previously saved.
- Returns
A new
ScheilCalculationResult
object which later can be used to get specific values from the calculated result
-
single_equilibrium
(path: str) → tc_python.single_equilibrium.SingleEquilibriumResult¶ Loads a
SingleEquilibriumResult
from disc.- Parameters
path – path to the folder where result was previously saved.
- Returns
A new
SingleEquilibriumResult
object which later can be used to get specific values from the calculated result
-
-
class
tc_python.server.
SetUp
(debug_logging=False)¶ Bases:
object
Starting point for all calculations.
Note
This class exposes methods that have no precondition, it is used for choosing databases and elements.
-
disable_caching
()¶ A previously set cache folder is no longer used.
Note
Within the session, caching is activated and used through the default temporary directory.
- Returns
This SetUp object
-
get_database_info
(database_short_name: str) → str¶ Obtains the short information available for the specified database.
- Parameters
database_short_name – The name of the database (i.e. “FEDEMO”, …)
- Returns
The short information about the database
-
get_database_path_on_disk
(database_short_name: str) → str¶ Obtains the path to the database file on disk. TCPATH is a placeholder for the root path of the used Thermo-Calc installation.
Note
Encrypted databases (*.TDC) cannot be edited.
- Parameters
database_short_name – The name of the database (i.e. “FEDEMO”, …)
- Returns
The path to the database on disk
-
get_databases
() → List[str]¶ Obtains the short names of all databases available in the used Thermo-Calc installation.
Note
Only databases with a valid license are listed.
- Returns
List of the available databases
-
get_property_models
(path_to_models: str = '') → Set[str]¶ Lists the names of all Property Models in the specified directory.
If the directory is not specified, the Property Model folder used by the normal Thermo-Calc application is used.
- Parameters
path_to_models – The path where the Property Models are installed. If no value is entered, the Property Model folder used by the normal Thermo-Calc application is used.
- Returns
Set containing all Property Model names
-
load_result_from_disk
() → tc_python.server.ResultLoader¶ Loads a previously calculated result from disk.
Note
This only works for results created by calling one of the
save_result()
methods on a Result class created from a calculation.- Returns
A new
ResultLoader
object
-
select_database_and_elements
(database_name: str, list_of_elements: List[str]) → tc_python.system.SystemBuilder¶ Selects a first thermodynamic or kinetic database and selects the elements in it.
- Parameters
database_name – The name of the database, for example “FEDEMO”
list_of_elements – The list of the selected elements in that database, for example [“Fe”, “C”]
- Returns
A new
SystemBuilder
object
-
select_thermodynamic_and_kinetic_databases_with_elements
(thermodynamic_db_name: str, kinetic_db_name: str, list_of_elements: List[str]) → tc_python.system.MultiDatabaseSystemBuilder¶ Selects the thermodynamic and kinetic database at once, guarantees that the databases are added in the correct order. Further rejection or selection of phases applies to both databases.
- Parameters
thermodynamic_db_name – The thermodynamic database name, for example “FEDEMO”
kinetic_db_name – The kinetic database name, for example “MFEDEMO”
list_of_elements – The list of the selected elements in that database, for example [“Fe”, “C”]
- Returns
A new
MultiDatabaseSystemBuilder
object
-
select_user_database_and_elements
(path_to_user_database: str, list_of_elements: List[str]) → tc_python.system.SystemBuilder¶ Selects a user-defined database and selects the elements in it.
Note
By using a r-literal, it is possible to use slashes on all platforms, also on Windows: select_user_database_and_elements(r”my path/user_db.tdb”, [“Fe”, “Cr”]])
Otherwise it is required to use double back-slashes on Windows as separator.
Note
On Linux and Mac the path is case-sensitive, also the file ending.
- Parameters
path_to_user_database – The path to the database file (“database”.TDB), defaults to the current working directory. Only filename is required if the database is located in the same folder as the script.
list_of_elements – The list of the selected elements in that database, for example [“Fe”, “C”]
- Returns
A new
SystemBuilder
object
-
set_cache_folder
(path: str = '', precision_for_floats: int = 12)¶ Sets a folder where results from calculations and state of systems are saved. If at any time a calculation is run which has the exact same setting as a previous, the calculation is not re-run. The result is instead loaded from this folder.
Note
The same folder can be used in several scripts, and it can even be shared between different users. It can be a network folder.
- Parameters
path – path to the folder where results should be stored. It can be relative or absolute.
precision_for_floats – The number of significant figures used when comparing if the calculation has the same setting as a previous.
- Returns
This SetUp object
-
set_ges_version
(version: int = 6)¶ Setting the version of the Gibbs Energy System (GES).
- Parameters
version – The GES-version (currently version 5 or 6)
- Returns
This SetUp object
-
set_log_level_to_debug
()¶ Sets log level to DEBUG
- Returns
This SetUp object
-
set_log_level_to_info
()¶ Sets log level to INFO
- Returns
This SetUp object
-
with_metallurgy
() → tc_python.server.MetallurgyCalculations¶ Provides access to the calculation objects for all Process Metallurgy calculations.
These are specialised calculations for working with metallurgical processes. Both equilibrium calculations and kinetic process simulations (Effective Equilibrium Reaction Zone model) are available.
-
-
class
tc_python.server.
TCPython
(logging_policy=<LoggingPolicy.SCREEN: 0>, log_file=None, debug_mode=False, debug_logging=False, do_throw_on_backend_hard_crash=True, port_number=0)¶ Bases:
object
Starting point of the API. Typical syntax:
with TCPython() as session: session.select_database_and_elements(...)
Note
Each usage of with TCPython() causes significant overhead (starting a new process, stopping the old one, cleaning up the temporary disk space). Usually it is recommendable to call with TCPython() only once for each process, even if working in a loop. Instead you should pass the session or calculator object into the loop and use them there.
If necessary, beginning from version 2019a it is however possible to call with TCPython safely multiple times.
-
tc_python.server.
start_api_server
(logging_policy=<LoggingPolicy.SCREEN: 0>, log_file=None, debug_mode=False, is_unittest=False, do_throw_on_backend_hard_crash=True, port_number=0)¶ Starts a process of the API server and sets up the socket communication with it.
- Parameters
logging_policy – Determines if the TC-Python log output is sent to the screen (LoggingPolicy.SCREEN), to file (LoggingPolicy.FILE) or nothing is logged at all (LoggingPolicy.NONE) Default: LoggingPolicy.SCREEN. Note that the log-handlers can also be adapted through the tc_python.LOGGER object at any time.
log_file – The log-file relative to the current path or absolute, only relevant if logging_policy=LoggingPolicy.FILE. Log-output will be appended.
debug_mode – If True it is tried to open a connection to an already running API-server. This is only used for debugging the API itself.
is_unittest – Should be True if called by a unit test, only to be used internally for development.
do_throw_on_backend_hard_crash – If True an UnrecoverableCalculationException will be thrown if the Java-backend crashes hard, if False the application will simply crash with a FORTRAN-stacktrace. If `True` the exception can be caught outside of the `with`-clause and the application can continue, if `False` more information about the error is shown by the stacktrace..
port_number – The port number for the communication with the Java-backend server. This is not required to be changed by normal users.
Warning
Most users should use
TCPython
using a with-statement for automatic management of the resources (network sockets and temporary files). If you anyway need to use that method, make sure to callstop_api_server()
in any case using the try-finally-pattern.
-
tc_python.server.
start_matlab_server
(logging_policy=<LoggingPolicy.SCREEN: 0>, log_file=None, debug_mode=False, is_unittest=False, do_throw_on_backend_hard_crash=True, port_number=0)¶
-
tc_python.server.
stop_api_server
(gateway_id: str = None)¶ Clears all resources used by the session (i.e. shuts down the API server and deletes all temporary files). The disk usage of temporary files might be significant.
Warning
Call this method only if you used
start_api_server()
initially. It should never be called when the API has been initialized in a with-statement usingTCPython
.