Skip to content

Commit 6807067

Browse files
committed
(tests) added an additional test for stitching, demonstrating a more complex elemental space
1 parent 7cc4e33 commit 6807067

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed

tests/stitching.nim

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,68 @@ suite "Set up two 3C simplex grids that happen to share a common 2C subspace and
5858
check p1 == p2
5959

6060
echo fmt"Finished test in {cpuTime()-t0} seconds."
61-
61+
62+
suite "Enhance the previous suite by (1) assigning higher order elemental space with chemical element names (Ti Al V Cr Ni) \nand (2) setting up the elemental space to be composed of alloys rather than pure elements":
63+
let comps = @["Ti", "Al", "V", "Cr", "Ni"]
64+
let t0 = cpuTime()
65+
# A - (Ti0.8 Al0.15 V0.05) TiAlloy
66+
# B - V0.25 Cr0.75 - CrV
67+
# C - V0.75 Ni0.25 - VNi
68+
# D - Al0.9 Cr0.1 - AlCr
69+
70+
# Set up A B C
71+
let grid1 = nimplex.simplex_grid_fractional(3, 5).attainable2elemental(@[
72+
# Ti Al V Cr Ni
73+
@[ 0.8, 0.15, 0.05, 0.0, 0.0], # A
74+
@[ 0.0, 0.0, 0.25, 0.75, 0.0], # B
75+
@[ 0.0, 0.0, 0.75, 0.0, 0.25]] # C
76+
)
77+
78+
# Set up D C A
79+
let grid2 = nimplex.simplex_grid_fractional(3, 5).attainable2elemental(@[
80+
# Ti Al V Cr Ni
81+
@[ 0.0, 0.9, 0.0, 0.1, 0.0], # D
82+
@[ 0.0, 0.0, 0.75, 0.0, 0.25], # C
83+
@[ 0.8, 0.15, 0.05, 0.0, 0.0]] # A
84+
)
85+
86+
test "Points generated and are in different spaces":
87+
check grid1 != grid2
88+
89+
let stitch1Table = findStitchingPoints(3, 5, components = @["TiAlloy", "CrV", "VNi"])
90+
let stitch2Table = findStitchingPoints(3, 5, components = @["AlCr", "VNi", "TiAlloy"])
91+
92+
test "Stitching tables generated and of correct size (6 ternaries, 6 binaries, 3 unaries = 15)":
93+
check stitch1Table.len == 15
94+
check stitch2Table.len == 15
95+
96+
let stitch1 = stitch1Table["TiAlloy-VNi"]
97+
let stitch2 = stitch2Table["TiAlloy-VNi"]
98+
99+
test "Binary stitching points were extracted from table and are of correct size (ndiv+1 = 5)":
100+
check stitch1.len == 6
101+
check stitch2.len == 6
102+
103+
test "Binary stitching points are differently indexed (because they are in different spaces)":
104+
check stitch1 != stitch2
105+
106+
test "Stitching points match expected reference values":
107+
check stitch1 == @[20, 18, 15, 11, 6, 0]
108+
check stitch2 == @[0, 1, 2, 3, 4, 5]
109+
110+
func formula(fracs: seq[float], components: seq[string]): string =
111+
for (frac, comp) in zip(fracs, components):
112+
if frac > 0:
113+
result.add(fmt"{comp}{frac:.2f} ")
114+
115+
for i in 0..5:
116+
let p1 = grid1[stitch1[i], _].squeeze().toSeq1D().mapIt(round(it, 3))
117+
let p2 = grid2[stitch2[i], _].squeeze().toSeq1D().mapIt(round(it, 3))
118+
test fmt"Stitching point {i} ({p1:<30}) in grid1 matches stitching point {i} in grid2 ({p2:<30}) -> {formula(p1, comps)}":
119+
check p1 == p2
120+
121+
echo fmt"Finished test in {cpuTime()-t0} seconds."
122+
62123

63124
suite "Set up dissimilar 6C and 7C simplex grids in 9C elemental space that happen to share a common 4C subspace and verify correct stitching":
64125
test "Don't try to visualize this, it's too big! :)":
@@ -131,6 +192,3 @@ suite "Set up dissimilar 6C and 7C simplex grids in 9C elemental space that happ
131192
132193
echo fmt"Finished test in {cpuTime()-t0} seconds."
133194
134-
135-
136-

0 commit comments

Comments
 (0)