# Gross-Pitaevskii equation with external magnetic field¶

We solve the 2D Gross-Pitaevskii equation with a magnetic field. This is similar to the previous example (Gross-Pitaevskii equation in one dimension), but with an extra term for the magnetic field. We reproduce here the results of https://arxiv.org/pdf/1611.02045.pdf Fig. 10

In [1]:
using DFTK
using StaticArrays
using Plots


Unit cell. Having one of the lattice vectors as zero means a 2D system

In [2]:
a = 15
lattice = a .* [[1 0 0.]; [0 1 0]; [0 0 0]];


Confining scalar potential, and magnetic vector potential

In [3]:
pot(x, y, z) = ((x - a/2)^2 + (y - a/2)^2)/2
ω = .6
Apot(x, y, z) = ω * @SVector [y - a/2, -(x - a/2), 0]
Apot(X) = Apot(X...);


Parameters

In [4]:
Ecut = 20  # Increase this for production
η = 500
C = η/2
α = 2
n_electrons = 1;  # Increase this for fun


Collect all the terms, build and run the model

In [5]:
terms = [Kinetic(),
ExternalFromReal(X -> pot(X...)),
LocalNonlinearity(ρ -> C * ρ^α),
Magnetic(Apot),
]
model = Model(lattice; n_electrons, terms, spin_polarization=:spinless)  # spinless electrons
basis = PlaneWaveBasis(model; Ecut, kgrid=(1, 1, 1))
scfres = direct_minimization(basis, tol=1e-5)  # Reduce tol for production
heatmap(scfres.ρ[:, :, 1, 1], c=:blues)

