Last active
January 11, 2024 10:49
-
-
Save flotang-gtt/8849dce3c47908e24532a3e866f8e222 to your computer and use it in GitHub Desktop.
The original slag heating example, slimmed down but not including any multiprocessing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#> Initialization and general setup | |
import os | |
from pathlib import Path | |
import numpy as np | |
from collections import OrderedDict | |
import chemapp as ca | |
from chemapp.friendly import ( | |
Info, | |
StreamCalculation as casc, | |
ThermochemicalSystem as cats, | |
EquilibriumCalculation as caec, | |
Units as cau, | |
TemperatureUnit, | |
PressureUnit, | |
VolumeUnit, | |
AmountUnit, | |
EnergyUnit, | |
Status, | |
) | |
from chemapp.core import ( | |
LimitVariable, | |
ChemAppError, | |
) | |
#> Load data file | |
cst_file = Path("SlagHeating.cst") | |
# load the database file | |
cats.load(cst_file) | |
#> Units setup | |
# It is possible to change the units before retrieving results, or in between making multiple inputs. However, mixed | |
# unit input is currently not generated automatically. | |
cau.set( | |
T = TemperatureUnit.C, | |
P = PressureUnit.atm, | |
V = VolumeUnit.dm3, | |
A = AmountUnit.gram, | |
E = EnergyUnit.J | |
) | |
#> Fixed conditions | |
# setting general boundary conditions of the calculation(s) | |
casc.set_eq_P(1.0) | |
#> Stream setup | |
# Create streams. The names are defaults of "#1", "#2", ... | |
# Feel free to make these more reasonable, but take care to edit everywhere they are used | |
casc.create_st(name="#1", T=25, P=1) | |
#> Variable conditions | |
# original condition for T was 1500.0, which would not include 1500.0. | |
# Increasing it by 20.0 yields the inclusive upper boundary. | |
T_range = np.arange(1400.0, 1520.0, 20.0) | |
# we keep the results in an OrderedDict, to access by variable value | |
# if wanted, the .values() attribute of results can be easily used like a list. | |
results = OrderedDict() | |
#> Calculation | |
for T in T_range: | |
# set incoming amounts | |
# since this is a calculation with initial conditions, input needs to be made | |
# using phase constituents | |
casc.set_IA_pc("#1", "Al2O3_gamma(s)", "Al2O3_gamma(s)", 15.0) | |
casc.set_IA_pc("#1", "CaO_Lime(s)", "CaO_Lime(s)", 33.0) | |
casc.set_IA_pc("#1", "MgO_periclase(s)", "MgO_periclase(s)", 15.0) | |
casc.set_IA_pc("#1", "SiO2_Quartz(l)(s)", "SiO2_Quartz(l)(s)", 37.0) | |
casc.set_IA_pc("#1", "FeO_Wustite(s)", "FeO_Wustite(s)", 0.001) | |
casc.set_IA_pc("#1", "Fe2O3_hematite(s)", "Fe2O3_hematite(s)", 0.001) | |
casc.set_IA_pc("#1", "Cr2O3_solid(s)", "Cr2O3_solid(s)", 0.001) | |
casc.set_IA_pc("#1", "MnO_solid(s)", "MnO_solid(s)", 0.001) | |
casc.set_IA_pc("#1", "TiO2_Rutile(s)", "TiO2_Rutile(s)", 0.001) | |
casc.set_IA_pc("#1", "K2O_solid(s)", "K2O_solid(s)", 0.001) | |
casc.set_IA_pc("#1", "Na2O_Solid-A(s)", "Na2O_Solid-A(s)", 0.001) | |
casc.set_IA_pc("#1", "V2O5_solid(s)", "V2O5_solid(s)", 0.001) | |
casc.set_IA_pc("#1", "NiO_solid(s)", "NiO_solid(s)", 0.001) | |
casc.set_IA_pc("#1", "Cu2O_solid(s)", "Cu2O_solid(s)", 0.001) | |
casc.set_IA_pc("#1", "Ni3S2_Solid_I(s)", "Ni3S2_Solid_I(s)", 0.001) | |
casc.set_IA_pc("#1", "Cu2S_Chalcocite(s)", "Cu2S_Chalcocite(s)", 0.001) | |
casc.set_IA_pc("#1", "FeS_solid(s)", "FeS_solid(s)", 0.001) | |
casc.set_IA_pc("#1", "S_alpha_orthorhombic_(s)", "S_alpha_orthorhombic_(s)", 0.001) | |
try: | |
# calculate | |
casc.calculate_eq() | |
#fetch results | |
results[T] = casc.get_result_object() | |
except ChemAppError as c_err: | |
print(f"[<T> = { T }] ChemApp Error {c_err.errno}:") | |
print(c_err) | |
# change this if you want to capture a calculation error | |
# maybe input a dummy value (or other, adequate replacements?): | |
# results[T] = None | |
pass | |
print("End of the Python script.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment