or Ba. We take $S=1$, and we thus fix the parameters $J_{0}=3.88$ meV and $\mu=1.88$ $e$Å, which were determined in section \[sec:fit\] for STO. To obtain a ferroelectric transition, we take $\Omega=3.2$ meV, which yields a bulk transition temperature $T_\mathrm{c}\approx20$ K, similar to what is observed in Sr$_{1-x}$Ca$_x$TiO$_3$. We treat $J_1$ as an adjustable parameter.

Thin films have a layered geometry that simplifies calculations. Taking each layer to be one unit cell thick, and assuming translational invariance within the $xy$-plane, the pseudospin, electric field, and polarization depend only on the layer index $i_{z}$ (instead of site $i$). Equation  becomes $$\label{S3_i}
S^{(3)}_{i_z} = \frac{S h^{(3)}_{i_z}}{h_{i_z}} f_{S}(h_{i_z}),$$ where $h_{i_z} = |{\mathbf{h}}_{i_z}|$ and the Weiss mean field is $$\label{eq:hz}
\textbf{h}_{i_z} = \left( \Omega, 0, \frac{J_{1}}{S} \sum_{i'} S^{(3)}_{i'} + \frac{J_\mathrm{an}}{S} S^{(3)}_{i_z} + \mu E_{i_z} \right),$$ where, for the cubic STO crystal structure, the sum over nearest neighbours of a pseudospin in layer $i_z$ is $\sum_{i'}S_{i'} = 4S^{(3)}_{i_z} + S^{(3)}_{i_z-1} + S^{(3)}_{i_z+1}$. The lattice polarization in layer $i_{z}$ is then $$\label{P_i}
P_{i_{z}} = \mu \eta S^{(3)}_{i_{z}}.$$ (Recall that $\mu S$ is the maximum dipole moment per unit cell and $\eta$ is the dipole moment density.)

We assume a short-circuit geometry, in which the top and 