Iter     Function value   Gradient norm
0     3.107107e+01     7.291843e+00
* time: 0.004687786102294922
1     2.876062e+01     5.700959e+00
* time: 0.013830900192260742
2     2.304645e+01     8.538451e+00
* time: 0.035635948181152344
3     1.369228e+01     3.329003e+00
* time: 0.06287288665771484
4     1.344589e+01     4.949706e+00
* time: 0.07953095436096191
5     1.267577e+01     2.016079e+00
* time: 0.09606385231018066
6     1.030306e+01     1.828672e+00
* time: 0.11199092864990234
7     9.804730e+00     1.001051e+00
* time: 0.12796688079833984
8     9.348828e+00     1.100985e+00
* time: 0.14391088485717773
9     9.085456e+00     9.168852e-01
* time: 0.16001176834106445
10     8.894131e+00     5.946768e-01
* time: 0.17604899406433105
11     8.780160e+00     5.250814e-01
* time: 0.18827080726623535
12     8.722700e+00     5.630382e-01
* time: 0.20036077499389648
13     8.643762e+00     3.687352e-01
* time: 0.2127208709716797
14     8.596611e+00     2.993913e-01
* time: 0.2248549461364746
15     8.579058e+00     1.886540e-01
* time: 0.23724794387817383
16     8.569429e+00     1.507300e-01
* time: 0.24960684776306152
17     8.558628e+00     1.775237e-01
* time: 0.26216983795166016
18     8.552135e+00     1.312452e-01
* time: 0.27478480339050293
19     8.548353e+00     1.458555e-01
* time: 0.3371129035949707
20     8.537814e+00     1.403037e-01
* time: 0.34923481941223145
21     8.536068e+00     1.913872e-01
* time: 0.36132287979125977
22     8.533663e+00     1.213611e-01
* time: 0.3736109733581543
23     8.531155e+00     1.087756e-01
* time: 0.3859109878540039
24     8.528869e+00     8.732103e-02
* time: 0.39804577827453613
25     8.525036e+00     7.347369e-02
* time: 0.41023993492126465
26     8.523419e+00     6.792758e-02
* time: 0.42258691787719727
27     8.522093e+00     8.064870e-02
* time: 0.43480682373046875
28     8.519904e+00     9.278107e-02
* time: 0.4468247890472412
29     8.518735e+00     6.592605e-02
* time: 0.45891880989074707
30     8.517826e+00     5.937242e-02
* time: 0.4708578586578369
31     8.516552e+00     6.000060e-02
* time: 0.48300695419311523
32     8.515120e+00     7.825918e-02
* time: 0.4949328899383545
33     8.514677e+00     5.167538e-02
* time: 0.5069518089294434
34     8.514196e+00     5.071020e-02
* time: 0.5190749168395996
35     8.513556e+00     3.271990e-02
* time: 0.5310459136962891
36     8.512923e+00     2.751282e-02
* time: 0.5431389808654785
37     8.512733e+00     3.217487e-02
* time: 0.5551638603210449
38     8.512515e+00     2.426274e-02
* time: 0.567166805267334
39     8.512408e+00     1.659509e-02
* time: 0.5791699886322021
40     8.512355e+00     1.780821e-02
* time: 0.5912129878997803
41     8.512252e+00     1.697188e-02
* time: 0.6032118797302246
42     8.512147e+00     1.524332e-02
* time: 0.6154689788818359
43     8.512066e+00     1.338087e-02
* time: 0.6278908252716064
44     8.512043e+00     1.209438e-02
* time: 0.6402428150177002
45     8.512022e+00     1.011911e-02
* time: 0.6899709701538086
46     8.511975e+00     8.841898e-03
* time: 0.7020578384399414
47     8.511932e+00     7.106516e-03
* time: 0.7141478061676025
48     8.511911e+00     8.613331e-03
* time: 0.7266199588775635
49     8.511889e+00     8.436513e-03
* time: 0.7390577793121338
50     8.511876e+00     4.374544e-03
* time: 0.7510759830474854
51     8.511871e+00     4.957880e-03
* time: 0.7632238864898682
52     8.511863e+00     4.498580e-03
* time: 0.7753629684448242
53     8.511857e+00     3.170509e-03
* time: 0.7872359752655029
54     8.511854e+00     2.437927e-03
* time: 0.7992448806762695
55     8.511853e+00     2.246858e-03
* time: 0.8112249374389648
56     8.511853e+00     3.645975e-03
* time: 0.823185920715332
57     8.511851e+00     2.312424e-03
* time: 0.8352530002593994
58     8.511849e+00     1.738604e-03
* time: 0.8471779823303223
59     8.511848e+00     1.317958e-03
* time: 0.8592209815979004
60     8.511848e+00     8.898985e-04
* time: 0.8712368011474609
61     8.511847e+00     1.677463e-03
* time: 0.883171796798706
62     8.511847e+00     1.617500e-03
* time: 0.895258903503418
63     8.511846e+00     1.070956e-03
* time: 0.9072108268737793
64     8.511846e+00     9.476841e-04
* time: 0.9191999435424805
65     8.511846e+00     7.572531e-04
* time: 0.9311749935150146
66     8.511846e+00     6.234727e-04
* time: 0.9431848526000977
67     8.511846e+00     6.651777e-04
* time: 0.9551668167114258
68     8.511846e+00     5.189622e-04
* time: 0.9671077728271484
69     8.511845e+00     4.145397e-04
* time: 0.9792499542236328
70     8.511845e+00     3.287611e-04
* time: 1.0219318866729736
71     8.511845e+00     3.203461e-04
* time: 1.0339758396148682
72     8.511845e+00     2.453704e-04
* time: 1.0459418296813965
73     8.511845e+00     2.266407e-04
* time: 1.0580909252166748
74     8.511845e+00     2.465120e-04
* time: 1.070326805114746
75     8.511845e+00     1.801527e-04
* time: 1.0823619365692139
76     8.511845e+00     1.499721e-04
* time: 1.0944569110870361
77     8.511845e+00     1.511243e-04
* time: 1.1066389083862305
78     8.511845e+00     1.294225e-04
* time: 1.1186778545379639
79     8.511845e+00     1.227820e-04
* time: 1.1305859088897705

Out[5]: