Skip to content

Commit 7acb976

Browse files
committed
Added prisms param filegen
1 parent 098d749 commit 7acb976

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

BinarySystems.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from scipy.interpolate import CubicSpline
44
import numpy as np
55
from pycalphad import calculate
6-
6+
import PRISMS_PF_fileGen
77
class BinaryIsothermalDiscretePhase:
88
"Class representing a single phase at one temperature described by a set of points in composition-Gibbs free energy space"
99
def __init__(self, xdata, Gdata):

PRISMS_PF_fileGen.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
def binary_isothermal_write_parabolic_parameters(binaryIsothermalSys, output_file, template_file, phases=None, component="comp_1"):
2+
"""
3+
Creates a parameters file from a BinaryIsothermal2ndOrderSystem
4+
5+
Parameters
6+
----------
7+
output_file : string
8+
path to file to create
9+
template_file : string
10+
path to template parameter file if needed
11+
phases : list (string)
12+
(optional) list of specific phases to copy to parameters
13+
component : string
14+
(optional) name of the x-component
15+
"""
16+
if phases is None:
17+
phase_list = binaryIsothermalSys.phases.keys()
18+
else:
19+
phase_list = phases
20+
cmin = {}
21+
fmin = {}
22+
kwell= {}
23+
for phase_name in phase_list:
24+
cmin[phase_name] = {component : binaryIsothermalSys.phases[phase_name].cmin}
25+
fmin[phase_name] = binaryIsothermalSys.phases[phase_name].fmin
26+
kwell[phase_name] = {component : binaryIsothermalSys.phases[phase_name].kwell}
27+
_PRISMS_parabolic_parameters(cmin=cmin, fmin=fmin, kwell=kwell,
28+
phases = phase_list ,comps=[component],
29+
template_file=template_file, output_file=output_file)
30+
31+
32+
def _PRISMS_parabolic_parameters(cmin, fmin, kwell, phases, comps, output_file, template_file):
33+
## Step 2: Make necessary strings
34+
num_phases = len(phases)
35+
num_comps = len(comps)
36+
sf = 3
37+
fmin_str = ""
38+
cmin_str = ""
39+
kwell_str = ""
40+
phase_names_str = ""
41+
comp_names_str = ""
42+
for phase in phases:
43+
fmin_str += f'{fmin[phase]:.{sf}e}' + ", "
44+
phase_names_str += phase + ", "
45+
for comp in comps:
46+
cmin_str += f'{cmin[phase][comp]:.{sf}f}' + ","
47+
kwell_str += f'{kwell[phase][comp]:.{sf}e}' + ","
48+
cmin_str += " "
49+
kwell_str += " "
50+
51+
for comp in comps:
52+
comp_names_str += comp + ", "
53+
54+
## Step 3: read template and write prm
55+
import re
56+
with open(template_file, 'r') as f_in, open(output_file, 'w') as f_out:
57+
for line in f_in:
58+
if re.match(r'^set Model constant num_phases\b', line):
59+
f_out.write("set Model constant num_phases = " + str(num_phases) + ", INT\n")
60+
elif re.match(r'^set Model constant num_comps\b', line):
61+
f_out.write("set Model constant num_comps = " + str(num_comps) + ", INT\n")
62+
elif re.match(r'^set Model constant fWell\b', line):
63+
f_out.write("set Model constant fWell = " + fmin_str + "DOUBLE ARRAY\n")
64+
elif re.match(r'^set Model constant kWell\b', line):
65+
f_out.write("set Model constant kWell = " + kwell_str + "DOUBLE ARRAY\n")
66+
elif re.match(r'^set Model constant cmin\b', line):
67+
f_out.write("set Model constant cmin = " + cmin_str + "DOUBLE ARRAY\n")
68+
elif re.match(r'^set Model constant phase_names\b', line):
69+
f_out.write("set Model constant phase_names = " + phase_names_str + "STRING ARRAY\n")
70+
elif re.match(r'^set Model constant comp_names\b', line):
71+
f_out.write("set Model constant comp_names = " + comp_names_str + "STRING ARRAY\n")
72+
else:
73+
f_out.write(line)
74+
75+
print("Model Parameters written to " + output_file + "\n")
76+

0 commit comments

Comments
 (0)