-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathferroelectric-response.typ
235 lines (217 loc) · 6.64 KB
/
ferroelectric-response.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#import "@preview/cetz:0.3.3": canvas, draw
#import draw: rect, line, circle, content, hobby, scale
#set page(width: auto, height: auto, margin: 8pt)
#canvas({
let arrow-style = (mark: (end: "stealth", fill: black, scale: .75))
let plot-height = 4
let plot-width = 10
let y-offset = 4.65 // Reduced from 6 to bring plots closer together
// Helper to draw axes
let draw-axes(origin, width, height) = {
line(
(origin.at(0) - 0.5, origin.at(1)),
(origin.at(0) + width, origin.at(1)),
..arrow-style,
name: "x-axis",
)
line(
(origin.at(0), origin.at(1) - 0.5),
(origin.at(0), origin.at(1) + height),
..arrow-style,
name: "y-axis",
)
}
// Top plot: Double-well potential
let top-origin = (-5, y-offset)
draw-axes(top-origin, plot-width, plot-height)
// Draw double-well potential curve using hobby spline
hobby(
(top-origin.at(0) + .5, top-origin.at(1) + 3.5), // start high
(top-origin.at(0) + 1.7, top-origin.at(1) + 0.4), // left minimum
(top-origin.at(0) + 1.8, top-origin.at(1) + 0.3), // left minimum
(top-origin.at(0) + 5, top-origin.at(1) + 1.5), // up to middle peak
(top-origin.at(0) + 8.2, top-origin.at(1) + 0.3), // right minimum
(top-origin.at(0) + 8.3, top-origin.at(1) + 0.4), // right minimum
(top-origin.at(0) + 9.5, top-origin.at(1) + 3.5), // up high again
omega: 0,
name: "potential-curve",
)
// Add "Free Energy" label
content(
"y-axis.mid",
[Free Energy],
angle: 90deg,
anchor: "south",
padding: (0, 0, 2pt),
)
// Bottom plot: Polarization vs. displacement
let bottom-origin = (-5, 0)
draw-axes(bottom-origin, plot-width, plot-height)
// zero lines
line(
(bottom-origin.at(0), bottom-origin.at(1) + plot-height / 2),
(bottom-origin.at(0) + plot-width, bottom-origin.at(1) + plot-height / 2),
stroke: gray + 0.5pt,
)
line(
(bottom-origin.at(0) + plot-width / 2, bottom-origin.at(1)),
(bottom-origin.at(0) + plot-width / 2, bottom-origin.at(1) + plot-height),
stroke: gray + 0.5pt,
)
// Add x-axis labels
content(
(bottom-origin.at(0), bottom-origin.at(1)),
[negative],
anchor: "north-west",
padding: (4pt, 2pt, 0),
name: "neg-label",
)
content(
(bottom-origin.at(0) + 8.5, bottom-origin.at(1)),
[positive],
anchor: "north-west",
padding: (4pt, 2pt, 0),
name: "pos-label",
)
// Draw linear polarization line
line(
(bottom-origin.at(0), bottom-origin.at(1)),
(bottom-origin.at(0) + plot-width, bottom-origin.at(1) + plot-height),
stroke: blue + 1.5pt,
name: "polarization-line",
)
// Add "Polarization" and "Ti Displacement" labels
content(
"y-axis.mid",
[Polarization],
angle: 90deg,
anchor: "south",
padding: 4pt,
)
content(
"x-axis.mid",
[Ti Displacement],
anchor: "north",
padding: (10pt, 0, 0),
)
// Helper function to draw BaTiO3 unit cell
// TODO the face-centered oxygen atom positions need fixing and the lines overlap the atoms
let draw-unit-cell(center-x, center-y, ti-y, cell-name) = {
let (x, y) = (center-x, center-y)
let z-offset = 0.3 // Consistent offset for back face
let cube-style = (stroke: 0.7pt)
// Draw unit cell cube with consistent offsets
rect(
(x - 1, y - 1),
(x + 1, y + 1),
..cube-style,
name: cell-name + "-front",
) // Front face
line(
(x - 1, y - 1),
(x - 1 + z-offset, y - 1 + z-offset),
..cube-style,
name: cell-name + "-left",
) // Left edge
line(
(x + 1, y - 1),
(x + 1 + z-offset, y - 1 + z-offset),
..cube-style,
name: cell-name + "-right",
) // Right edge
line(
(x - 1 + z-offset, y - 1 + z-offset),
(x + 1 + z-offset, y - 1 + z-offset),
..cube-style,
name: cell-name + "-back",
) // Back edge
line(
(x - 1 + z-offset, y + 1 + z-offset),
(x + 1 + z-offset, y + 1 + z-offset),
..cube-style,
name: cell-name + "-top-back",
) // Top back edge
line(
(x - 1 + z-offset, y - 1 + z-offset),
(x - 1 + z-offset, y + 1 + z-offset),
..cube-style,
name: cell-name + "-left-back",
) // Left back edge
line(
(x + 1 + z-offset, y - 1 + z-offset),
(x + 1 + z-offset, y + 1 + z-offset),
..cube-style,
name: cell-name + "-right-back",
) // Right back edge
// Draw Ba atoms (all 8 corners)
let ba-style = (stroke: none, fill: rgb("#00ffff"))
for (pos, suffix) in (
// Front face corners
((x - 1, y - 1), "front-bl"),
((x + 1, y - 1), "front-br"),
((x - 1, y + 1), "front-tl"),
((x + 1, y + 1), "front-tr"),
// Back face corners
((x - 1 + z-offset, y - 1 + z-offset), "back-bl"),
((x + 1 + z-offset, y - 1 + z-offset), "back-br"),
((x - 1 + z-offset, y + 1 + z-offset), "back-tl"),
((x + 1 + z-offset, y + 1 + z-offset), "back-tr"),
) {
circle(
pos,
radius: 0.15,
..ba-style,
name: cell-name + "-ba-" + suffix,
)
}
// Draw O atoms (all 6 face centers)
let o-style = (stroke: none, fill: red)
for (pos, suffix) in (
// Front and back face centers
((x, y), "front"), // Front face center
((x + z-offset, y + z-offset), "back"), // Back face center
// Face centers with consistent offsets
((x, y + 1), "top"), // Top face center
((x, y - 1), "bottom"), // Bottom face center
((x - 1, y), "left"), // Left face center
((x + 1, y), "right"), // Right face center
) {
circle(
pos,
radius: 0.12,
..o-style,
name: cell-name + "-o-" + suffix,
)
}
// Draw Ti atom (center, displaced)
let ti-style = (stroke: none, fill: gray)
circle(
(x + z-offset / 2, y + ti-y),
radius: 0.1,
..ti-style,
name: cell-name + "-ti",
)
// Draw Ti-O bonds
let bond-style = (stroke: (thickness: 0.5pt))
for (end-pos, suffix) in (
((x, y), "front"), // Front face center
((x + z-offset, y + z-offset), "back"), // Back face center
((x, y + 1), "top"), // Top face center
((x, y - 1), "bottom"), // Bottom face center
((x - 1, y), "left"), // Left face center
((x + 1, y), "right"), // Right face center
) {
line(
(x + z-offset / 2, y + ti-y), // Ti position
end-pos,
..bond-style,
name: cell-name + "-bond-" + suffix,
)
}
}
// Draw three unit cells with different Ti displacements
scale(0.75)
draw-unit-cell(-4, y-offset + 5, -0.2, "cell1")
draw-unit-cell(0, y-offset + 5, 0, "cell2")
draw-unit-cell(4, y-offset + 5, 0.2, "cell3")
})