### Example Equilibrium Condition in OC Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Demonstrates how to specify complex equilibrium conditions in the OpenCalphad command line, such as defining a minimum of a liquidus line or a second-order transition. ```text x(liq,cr)-x(bcc,cr)=0 ``` ```text y(bcc-B2,Al)-y(bcc-B2,Al#2)=0.01 ``` -------------------------------- ### GET /list/short Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Provides a concise summary of elements, species, phases, or models based on the selected option. ```APIDOC ## GET /list/short ### Description Lists essential data in a short format based on the provided option. ### Method GET ### Endpoint /list/short ### Parameters #### Query Parameters - **option** (string) - Required - Options: 'A' (elements/species/phases), 'C' (components), 'M' (models/constitution), 'P' (stable phases). ``` -------------------------------- ### Example output for phase equilibrium data Source: https://github.com/sundmanbo/opencalphad/blob/master/OCisoCbinding/pyOC/example.ipynb Sample JSON-like output representing the structure of phase molar amounts, element compositions, site counts, and constituent compositions. ```json (OpenCalphad being verbose): phases at equilibrium: phase molar amounts: { "FCC_A1#1": 0.01920542894617253, "M23C6": 0.02977621280681491, "M6C": 0.09441638360236765, "FCC_A1_AUTO#2": 0.856601974644645 } phase element composition: { "FCC_A1#1": { "C": 0.45665297099480046, "CR": 0.03426417107693683, "FE": 0.0020841630748334116, "MO": 0.1443298386826512, "SI": 6.681137603878831e-10, "V": 0.3626688555026644 }, "M23C6": { "C": 0.2068965517241379, "CR": 0.3414624222993837, "FE": 0.3838209757158874, "MO": 0.06769132200309422, "SI": 0.0, "V": 0.00012872825749663693 }, "M6C": { "C": 0.14285714285714285, "CR": 0.06508399462251023, "FE": 0.38133540345297173, "MO": 0.39191933121811307, "SI": 0.0, "V": 0.018804127849262088 }, "FCC_A1_AUTO#2": { "C": 0.013519853563065565, "CR": 0.050232768562391776, "FE": 0.9216963669684142, "MO": 0.009583081354863507, "SI": 0.003502209983129125, "V": 0.001465719568135902 } } phase sites: { "FCC_A1#1": [ 1.0, 1.0 ], "M23C6": [ 20.0, 3.0, 6.0 ], "M6C": [ 2.0, 2.0, 2.0, 1.0 ], "FCC_A1_AUTO#2": [ 1.0, 1.0 ] } phase constituent composition: { "FCC_A1#1": { "sublattice 0": { "CR": 0.06306130198166399, "FE": 0.0038357862720796564, "MO": 0.26563104420926176, "SI": 1.229626232816835e-09, "V": 0.6674718663073684 }, "sublattice 1": { "C": 0.8404444059091938, "VA": 0.15955559409080622 } }, "M23C6": { "sublattice 0": { "CR": 0.4730948138378144, "FE": 0.5268934005119624, "V": 1.1785650223144731e-05 }, "sublattice 1": { "CR": 0.14683798997528025, "FE": 0.19764676184049562, "MO": 0.654349446029911, "V": 0.0011658021543131923 }, "sublattice 2": { "C": 1.0 } }, "M6C": { "sublattice 0": { "FE": 1.0 }, "sublattice 1": { "MO": 1.0 }, "sublattice 2": { "CR": 0.2277939811787858, "FE": 0.33467391208540104, "MO": 0.37171765926339584, "V": 0.06581444747241731 }, "sublattice 3": { "C": 1.0 } }, "FCC_A1_AUTO#2": { "sublattice 0": { "CR": 0.050921215945224446, "FE": 0.9343283494325632, "MO": 0.00971441887551069, "SI": 0.0035502082791820494, "V": 0.0014858074675196773 }, "sublattice 1": { "C": 0.013705145118123152, "VA": 0.9862948548818768 } } } ``` -------------------------------- ### Define Parameters for Carbon Phases Source: https://github.com/sundmanbo/opencalphad/blob/master/changes.txt Example of defining Gibbs energy and LNTH parameters for carbon phases using multiple Einstein functions. ```OpenCalphad PARAMETER G(GRAPHITE,C) 10 +GHSERCC; 6000 N 20HE ! PARAMETER LNTH(GRAPHITE,C) 10 LN(1953); 6000 N 20HE ! ``` -------------------------------- ### tqgetv - Get State Variable Values Source: https://context7.com/sundmanbo/opencalphad/llms.txt Retrieves equilibrium results including temperature, pressure, Gibbs energy, chemical potentials, phase amounts, and compositions. ```APIDOC ## tqgetv ### Description Retrieves equilibrium results including temperature, pressure, Gibbs energy, chemical potentials, phase amounts, and compositions. ### Parameters - **var** (character) - The state variable identifier (e.g., 'T', 'G', 'GM', 'MU', 'NP', 'X'). - **phtupx** (integer) - Phase tuple index; use -1 for all phases or 0 for global variables. - **comp** (integer) - Component index; use -1 for all components. - **n3** (integer) - Number of values to retrieve. - **values** (double precision array) - Output array for retrieved values. - **ceq** (type) - Equilibrium data pointer. ``` -------------------------------- ### Print output for equilibrium calculations Source: https://github.com/sundmanbo/opencalphad/blob/master/OCisoCbinding/pyOC/example.ipynb Displays the results of the print statements from the equilibrium calculation example. ```text n_C in FCC_A1#1 = 0.45665297099480046 a_i in FCC_A1#1 = [1.0, 1.0] y_V^0 in liquid = 0.6674718663073684 ``` -------------------------------- ### TPFUN Expression Example Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html An example of a TPFUN expression defining a thermodynamic parameter with temperature and pressure dependence, including a breakpoint and bibliographic reference. Ensure continuity at breakpoints. ```text 298.15 -8856.94+157.48*T-26.908*T*LN(T)+.00189435*T**2 -1.47721E-06*T**3+139250*T**(-1); 2180 Y -34869.344+344.18*T-50*T*LN(T)-2.88526E+32*T**(-9); 6000 N 91Din ``` -------------------------------- ### POST /calculate/no-global Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Calculates equilibrium without using the global grid minimizer for start constitutions. ```APIDOC ## POST /calculate/no-global ### Description Calculates equilibrium using the current equilibrium as the start point, bypassing the global grid minimizer. Useful for small condition changes. ### Method POST ### Endpoint /calculate/no-global ``` -------------------------------- ### GET /list/csv Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Exports STEP calculation results to a CSV file. ```APIDOC ## GET /list/csv ### Description Lists the result from a STEP calculation in Comma Separated Value (CSV) format for external processing. ### Method GET ### Endpoint /list/csv ### Parameters #### Query Parameters - **independent_variable** (string) - Required - Single valued state variable (e.g., T). - **dependent_variables** (string) - Required - Variables to list (e.g., NP(*), DGM(#)). ``` -------------------------------- ### Example Macro for Site Fraction Condition Source: https://github.com/sundmanbo/opencalphad/blob/master/changes.txt This macro, STEP8, shows how to set a condition on a constituent (site) fraction of a phase, specifically setting the constituent fraction of H2O in a gas phase. This is equivalent to setting its partial pressure in an ideal gas phase. ```text STEP8 ``` -------------------------------- ### Get Phase Equilibrium Data with Python Source: https://context7.com/sundmanbo/opencalphad/llms.txt Retrieve and print phase amounts, compositions, sublattice sites, and constituent fractions from phase equilibrium data. Access constituent descriptions like mass and charge. This is useful for analyzing the results of equilibrium calculations. ```python phasesAtEq = oc.getPhasesAtEquilibrium() molarAmounts = phasesAtEq.getPhaseMolarAmounts() print('Phase amounts:', molarAmounts) compositions = phasesAtEq.getPhaseElementComposition() for phase, comp in compositions.items(): print(f'{phase}: {comp}') sites = phasesAtEq.getPhaseSites() constituentComp = phasesAtEq.getPhaseConstituentComposition() print('Sublattice sites:', sites) print('Constituent fractions:', constituentComp) constituentsDesc = oc.getConstituentsDescription() print('Vanadium mass:', constituentsDesc['V']['mass']) print('Vanadium charge:', constituentsDesc['V']['charge']) ``` -------------------------------- ### Example Macro for Gibbs Triangle Source: https://github.com/sundmanbo/opencalphad/blob/master/changes.txt This macro demonstrates the use of the 'extra' subcommand for plot options, such as 'extra Gibbs-triangle y'. This syntax is new in OC version 5.048. ```text extra Gibbs-triangle y ``` -------------------------------- ### Example Macro for Constituent Fraction Condition Source: https://github.com/sundmanbo/opencalphad/blob/master/changes.txt This macro, step9.OCM, demonstrates setting a condition on a constituent fraction, allowing for expressions necessary for calculating second-order transitions. It also tests a new expression for the SRO parameter. ```text step9.OCM ``` -------------------------------- ### Compute Transition Temperatures Source: https://github.com/sundmanbo/opencalphad/blob/master/examples/TQ4lib/Cpp/Scheil/input.txt Computes transition temperatures within specified parameters. Parameters include start temperature, end temperature, temperature step, and a value related to phase fraction or similar. ```OpenCalphad Computation COMPUTE_TRANSITION_TEMPERATURES<1100.0/400.0/0.0010000/20 > ``` -------------------------------- ### Configuration and Execution Commands Source: https://github.com/sundmanbo/opencalphad/blob/master/examples/TQ4lib/Cpp/Scheil/input.txt Endpoints for setting up the environment, defining thermodynamic systems, and running phase transition calculations. ```APIDOC ## Configuration Commands ### Description Commands to define file paths, thermodynamic data, and system units. ### Parameters - **DEFINE_OUTPUT_FILE_NAME** (string) - Name of the log file. - **TDB_FILE_NAME** (string) - Name of the thermodynamic data file. - **DEFINE_REF_ELEMENT** (string) - Reference element definition. - **DEFINE_LIQUID_NAME** (string) - Name of the liquid phase. - **DEFINE_SOLSOL_NAME** (string) - Name of the solid solution phase. - **DEFINE_UNIT_COMPO_INPUT** (string) - Composition unit (e.g., W%). - **DEFINE_UNIT_TEMP_INPUT** (string) - Temperature unit (C or K). - **DEFINE_NCPU** (integer) - Number of CPUs to use. ## Calculation Commands ### Description Commands to execute specific thermodynamic calculations. ### Parameters - **DEFINE_COMPOSITION** (string) - Composition definition (e.g., MG=5/SI=1). - **LIQUIDUS** (void) - Calculate liquidus temperature. - **SOLIDUS** (void) - Calculate solidus temperature. - **COMPUTE_TRANSITION_TEMPERATURES** (string) - Parameters: T_start/T_end/step/iterations. - **COMPUTE_EQUILIBRIUM** (string) - Parameters: T/P. - **SCHEIL_SOLIDIFICATION** (string) - Parameters: filename/fraction_solid/step/something. ``` -------------------------------- ### GET /list/tpfun_symbols Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Lists TPFUN expressions. ```APIDOC ## GET /list/tpfun_symbols ### Description Lists all or specific TPFUN expressions. Use '*' for all or specific prefixes to filter. ``` -------------------------------- ### Basic Equilibrium Calculation in C Source: https://context7.com/sundmanbo/opencalphad/llms.txt Demonstrates initializing OpenCalphad, reading a database, setting conditions (temperature, pressure, composition), performing an equilibrium calculation, and retrieving results like Gibbs energy, phase amounts, and chemical potentials. Ensure the 'crfe.TDB' database is accessible. ```c #include "octqc.h" #include #include int main() { void *ceq; // Equilibrium pointer int n, n1, n2, n3, cnum; double value, values[100]; char phasename[25]; // Initialize OpenCalphad c_tqini(0, &ceq); // Read database c_tqrfil("crfe.TDB", &ceq); // Check number of elements and phases printf("Elements: %d, Phases: %d\n", c_nel, c_ntup); // Set conditions c_tqsetc("T", 0, 0, 1000.0, &cnum, ceq); c_tqsetc("P", 0, 0, 1.0e5, &cnum, ceq); c_tqsetc("N", 0, 0, 1.0, &cnum, ceq); c_tqsetc("X", 1, 0, 0.3, &cnum, ceq); // X(Cr)=0.3 // Calculate equilibrium (n1>=0 uses grid minimizer) n1 = 0; c_tqce("", n1, 0, &value, &ceq); // Check for errors int err = c_errors_number(); if (err != 0) { printf("Calculation failed with error: %d\n", err); c_reset_errors_number(); return 1; } // Get Gibbs energy n3 = 1; c_tqgetv("G", 0, 0, &n3, values, &ceq); printf("Gibbs energy: %e J\n", values[0]); // Get phase amounts n3 = c_ntup; c_tqgetv("NP", -1, 0, &n3, values, &ceq); // List stable phases for (int i = 0; i < c_ntup; i++) { if (values[i] > 0.0) { c_tqgpn(i+1, phasename, &ceq); printf("Phase %s: %e mol\n", phasename, values[i]); } } // Get compositions n3 = c_nel; c_tqgetv("MU", -1, 0, &n3, values, &ceq); printf("Chemical potentials:\n"); for (int i = 0; i < c_nel; i++) { printf(" %d: %e J/mol\n", i+1, values[i]); } // Clean up c_tqfree(); return 0; } ``` -------------------------------- ### GET /list/symbols Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Lists all state variable symbols and their expressions. ```APIDOC ## GET /list/symbols ### Description Lists all state variable symbols and their associated expressions. Does not return calculated values. ``` -------------------------------- ### Initialize pyOC Environment Source: https://github.com/sundmanbo/opencalphad/blob/master/OCisoCbinding/pyOC/example.ipynb Import necessary modules and set up the environment for OpenCalphad operations. ```python import os ``` ```python import pyOC from pyOC import opencalphad as oc from pyOC import PhaseStatus as phStat from pyOC import GridMinimizerStatus as gmStat ``` -------------------------------- ### Manage Multiple Equilibria with tqcceq and tqselceq Source: https://context7.com/sundmanbo/opencalphad/llms.txt Demonstrates creating independent equilibrium records and switching between them for comparative calculations. ```fortran program multiple_equilibria use liboctq implicit none type(gtp_equilibrium_data), pointer :: ceq, newceq integer :: n, n1, cnum double precision :: values(10) character(len=24) :: name call tqini(n, ceq) call tqrfil('crfe.TDB', ceq) ! Set up first equilibrium call tqsetc('T', 0, 0, 1000.0d0, cnum, ceq) call tqsetc('P', 0, 0, 1.0d5, cnum, ceq) call tqsetc('N', 0, 0, 1.0d0, cnum, ceq) call tqsetc('X', 1, 0, 0.3d0, cnum, ceq) call tqce(' ', 0, 0, values(1), ceq) ! Copy to new equilibrium record name = 'EQ2' call tqcceq(name, n1, newceq, ceq) write(*,*) 'Created equilibrium copy:', n1 ! Modify conditions in the copy call tqsetc('T', 0, 0, 1200.0d0, cnum, newceq) call tqce(' ', 0, 0, values(1), newceq) ! Switch back to original equilibrium call tqselceq('DEFAULT', ceq) ! Compare results call tqgetv('G', 0, 0, n1, values, ceq) write(*,*) 'G at 1000K:', values(1) call tqselceq('EQ2', ceq) call tqgetv('G', 0, 0, n1, values, ceq) write(*,*) 'G at 1200K:', values(1) end program multiple_equilibria ``` -------------------------------- ### Open Online Help Browser Source: https://github.com/sundmanbo/opencalphad/blob/master/changes.txt Use two question marks '??' to open the browser to the current menu in the online help facility. Ensure the OCHOME environment variable is set correctly. ```text ?? ``` -------------------------------- ### GET /list/state_variables Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Lists the current values of individual state variables. ```APIDOC ## GET /list/state_variables ### Description Lists values of individual state variables like G, HM, or X. Also supports listing calculated parameter identifiers like Curie temperatures or mobility logarithms. ### Method GET ### Endpoint /list/state_variables ``` -------------------------------- ### Load Thermodynamic Database Source: https://github.com/sundmanbo/opencalphad/blob/master/OCisoCbinding/pyOC/example.ipynb Read a .tdb file from the environment path to initialize the thermodynamic system. ```python tdbFile=os.environ.get('OCPUBLICDATA')+'/steel7.TDB' oc.readtdb(tdbFile) ``` -------------------------------- ### Comment in Macro File Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Lines starting with '@$' are ignored by the OC software and can be used for comments. ```plaintext @$ Ask user for the condition on the T ``` -------------------------------- ### Enter Material Workflow Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Interactive session for defining a material and performing an equilibrium calculation. ```text OC4:enter mat Database:steel7 Elements: C , MO, V , CR, FE, SI, Major element or material:fe Input in mass percent? /Y/: Input expected in mass percent First alloying element:c Mass percent: /1/: Second alloying element:cr Mass percent: /1/: 5 Third alloying element:mo Mass percent: /1/: 8 Next alloying element:v Mass percent: /1/: Next alloying element: 3E reading a TDB file 3D em: W%(C)=1 W%(CR)=5 W%(MO)=8 W%(V)=1 N=1 Temperature /1000/: 3Y Constitution of metastable phases set 3Y Composition set(s) created: 1 Gridmin: 18846 points 6.25E-02 s and 78 clockcycles, T= 1000.00 Phase change: its/add/remove: 5 0 21 Equilibrium calculation 19 its, 6.2500E-02 s and 94 clockcycles ``` -------------------------------- ### Initialize OpenCalphad Workspace (Fortran) Source: https://context7.com/sundmanbo/opencalphad/llms.txt Initializes the OpenCalphad workspace and creates the default equilibrium record. This must be called before any other TQ routines. It returns an integer status and a pointer to the equilibrium data. ```fortran program init_example use liboctq implicit none type(gtp_equilibrium_data), pointer :: ceq integer :: n ! Initialize workspace call tqini(n, ceq) if (gx%bmperr .ne. 0) then write(*,*) 'Initialization failed with error:', gx%bmperr stop endif write(*,*) 'OpenCalphad initialized successfully' write(*,*) 'Equilibrium name:', ceq%eqname end program init_example ``` -------------------------------- ### GET /list/results Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Lists the results of an equilibrium calculation, including conditions, global data, component data, and stable phases. ```APIDOC ## GET /list/results ### Description Lists the results of an equilibrium calculation. The output includes current conditions, global data, component specific data, and a list of stable phases with amounts, compositions, and constitutions. ### Method GET ### Endpoint /list/results ### Parameters #### Query Parameters - **option** (integer) - Required - Formatting option (1-9) defining output units (mole/mass fractions) and sorting order (value/alphabetical). - **output** (string) - Optional - File path to write the output. - **append** (string) - Optional - File path to append the output. ``` -------------------------------- ### Set Initial Temperature and Pressure Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Local values of T (temperature) and P (pressure) can be set. These are not conditions but are used for commands like CALCULATE PHASE. ```text --->OC5:set c t=1000 p=1e5 ``` -------------------------------- ### Set Scaled Coefficient Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Allows specifying a coefficient for optimization with a start value, scaling factor, and minimum/maximum values. Currently not implemented. ```APIDOC ## SET SCALED COEFFICIENT ### Description Sets a coefficient for optimization, including a start value, scaling factor, and optional minimum and maximum values. The `SET VARIABLE` command sets the scaling factor equal to the start value and has no min or max values. ### Method SET SCALED COEFFICIENT ### Endpoint Not applicable (command-line interface) ### Parameters None (Not implemented yet) ### Request Example None (Not implemented yet) ### Response None (Not implemented yet) ``` -------------------------------- ### tqini - Initialize Workspace Source: https://context7.com/sundmanbo/opencalphad/llms.txt Initializes the OpenCalphad workspace and creates the default equilibrium record. This must be called before any other TQ routines. ```APIDOC ## tqini ### Description Initializes the OpenCalphad workspace and creates the default equilibrium record. ### Parameters - **n** (integer) - Output parameter for workspace index. - **ceq** (gtp_equilibrium_data) - Pointer to the equilibrium data structure. ``` -------------------------------- ### Stop in Macro File Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Lines starting with '@&' create a stop point in the macro execution, allowing for inspection of output. The macro resumes after pressing ENTER/RETURN. ```plaintext @&Input-new-temperature ``` -------------------------------- ### Link OpenCalphad with Alternative Build Configurations Source: https://github.com/sundmanbo/opencalphad/blob/master/changes.txt Use these specific make targets on Windows or UNIX to exclude popup windows or command-line editing features. ```text linkmake-notinyfd ``` ```text linkpara-notinyfd ``` ```text Makefile-nogetkey ``` -------------------------------- ### Show Commands Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Commands for displaying information. ```APIDOC ## Show Commands ### Description Commands to display information about the system or its components. ### Endpoints - `show property:` ### Parameters - **property:** (string) - Displays specific properties. ``` -------------------------------- ### Scheil Solidification Simulation in C++ Source: https://context7.com/sundmanbo/opencalphad/llms.txt Implements a Scheil solidification calculator using a C++ class that wraps the OpenCalphad C API. It allows setting composition, calculating equilibrium at different temperatures, and retrieving the liquid fraction. Requires a database file like 'cost507r.TDB'. ```cpp #include "octqc.h" #include #include #include class ScheilCalculator { private: void* ceq; int nel, ntup; public: ScheilCalculator(const char* database) { c_tqini(0, &ceq); c_tqrfil(database, &ceq); nel = c_nel; ntup = c_ntup; } void setComposition(double T, double P, const std::vector>& composition) { int cnum; c_tqsetc("T", 0, 0, T, &cnum, ceq); c_tqsetc("P", 0, 0, P, &cnum, ceq); c_tqsetc("N", 0, 0, 1.0, &cnum, ceq); for (const auto& [compIdx, moleFrac] : composition) { c_tqsetc("X", compIdx, 0, moleFrac, &cnum, ceq); } } bool calculate() { double value; c_tqce("", 0, 0, &value, &ceq); return c_errors_number() == 0; } double getLiquidFraction() { int n3 = 1; double np; // Find liquid phase tuple index first for (int i = 1; i <= c_ntup; i++) { char pname[25]; c_tqgpn(i, pname, &ceq); if (strncmp(pname, "LIQUID", 6) == 0) { c_tqgetv("NP", i, 0, &n3, &np, &ceq); return np; } } return 0.0; } void runScheil(double Tstart, double Tend, double dT) { std::cout << "T(K)\tLiquid_Fraction\n"; double T = Tstart; while (T > Tend && getLiquidFraction() > 0.001) { int cnum; c_tqsetc("T", 0, 0, T, &cnum, ceq); if (calculate()) { double fliq = getLiquidFraction(); std::cout << T << "\t" << fliq << "\n"; } T -= dT; } } ~ScheilCalculator() { c_tqfree(); } }; int main() { ScheilCalculator calc("cost507r.TDB"); // Al-Cu-Mg alloy std::vector> comp = { {1, 0.02}, // Cu {2, 0.03}, // Mg }; calc.setComposition(1000.0, 1e5, comp); calc.calculate(); calc.runScheil(900.0, 400.0, 5.0); return 0; } ``` -------------------------------- ### List Equilibrium Conditions Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Lists the current conditions for equilibrium calculation, including component amounts, temperature, and pressure. This command helps verify the input parameters before proceeding with calculations. ```text --->OC5:l c ``` -------------------------------- ### tqcceq / tqselceq - Copy and Select Equilibria Source: https://context7.com/sundmanbo/opencalphad/llms.txt Creates copies of equilibrium records and selects which one to use for calculations. ```APIDOC ## tqcceq / tqselceq ### Description Creates copies of equilibrium records and selects which one to use for calculations. ### Methods - **tqcceq(name, n1, newceq, ceq)**: Creates a copy of the current equilibrium record. - **tqselceq(name, ceq)**: Switches the active equilibrium record. ``` -------------------------------- ### User Input in Macro File Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Use '@?' followed by a prompt string to ask the user for input. The program waits for keyboard input, and the entered value is used for the subsequent command. ```plaintext @?Input-new-temperature ``` -------------------------------- ### List Ternary System Asymmetries (OC6) Source: https://github.com/sundmanbo/opencalphad/blob/master/changes.txt Use this command to list the asymmetries of ternary systems. It helps in understanding the configuration of asymmetric cations within a ternary system. ```bash --->OC6:l mq ms asym y ``` -------------------------------- ### Calculate Phase Properties with tqcph1 Source: https://context7.com/sundmanbo/opencalphad/llms.txt Computes Gibbs energy and its derivatives for a specific phase without performing a full equilibrium calculation. Requires initialization via tqini and database loading via tqrfil. ```fortran program phase_properties use liboctq implicit none type(gtp_equilibrium_data), pointer :: ceq integer :: n, n1, n2, n3, cnum, nofc double precision :: gtp(6), dgdy(100), d2gdydt(100), d2gdydp(100), d2gdy2(5050) call tqini(n, ceq) call tqrfil('crfe.TDB', ceq) ! Set T and P conditions call tqsetc('T', 0, 0, 1000.0d0, cnum, ceq) call tqsetc('P', 0, 0, 1.0d5, cnum, ceq) ! Calculate phase properties ! n1 = phase tuple index ! n2 = calculation mode (0=G and T,P derivatives, 1=also composition derivatives, 2=also 2nd derivatives) n1 = 1 n2 = 2 call tqcph1(n1, n2, n3, gtp, dgdy, d2gdydt, d2gdydp, d2gdy2, ceq) write(*,*) 'Number of constituents:', n3 write(*,*) 'G/RT:', gtp(1) write(*,*) 'dG/dT:', gtp(2) write(*,*) 'dG/dP:', gtp(3) write(*,*) 'd2G/dT2:', gtp(4) write(*,*) 'd2G/dTdP:', gtp(5) write(*,*) 'd2G/dP2:', gtp(6) ! First derivatives w.r.t. constituent fractions write(*,*) 'dG/dy:', (dgdy(n), n=1,n3) end program phase_properties ``` -------------------------------- ### POST /calculate/all-equilibria Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Calculates all equilibria with non-zero weight as defined by the current range settings. ```APIDOC ## POST /calculate/all-equilibria ### Description Calculates all equilibria with non-zero weight. Intended for assessment procedures and testing parallelization. ### Method POST ### Endpoint /calculate/all-equilibria ``` -------------------------------- ### tqce - Calculate Equilibrium Source: https://context7.com/sundmanbo/opencalphad/llms.txt Calculates thermodynamic equilibrium using the set conditions. Uses grid minimization by default to find the global minimum. ```APIDOC ## tqce ### Description Performs the equilibrium calculation based on previously defined conditions. ### Parameters - **target** (character) - Target string for calculation. - **n1** (integer) - Minimizer control (0 for grid minimizer, -1 to skip). - **n2** (integer) - Secondary control parameter. - **value** (double precision) - Resulting value. - **ceq** (gtp_equilibrium_data) - Pointer to the equilibrium data structure. ``` -------------------------------- ### Set Commands Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Commands for setting various parameters and configurations. ```APIDOC ## Set Commands ### Description Commands to set various parameters, options, and configurations within the system. ### Endpoints - `set Advanced` - `set As start equilibrium` - `set Axis` - `set Bit` - `set Condition` - `set Echo` - `set Fixed coefficient` - `set initial_T_and_P` - `set Input-Amounts` - `set Interactive` - `set Log-File` - `set Numeric-Options` - `set Optimizing conditions` - `set system variable` - `set Phase "phase-name"` - `set Quit` - `set Range of experimental equilibria` - `set Reference-State` - `set Scaled coefficient` - `set Status` - `set Units` - `set Variable coefficient` - `set Verbose` - `set Weight` ### Sub-Commands for `set Advanced`: - `set advanced EEC-method` - `set advanced equilibrium transfer` - `set advanced global-min-onoff` - `set advanced grid_density` - `set advanced help-popup-off` - `set advanced level` - `set advanced map-special` - `set advanced no-macro-stop` - `set advanced open-popup-off` - `set advanced quit` - `set advanced symbol` - `set advanced working-directory` ### Sub-Commands for `set Phase "phase-name"`: - `set phase ... Amount` - `set phase ... Bits` - `set phase ... Constitution` - `set phase ... Default-constitution` - `set phase ... Quit` - `set phase ... Status` ### Sub-Commands for `set Status`: - `set status Constituent` - `set status Element` - `set status Phases` - `set status Species` ### Parameters - **Advanced** (string) - Accesses advanced settings. - **As start equilibrium** (string) - Sets as starting equilibrium. - **Axis** (string) - Sets axis properties. - **Bit** (string) - Sets bit options. - **Condition** (string) - Sets conditions. - **Echo** (string) - Sets echo behavior. - **Fixed coefficient** (string) - Sets fixed coefficients. - **initial_T_and_P** (string) - Sets initial Temperature and Pressure. - **Input-Amounts** (string) - Sets input amounts. - **Interactive** (string) - Sets interactive mode. - **Log-File** (string) - Sets the log file. - **Numeric-Options** (string) - Sets numeric options. - **Optimizing conditions** (string) - Sets optimizing conditions. - **system variable** (string) - Sets system variables. - **Phase "phase-name"** (string) - Sets properties for a specific phase. - **Quit** (boolean) - Quits the set operation. - **Range of experimental equilibria** (string) - Sets the range for experimental equilibria. - **Reference-State** (string) - Sets the reference state. - **Scaled coefficient** (string) - Sets scaled coefficients. - **Status** (string) - Sets status information. - **Units** (string) - Sets the units. - **Variable coefficient** (string) - Sets variable coefficients. - **Verbose** (string) - Sets verbose output. - **Weight** (string) - Sets weight. ``` -------------------------------- ### Retrieve Equilibrium State Variables with tqgetv Source: https://context7.com/sundmanbo/opencalphad/llms.txt Retrieves thermodynamic properties like temperature, Gibbs energy, chemical potentials, and phase compositions after equilibrium calculation. ```fortran program get_results use liboctq implicit none type(gtp_equilibrium_data), pointer :: ceq integer :: n, n1, n2, n3, cnum, i double precision :: values(100), temp, gibbs character(len=24) :: statevar, phasename call tqini(n, ceq) call tqrfil('crfe.TDB', ceq) ! Set conditions and calculate call tqsetc('T', 0, 0, 1000.0d0, cnum, ceq) call tqsetc('P', 0, 0, 1.0d5, cnum, ceq) call tqsetc('N', 0, 0, 1.0d0, cnum, ceq) call tqsetc('X', 1, 0, 0.3d0, cnum, ceq) call tqce(' ', 0, 0, temp, ceq) ! Get temperature call tqgetv('T', 0, 0, n3, values, ceq) write(*,*) 'Temperature:', values(1), 'K' ! Get total Gibbs energy call tqgetv('G', 0, 0, n3, values, ceq) write(*,*) 'Gibbs energy:', values(1), 'J' ! Get Gibbs energy per mole call tqgetv('GM', 0, 0, n3, values, ceq) write(*,*) 'Gibbs energy/mol:', values(1), 'J/mol' ! Get chemical potentials of all components n3 = nel call tqgetv('MU', -1, 0, n3, values, ceq) write(*,*) 'Chemical potentials:' do i = 1, n3 write(*,*) ' ', cnam(i), ':', values(i) enddo ! Get phase amounts for all phases n3 = ntup call tqgetv('NP', -1, 0, n3, values, ceq) write(*,*) 'Phase amounts:' do i = 1, n3 if (values(i) .gt. 0.0d0) then call tqgpn(i, phasename, ceq) write(*,*) ' ', trim(phasename), ':', values(i) endif enddo ! Get composition of specific phase (phase tuple index 1) n3 = nel call tqgetv('X', 1, -1, n3, values, ceq) write(*,*) 'Phase 1 composition:', (values(i), i=1,n3) end program get_results ``` -------------------------------- ### Set Thermodynamic Conditions Source: https://github.com/sundmanbo/opencalphad/blob/master/OCisoCbinding/pyOC/example.ipynb Define the pressure and temperature for the system state. ```python oc.setPressure(1E5) oc.setTemperature(1173) ``` -------------------------------- ### Show Property Values in OpenCalphad Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Use the 'show' command to display the values of state variables, user-defined symbols, or model parameters. Properties are separated by spaces. This is similar to the LIST state-variables command. ```text OC5:show t g tc(bcc) x(bcc,cr) mu(cr) cp T= 1.2000000E+03 G= -5.9565761E+04 TC(BCC_A2)= 1.0272646E+03 X(BCC_A2,CR)= 3.100000E-2 MU(CR)= -7.2489667E+04 CP= 4.08487869E+01 ``` -------------------------------- ### Selection Commands Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html Commands for selecting various system components or settings. ```APIDOC ## Select Commands ### Description Commands to select specific options or components within the system. ### Endpoints - `select Equilibrium` - `select Graphics` - `select Language` - `select Minimizer` - `select Optimizer` ### Parameters - **Equilibrium** (string) - Selects equilibrium settings. - **Graphics** (string) - Selects graphics options. - **Language** (string) - Selects the language. - **Minimizer** (string) - Selects the minimizer. - **Optimizer** (string) - Selects the optimizer. ``` -------------------------------- ### Manipulate Equilibrium Records and Calculate Gibbs Energy with Python Source: https://context7.com/sundmanbo/opencalphad/llms.txt Change the active equilibrium record, set temperature, calculate equilibrium, and retrieve Gibbs energy. This allows for comparing thermodynamic properties at different conditions or equilibrium states. ```python oc.changeEquilibriumRecord('eq2', copiedEqName='default equilibrium') oc.setTemperature(1273) oc.calculateEquilibrium() G2 = oc.getGibbsEnergy() oc.changeEquilibriumRecord() G1 = oc.getGibbsEnergy() print(f'G at 1173K: {G1:.2e}, G at 1273K: {G2:.2e}') ``` -------------------------------- ### List Ternary System Asymmetries (Post-Amend) Source: https://github.com/sundmanbo/opencalphad/blob/master/changes.txt Lists the asymmetries of ternary systems after an amendment, showing the updated configuration. This command is used to verify changes made to the system. ```bash --->OC6:l mq ms asym ``` -------------------------------- ### Calculate Equilibrium (Fortran) Source: https://context7.com/sundmanbo/opencalphad/llms.txt Calculates thermodynamic equilibrium using the set conditions. Uses grid minimization by default to find the global minimum. Set the `n1` parameter to 0 or a positive value for grid minimization, or -1 to disable it. ```fortran program calculate_equilibrium use liboctq implicit none type(gtp_equilibrium_data), pointer :: ceq integer :: n, n1, n2, cnum double precision :: value character(len=60) :: target call tqini(n, ceq) call tqrfil('crfe.TDB', ceq) ! Set conditions call tqsetc('T', 0, 0, 1000.0d0, cnum, ceq) call tqsetc('P', 0, 0, 1.0d5, cnum, ceq) call tqsetc('N', 0, 0, 1.0d0, cnum, ceq) call tqsetc('X', 1, 0, 0.3d0, cnum, ceq) ! Calculate equilibrium with grid minimizer (n1=0 or positive) target = ' ' n1 = 0 ! Use grid minimizer n2 = 0 call tqce(target, n1, n2, value, ceq) if (gx%bmperr .ne. 0) then write(*,*) 'Calculation failed:', gx%bmperr else write(*,*) 'Equilibrium calculated successfully' endif ! To calculate without grid minimizer, set n1 = -1 ! call tqce(target, -1, n2, value, ceq) end program calculate_equilibrium ``` -------------------------------- ### SHOW Command Source: https://github.com/sundmanbo/opencalphad/blob/master/doc/manual/ochelp.html The SHOW command displays the current value of state variables, user-defined symbols, or model parameters. ```APIDOC ## SHOW ### Description Displays the value of a property, state variable (e.g., T, G), or model parameter. Multiple properties can be specified on the same line separated by spaces. ### Parameters #### Query Parameters - **properties** (string) - Required - A space-separated list of properties or symbols to display (e.g., 't g tc(bcc)'). ``` -------------------------------- ### Compile and Link C++ TQ Interface Source: https://github.com/sundmanbo/opencalphad/blob/master/examples/TQ4lib/Cpp/Matthias/readme.txt Command to compile and link the main C++ program with the required Fortran TQ libraries and standard system libraries. ```bash g++ -o tqintf -lstdc++ tqintf.cpp liboctqiso.o liboctq.o liboceq.a -lgfortran -lm ``` -------------------------------- ### Read TDB Database File (Fortran) Source: https://context7.com/sundmanbo/opencalphad/llms.txt Reads a thermodynamic database file in TDB format. Use `tqrfil` to read all elements or `tqrpfil` to read only selected elements. Ensure the database file exists and is accessible. ```fortran program read_database use liboctq implicit none type(gtp_equilibrium_data), pointer :: ceq character(len=60) :: filename character(len=2) :: selel(3) integer :: n, nsel call tqini(n, ceq) ! Read all elements from database filename = 'steel7.TDB' call tqrfil(filename, ceq) if (gx%bmperr .ne. 0) goto 1000 write(*,*) 'Number of elements:', nel write(*,*) 'Number of phase tuples:', ntup ! Alternatively, read only selected elements ! selel = (/'FE', 'CR', 'NI' /) ! nsel = 3 ! call tqrpfil(filename, nsel, selel, ceq) 1000 continue end program read_database ``` -------------------------------- ### Compute Equilibrium Source: https://github.com/sundmanbo/opencalphad/blob/master/examples/TQ4lib/Cpp/Scheil/input.txt Computes the equilibrium state at a given temperature and pressure. ```OpenCalphad Computation COMPUTE_EQUILIBRIUM<500/3> ```