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
a = 15
lattice = a .* [[1 0 0.]; [0 1 0]; [0 0 0]];

# Confining scalar potential, and magnetic vector potential
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
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
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.170912e+01     6.360302e+00
 * time: 0.0043621063232421875
     1     2.931172e+01     6.265971e+00
 * time: 0.012782096862792969
     2     2.195605e+01     5.139085e+00
 * time: 0.033094167709350586
     3     1.424589e+01     1.711165e+00
 * time: 0.057192087173461914
     4     1.138878e+01     8.367846e-01
 * time: 0.07734203338623047
     5     1.123285e+01     1.273805e+00
 * time: 0.1677260398864746
     6     1.050670e+01     1.369371e+00
 * time: 0.18364310264587402
     7     1.005320e+01     9.154337e-01
 * time: 0.19940519332885742
     8     9.856926e+00     7.046263e-01
 * time: 0.21506619453430176
     9     9.736397e+00     4.559933e-01
 * time: 0.23055815696716309
    10     9.622823e+00     3.811662e-01
 * time: 0.24585914611816406
    11     9.559846e+00     5.473489e-01
 * time: 0.2577500343322754
    12     9.522914e+00     5.880825e-01
 * time: 0.2696340084075928
    13     9.485757e+00     3.468251e-01
 * time: 0.2852480411529541
    14     9.454671e+00     4.759135e-01
 * time: 0.29700517654418945
    15     9.428250e+00     2.982504e-01
 * time: 0.3087351322174072
    16     9.405865e+00     2.834709e-01
 * time: 0.32050609588623047
    17     9.374254e+00     2.122735e-01
 * time: 0.33239006996154785
    18     9.367758e+00     2.112867e-01
 * time: 0.34413909912109375
    19     9.366211e+00     2.807264e-01
 * time: 0.35590505599975586
    20     9.359579e+00     2.298018e-01
 * time: 0.3674910068511963
    21     9.348747e+00     1.824376e-01
 * time: 0.3790290355682373
    22     9.344617e+00     1.416999e-01
 * time: 0.39046311378479004
    23     9.340467e+00     1.116812e-01
 * time: 0.4022071361541748
    24     9.336310e+00     1.668980e-01
 * time: 0.4138951301574707
    25     9.330638e+00     1.219833e-01
 * time: 0.42561912536621094
    26     9.328471e+00     7.769024e-02
 * time: 0.4372432231903076
    27     9.327201e+00     1.202868e-01
 * time: 0.44901418685913086
    28     9.323275e+00     5.881263e-02
 * time: 0.46082305908203125
    29     9.321338e+00     6.906074e-02
 * time: 0.47248411178588867
    30     9.320866e+00     4.084347e-02
 * time: 0.48805999755859375
    31     9.320345e+00     6.575464e-02
 * time: 0.49985718727111816
    32     9.319015e+00     3.246313e-02
 * time: 0.5115740299224854
    33     9.318330e+00     2.500694e-01
 * time: 0.5197131633758545
    34     9.313040e+00     1.324316e-01
 * time: 0.5319662094116211
    35     9.308644e+00     9.831239e-02
 * time: 0.5438470840454102
    36     9.307580e+00     8.185243e-02
 * time: 0.555927038192749
    37     9.307414e+00     4.341591e-02
 * time: 0.5722291469573975
    38     9.307206e+00     5.370488e-02
 * time: 0.5845181941986084
    39     9.306217e+00     4.127214e-02
 * time: 0.5965940952301025
    40     9.303663e+00     9.985026e-02
 * time: 0.6088690757751465
    41     9.301147e+00     2.859551e-01
 * time: 0.6171572208404541
    42     9.295117e+00     1.973940e-01
 * time: 0.6293151378631592
    43     9.292691e+00     1.684452e-01
 * time: 0.6456341743469238
    44     9.289944e+00     1.457288e-01
 * time: 0.6577341556549072
    45     9.282724e+00     8.454584e-02
 * time: 0.6701111793518066
    46     9.282081e+00     6.871866e-02
 * time: 0.6822412014007568
    47     9.281218e+00     5.156265e-02
 * time: 0.6943860054016113
    48     9.277345e+00     9.731595e-02
 * time: 0.7065331935882568
    49     9.272827e+00     7.534179e-02
 * time: 0.7186992168426514
    50     9.271000e+00     6.589796e-02
 * time: 0.7306911945343018
    51     9.267663e+00     7.901974e-02
 * time: 0.7431690692901611
    52     9.260631e+00     2.819699e-01
 * time: 0.7518370151519775
    53     9.251532e+00     2.216085e-01
 * time: 0.7646300792694092
    54     9.247834e+00     2.295872e-01
 * time: 0.7772471904754639
    55     9.241000e+00     1.250288e-01
 * time: 0.7899470329284668
    56     9.236274e+00     1.444614e-01
 * time: 0.8023531436920166
    57     9.231389e+00     1.084476e-01
 * time: 0.8148891925811768
    58     9.227486e+00     1.118260e-01
 * time: 0.8277740478515625
    59     9.222604e+00     9.252583e-02
 * time: 0.8406310081481934
    60     9.215846e+00     1.135831e-01
 * time: 0.8533680438995361
    61     9.202626e+00     1.671377e-01
 * time: 0.9213471412658691
    62     9.195539e+00     1.501892e-01
 * time: 0.9332292079925537
    63     9.192899e+00     1.098381e-01
 * time: 0.94482421875
    64     9.189271e+00     1.353576e-01
 * time: 0.9566349983215332
    65     9.179416e+00     1.323246e-01
 * time: 0.9682102203369141
    66     9.169957e+00     1.149294e-01
 * time: 0.9797391891479492
    67     9.167443e+00     1.102427e-01
 * time: 0.9914782047271729
    68     9.158277e+00     1.766439e-01
 * time: 1.0033190250396729
    69     9.148612e+00     1.337518e-01
 * time: 1.0150411128997803
    70     9.135499e+00     1.433978e-01
 * time: 1.0266201496124268
    71     9.124734e+00     2.055086e-01
 * time: 1.03810715675354
    72     9.116504e+00     2.294350e-01
 * time: 1.049926996231079
    73     9.111598e+00     2.020176e-01
 * time: 1.0618531703948975
    74     9.087792e+00     1.637168e-01
 * time: 1.0735700130462646
    75     9.078883e+00     1.523720e-01
 * time: 1.0853102207183838
    76     9.074586e+00     1.406730e-01
 * time: 1.096912145614624
    77     9.067875e+00     1.607302e-01
 * time: 1.1086561679840088
    78     9.064213e+00     1.994306e-01
 * time: 1.1203861236572266
    79     9.058364e+00     1.699841e-01
 * time: 1.1319911479949951
    80     9.044933e+00     2.498340e-01
 * time: 1.1437511444091797
    81     9.032408e+00     1.621983e-01
 * time: 1.1551721096038818
    82     9.017918e+00     1.947078e-01
 * time: 1.166896104812622
    83     9.003244e+00     1.474720e-01
 * time: 1.1785449981689453
    84     8.991946e+00     1.343248e-01
 * time: 1.1903181076049805
    85     8.979491e+00     1.508666e-01
 * time: 1.2020840644836426
    86     8.968311e+00     1.334005e-01
 * time: 1.2136991024017334
    87     8.940874e+00     1.688551e-01
 * time: 1.2255311012268066
    88     8.926509e+00     1.947394e-01
 * time: 1.237192153930664
    89     8.901758e+00     2.167859e-01
 * time: 1.2491512298583984
    90     8.882959e+00     2.351602e-01
 * time: 1.2612621784210205
    91     8.869064e+00     2.053316e-01
 * time: 1.2735660076141357
    92     8.857656e+00     1.344689e-01
 * time: 1.2855541706085205
    93     8.842519e+00     1.821028e-01
 * time: 1.2976040840148926
    94     8.834062e+00     1.667926e-01
 * time: 1.3098289966583252
    95     8.816064e+00     2.249383e-01
 * time: 1.3218111991882324
    96     8.790293e+00     2.172484e-01
 * time: 1.3339672088623047
    97     8.768550e+00     1.726694e-01
 * time: 1.3462011814117432
    98     8.746495e+00     1.578501e-01
 * time: 1.358199119567871
    99     8.714193e+00     2.055451e-01
 * time: 1.370474100112915
   100     8.682707e+00     1.934821e-01
 * time: 1.382620096206665
   101     8.662307e+00     6.809440e-01
 * time: 1.390726089477539
   102     8.617488e+00     3.714069e-01
 * time: 1.4028210639953613
   103     8.574112e+00     4.137236e-01
 * time: 1.4148712158203125
   104     8.557076e+00     2.238488e-01
 * time: 1.4268381595611572
   105     8.549236e+00     1.320331e-01
 * time: 1.4388420581817627
   106     8.542633e+00     1.256028e-01
 * time: 1.451146125793457
   107     8.536839e+00     1.454259e-01
 * time: 1.463395118713379
   108     8.530770e+00     1.345589e-01
 * time: 1.4754371643066406
   109     8.522545e+00     8.686581e-02
 * time: 1.4878921508789062
   110     8.518893e+00     8.526019e-02
 * time: 1.5006051063537598
   111     8.516610e+00     7.538590e-02
 * time: 1.5131750106811523
   112     8.515162e+00     5.385389e-02
 * time: 1.5258491039276123
   113     8.514090e+00     7.610562e-02
 * time: 1.5383970737457275
   114     8.514016e+00     6.616039e-02
 * time: 1.55122709274292
   115     8.513848e+00     4.204365e-02
 * time: 1.5637531280517578
   116     8.513359e+00     3.889917e-02
 * time: 1.576620101928711
   117     8.512972e+00     3.307892e-02
 * time: 1.5891990661621094
   118     8.512772e+00     3.856756e-02
 * time: 1.6510391235351562
   119     8.512628e+00     3.468493e-02
 * time: 1.6629531383514404
   120     8.512485e+00     3.493368e-02
 * time: 1.6748130321502686
   121     8.512295e+00     3.057295e-02
 * time: 1.6866340637207031
   122     8.512248e+00     1.633541e-02
 * time: 1.6984121799468994
   123     8.512187e+00     1.575410e-02
 * time: 1.710076093673706
   124     8.512101e+00     1.708457e-02
 * time: 1.7219312191009521
   125     8.512074e+00     1.346665e-02
 * time: 1.7335050106048584
   126     8.512057e+00     7.816918e-03
 * time: 1.7450881004333496
   127     8.512014e+00     9.067979e-03
 * time: 1.7567050457000732
   128     8.511993e+00     8.302427e-03
 * time: 1.7684612274169922
   129     8.511965e+00     8.005615e-03
 * time: 1.7802441120147705
   130     8.511950e+00     6.628085e-03
 * time: 1.7920451164245605
   131     8.511941e+00     9.270250e-03
 * time: 1.8037691116333008
   132     8.511916e+00     7.158347e-03
 * time: 1.8152611255645752
   133     8.511903e+00     6.406994e-03
 * time: 1.8269431591033936
   134     8.511891e+00     4.684444e-03
 * time: 1.8388011455535889
   135     8.511882e+00     4.126750e-03
 * time: 1.8505051136016846
   136     8.511872e+00     6.334414e-03
 * time: 1.8623671531677246
   137     8.511868e+00     3.683836e-03
 * time: 1.873946189880371
   138     8.511865e+00     3.934017e-03
 * time: 1.8856120109558105
   139     8.511859e+00     2.641955e-03
 * time: 1.8974270820617676
   140     8.511856e+00     3.600353e-03
 * time: 1.9091150760650635
   141     8.511853e+00     2.037216e-03
 * time: 1.9207031726837158
   142     8.511853e+00     2.115360e-03
 * time: 1.9324491024017334
   143     8.511852e+00     2.490188e-03
 * time: 1.944092035293579
   144     8.511849e+00     1.629815e-03
 * time: 1.9560530185699463
   145     8.511848e+00     1.600314e-03
 * time: 1.9678380489349365
   146     8.511848e+00     1.436800e-03
 * time: 1.9793200492858887
   147     8.511848e+00     1.375760e-03
 * time: 1.9911072254180908
   148     8.511847e+00     1.410468e-03
 * time: 2.0032410621643066
   149     8.511847e+00     1.050250e-03
 * time: 2.0152721405029297
   150     8.511846e+00     9.749387e-04
 * time: 2.027245044708252
   151     8.511846e+00     9.498488e-04
 * time: 2.0394680500030518
   152     8.511846e+00     7.896550e-04
 * time: 2.051664113998413
   153     8.511846e+00     5.867535e-04
 * time: 2.063836097717285
   154     8.511846e+00     7.477354e-04
 * time: 2.076181173324585
   155     8.511846e+00     6.299342e-04
 * time: 2.0884170532226562
   156     8.511845e+00     3.499972e-04
 * time: 2.100548028945923
   157     8.511845e+00     4.126935e-04
 * time: 2.1123812198638916
   158     8.511845e+00     4.131686e-04
 * time: 2.1246612071990967
   159     8.511845e+00     2.335790e-04
 * time: 2.1367311477661133
   160     8.511845e+00     3.042421e-04
 * time: 2.1487061977386475
   161     8.511845e+00     1.987897e-04
 * time: 2.160861015319824
   162     8.511845e+00     1.966069e-04
 * time: 2.1728310585021973
   163     8.511845e+00     1.707244e-04
 * time: 2.18471622467041
   164     8.511845e+00     1.530225e-04
 * time: 2.196885108947754
   165     8.511845e+00     1.407033e-04
 * time: 2.2090752124786377
   166     8.511845e+00     1.228115e-04
 * time: 2.221372127532959
Out[1]: