Gross-Pitaevskii equation with magnetism

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.

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 = 10
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
Apot(x, y, z) = .2 * @SVector [y - a/2, -(x - a/2), 0]
Apot(X) = Apot(X...);

Parameters

In [4]:
Ecut = 20  # Increase this for production
C = 500.0
α = 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...)),
         PowerNonlinearity(C, α),
         Magnetic(Apot),
]
model = Model(lattice; n_electrons=n_electrons,
              terms=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.ρ.real[:, :, 1], c=:blues)
Iter     Function value   Gradient norm 
     0     3.746739e+01     1.353388e+01
 * time: 0.0015690326690673828
     1     3.046450e+01     6.417268e+00
 * time: 0.0065479278564453125
     2     2.768416e+01     4.818063e+00
 * time: 0.011841058731079102
     3     2.272019e+01     2.647425e+00
 * time: 0.01700305938720703
     4     2.068179e+01     2.021774e+00
 * time: 0.0221710205078125
     5     1.959728e+01     1.541682e+00
 * time: 0.027524948120117188
     6     1.932754e+01     2.067365e+00
 * time: 0.03201889991760254
     7     1.904886e+01     1.796727e+00
 * time: 0.03644990921020508
     8     1.852975e+01     1.340032e+00
 * time: 0.0409390926361084
     9     1.813674e+01     1.517199e+00
 * time: 0.1518089771270752
    10     1.784898e+01     1.063118e+00
 * time: 0.157073974609375
    11     1.756760e+01     8.100212e-01
 * time: 0.1621699333190918
    12     1.741309e+01     6.283331e-01
 * time: 0.16722989082336426
    13     1.731445e+01     8.191073e-01
 * time: 0.1722700595855713
    14     1.728891e+01     9.379846e-01
 * time: 0.17611408233642578
    15     1.724521e+01     6.925645e-01
 * time: 0.179948091506958
    16     1.720754e+01     5.462125e-01
 * time: 0.18377208709716797
    17     1.717553e+01     5.416292e-01
 * time: 0.1876990795135498
    18     1.713848e+01     3.899534e-01
 * time: 0.1916520595550537
    19     1.711308e+01     2.832706e-01
 * time: 0.1955559253692627
    20     1.709566e+01     2.355302e-01
 * time: 0.19936203956604004
    21     1.708778e+01     5.870818e-01
 * time: 0.20308208465576172
    22     1.707684e+01     4.355006e-01
 * time: 0.20688104629516602
    23     1.706142e+01     3.043304e-01
 * time: 0.2107388973236084
    24     1.705053e+01     2.587326e-01
 * time: 0.21450495719909668
    25     1.704534e+01     4.074769e-01
 * time: 0.2182939052581787
    26     1.703651e+01     3.445156e-01
 * time: 0.22203898429870605
    27     1.702703e+01     2.647592e-01
 * time: 0.22580409049987793
    28     1.701647e+01     3.279275e-01
 * time: 0.2296590805053711
    29     1.700936e+01     3.108395e-01
 * time: 0.233781099319458
    30     1.700336e+01     2.250530e-01
 * time: 0.23758292198181152
    31     1.699626e+01     1.966943e-01
 * time: 0.24142193794250488
    32     1.699209e+01     2.838401e-01
 * time: 0.24639105796813965
    33     1.699113e+01     2.960084e-01
 * time: 0.25025510787963867
    34     1.698594e+01     2.165760e-01
 * time: 0.2541999816894531
    35     1.698117e+01     1.621914e-01
 * time: 0.25794291496276855
    36     1.698090e+01     4.163217e-01
 * time: 0.2616569995880127
    37     1.697601e+01     2.401463e-01
 * time: 0.2653830051422119
    38     1.697133e+01     1.920201e-01
 * time: 0.26909399032592773
    39     1.696682e+01     1.789628e-01
 * time: 0.2729630470275879
    40     1.696354e+01     1.713193e-01
 * time: 0.27666211128234863
    41     1.695946e+01     1.322362e-01
 * time: 0.2803208827972412
    42     1.695621e+01     1.493128e-01
 * time: 0.28411388397216797
    43     1.695281e+01     1.312283e-01
 * time: 0.2878561019897461
    44     1.695169e+01     8.774904e-02
 * time: 0.29270100593566895
    45     1.694977e+01     8.487424e-02
 * time: 0.2964460849761963
    46     1.694884e+01     1.085482e-01
 * time: 0.30027294158935547
    47     1.694808e+01     1.226635e-01
 * time: 0.30408406257629395
    48     1.694806e+01     1.242679e-01
 * time: 0.3078949451446533
    49     1.694701e+01     7.531544e-02
 * time: 0.3118569850921631
    50     1.694614e+01     5.899703e-02
 * time: 0.3156619071960449
    51     1.694558e+01     5.295521e-02
 * time: 0.31947803497314453
    52     1.694517e+01     5.806821e-02
 * time: 0.3233931064605713
    53     1.694486e+01     3.612905e-02
 * time: 0.32728004455566406
    54     1.694455e+01     3.685437e-02
 * time: 0.3312408924102783
    55     1.694436e+01     5.161578e-02
 * time: 0.3350830078125
    56     1.694418e+01     5.447925e-02
 * time: 0.3388080596923828
    57     1.694381e+01     4.581416e-02
 * time: 0.3425149917602539
    58     1.694346e+01     5.987433e-02
 * time: 0.34624290466308594
    59     1.694302e+01     4.679081e-02
 * time: 0.3510739803314209
    60     1.694254e+01     4.023347e-02
 * time: 0.354780912399292
    61     1.694209e+01     4.801410e-02
 * time: 0.35848188400268555
    62     1.694136e+01     4.985300e-02
 * time: 0.6241738796234131
    63     1.694085e+01     4.801136e-02
 * time: 0.6282370090484619
    64     1.694034e+01     5.064967e-02
 * time: 0.6319010257720947
    65     1.693984e+01     4.838451e-02
 * time: 0.6353709697723389
    66     1.693939e+01     7.248552e-02
 * time: 0.6384780406951904
    67     1.693885e+01     5.190374e-02
 * time: 0.6416530609130859
    68     1.693858e+01     5.462290e-02
 * time: 0.6449398994445801
    69     1.693832e+01     6.080742e-02
 * time: 0.6480240821838379
    70     1.693805e+01     6.406749e-02
 * time: 0.6511549949645996
    71     1.693771e+01     5.599192e-02
 * time: 0.654170036315918
    72     1.693744e+01     3.652619e-02
 * time: 0.6571140289306641
    73     1.693725e+01     3.648817e-02
 * time: 0.6600871086120605
    74     1.693696e+01     4.167770e-02
 * time: 0.6630740165710449
    75     1.693678e+01     4.129960e-02
 * time: 0.666038990020752
    76     1.693650e+01     3.030787e-02
 * time: 0.6689190864562988
    77     1.693632e+01     3.240291e-02
 * time: 0.6721000671386719
    78     1.693623e+01     5.547537e-02
 * time: 0.6750490665435791
    79     1.693613e+01     3.141427e-02
 * time: 0.677933931350708
    80     1.693594e+01     3.899668e-02
 * time: 0.6808888912200928
    81     1.693585e+01     4.191033e-02
 * time: 0.6838350296020508
    82     1.693567e+01     3.690392e-02
 * time: 0.6869909763336182
    83     1.693557e+01     3.741093e-02
 * time: 0.6904129981994629
    84     1.693542e+01     3.335018e-02
 * time: 0.6940081119537354
    85     1.693526e+01     3.260717e-02
 * time: 0.6973910331726074
    86     1.693512e+01     3.531161e-02
 * time: 0.7005960941314697
    87     1.693500e+01     3.644587e-02
 * time: 0.7041909694671631
    88     1.693486e+01     4.174308e-02
 * time: 0.7071609497070312
    89     1.693469e+01     3.991553e-02
 * time: 0.7101030349731445
    90     1.693457e+01     4.800798e-02
 * time: 0.7133920192718506
    91     1.693440e+01     3.590877e-02
 * time: 0.717695951461792
    92     1.693424e+01     2.879978e-02
 * time: 0.7210109233856201
    93     1.693414e+01     3.862557e-02
 * time: 0.7239820957183838
    94     1.693404e+01     3.433424e-02
 * time: 0.7269229888916016
    95     1.693392e+01     3.694768e-02
 * time: 0.7298409938812256
    96     1.693387e+01     3.973381e-02
 * time: 0.7331280708312988
    97     1.693374e+01     4.455096e-02
 * time: 0.7362029552459717
    98     1.693359e+01     3.038917e-02
 * time: 0.7393460273742676
    99     1.693344e+01     3.356708e-02
 * time: 0.7429349422454834
   100     1.693333e+01     2.743689e-02
 * time: 0.7464160919189453
   101     1.693323e+01     2.538352e-02
 * time: 0.7498369216918945
   102     1.693314e+01     2.664658e-02
 * time: 0.7537739276885986
   103     1.693298e+01     2.678666e-02
 * time: 0.7572441101074219
   104     1.693290e+01     4.213287e-02
 * time: 0.7607009410858154
   105     1.693280e+01     2.882583e-02
 * time: 0.7641839981079102
   106     1.693277e+01     5.008904e-02
 * time: 0.7676150798797607
   107     1.693266e+01     3.739881e-02
 * time: 0.7707281112670898
   108     1.693254e+01     4.534401e-02
 * time: 0.7739720344543457
   109     1.693244e+01     3.100330e-02
 * time: 0.7771389484405518
   110     1.693232e+01     2.884406e-02
 * time: 0.7802019119262695
   111     1.693221e+01     2.524290e-02
 * time: 0.7834510803222656
   112     1.693215e+01     2.514726e-02
 * time: 0.7864890098571777
   113     1.693209e+01     4.112435e-02
 * time: 0.7893819808959961
   114     1.693197e+01     3.522550e-02
 * time: 0.792478084564209
   115     1.693185e+01     2.835951e-02
 * time: 0.7953729629516602
   116     1.693171e+01     2.859958e-02
 * time: 0.798259973526001
   117     1.693159e+01     3.958619e-02
 * time: 0.801171064376831
   118     1.693148e+01     4.047978e-02
 * time: 0.8210630416870117
   119     1.693137e+01     3.889595e-02
 * time: 0.8242099285125732
   120     1.693113e+01     4.016915e-02
 * time: 0.8272988796234131
   121     1.693089e+01     5.717155e-02
 * time: 0.8304870128631592
   122     1.693053e+01     6.324404e-02
 * time: 0.8336260318756104
   123     1.693016e+01     4.754698e-02
 * time: 0.8366320133209229
   124     1.692995e+01     9.700857e-02
 * time: 0.8396270275115967
   125     1.692943e+01     9.835191e-02
 * time: 0.8426609039306641
   126     1.692882e+01     1.074599e-01
 * time: 0.8455839157104492
   127     1.692814e+01     9.296504e-02
 * time: 0.8485689163208008
   128     1.692726e+01     9.783007e-02
 * time: 0.8515939712524414
   129     1.692672e+01     9.766646e-02
 * time: 0.8546121120452881
   130     1.692611e+01     1.868831e-01
 * time: 0.8575520515441895
   131     1.692473e+01     1.167292e-01
 * time: 0.8604800701141357
   132     1.692338e+01     1.455356e-01
 * time: 0.8636260032653809
   133     1.692152e+01     1.110361e-01
 * time: 0.8665370941162109
   134     1.691991e+01     1.027409e-01
 * time: 0.869394063949585
   135     1.691765e+01     8.018433e-02
 * time: 0.8724989891052246
   136     1.691635e+01     7.646366e-02
 * time: 0.875432014465332
   137     1.691554e+01     7.247876e-02
 * time: 0.878364086151123
   138     1.691487e+01     6.849694e-02
 * time: 0.8812570571899414
   139     1.691448e+01     6.339365e-02
 * time: 0.8841860294342041
   140     1.691417e+01     5.296783e-02
 * time: 0.8871080875396729
   141     1.691397e+01     2.924125e-02
 * time: 0.8907909393310547
   142     1.691384e+01     2.866903e-02
 * time: 0.8944439888000488
   143     1.691371e+01     2.199511e-02
 * time: 0.8974349498748779
   144     1.691363e+01     1.883881e-02
 * time: 0.9003880023956299
   145     1.691358e+01     1.509427e-02
 * time: 0.9035429954528809
   146     1.691352e+01     1.496382e-02
 * time: 0.9065530300140381
   147     1.691347e+01     1.694063e-02
 * time: 0.9094710350036621
   148     1.691344e+01     1.398099e-02
 * time: 0.9125480651855469
   149     1.691339e+01     9.482891e-03
 * time: 0.915532112121582
   150     1.691336e+01     1.060232e-02
 * time: 0.9184839725494385
   151     1.691332e+01     1.273151e-02
 * time: 0.9213829040527344
   152     1.691329e+01     1.054243e-02
 * time: 0.9243559837341309
   153     1.691326e+01     1.022215e-02
 * time: 0.9273018836975098
   154     1.691324e+01     1.620140e-02
 * time: 0.9411840438842773
   155     1.691321e+01     1.296742e-02
 * time: 0.9442870616912842
   156     1.691318e+01     1.355673e-02
 * time: 0.9473190307617188
   157     1.691314e+01     2.053742e-02
 * time: 0.9503669738769531
   158     1.691309e+01     1.257399e-02
 * time: 0.9535140991210938
   159     1.691306e+01     1.377026e-02
 * time: 0.95648193359375
   160     1.691302e+01     1.553225e-02
 * time: 0.9595110416412354
   161     1.691299e+01     1.539312e-02
 * time: 0.9624888896942139
   162     1.691295e+01     1.555991e-02
 * time: 0.9654378890991211
   163     1.691290e+01     1.683999e-02
 * time: 0.9684009552001953
   164     1.691286e+01     1.621281e-02
 * time: 0.9715220928192139
   165     1.691280e+01     1.496390e-02
 * time: 0.9744570255279541
   166     1.691277e+01     2.505621e-02
 * time: 0.9773581027984619
   167     1.691271e+01     1.770493e-02
 * time: 0.9807150363922119
   168     1.691266e+01     2.027175e-02
 * time: 0.9836220741271973
   169     1.691258e+01     1.762366e-02
 * time: 0.9865200519561768
   170     1.691252e+01     1.755092e-02
 * time: 0.9893970489501953
   171     1.691245e+01     1.621393e-02
 * time: 0.9924499988555908
   172     1.691240e+01     2.123127e-02
 * time: 0.9953880310058594
   173     1.691235e+01     1.529019e-02
 * time: 0.9982750415802002
   174     1.691231e+01     2.097363e-02
 * time: 1.0011579990386963
   175     1.691225e+01     1.405658e-02
 * time: 1.0040669441223145
   176     1.691222e+01     1.824929e-02
 * time: 1.0070459842681885
   177     1.691220e+01     1.331508e-02
 * time: 1.0099709033966064
   178     1.691216e+01     1.296162e-02
 * time: 1.0129749774932861
   179     1.691213e+01     1.304912e-02
 * time: 1.0158569812774658
   180     1.691211e+01     1.232773e-02
 * time: 1.0188789367675781
   181     1.691209e+01     1.759191e-02
 * time: 1.0217170715332031
   182     1.691207e+01     1.053882e-02
 * time: 1.0245881080627441
   183     1.691205e+01     1.092798e-02
 * time: 1.0274639129638672
   184     1.691203e+01     1.447859e-02
 * time: 1.0306029319763184
   185     1.691201e+01     9.674509e-03
 * time: 1.0335569381713867
   186     1.691199e+01     9.940403e-03
 * time: 1.0365839004516602
   187     1.691198e+01     1.074373e-02
 * time: 1.039525032043457
   188     1.691196e+01     1.289680e-02
 * time: 1.0424320697784424
   189     1.691195e+01     1.080108e-02
 * time: 1.0452730655670166
   190     1.691193e+01     1.202590e-02
 * time: 1.0584380626678467
   191     1.691192e+01     9.717551e-03
 * time: 1.0614171028137207
   192     1.691191e+01     8.809875e-03
 * time: 1.0643970966339111
   193     1.691190e+01     1.014595e-02
 * time: 1.0673658847808838
   194     1.691189e+01     1.000296e-02
 * time: 1.0703480243682861
   195     1.691188e+01     6.889004e-03
 * time: 1.0733659267425537
   196     1.691187e+01     8.680561e-03
 * time: 1.076282024383545
   197     1.691186e+01     5.611327e-03
 * time: 1.0791990756988525
   198     1.691186e+01     5.588640e-03
 * time: 1.0821070671081543
   199     1.691185e+01     7.565645e-03
 * time: 1.0850930213928223
   200     1.691184e+01     4.017926e-03
 * time: 1.0879650115966797
   201     1.691184e+01     5.157058e-03
 * time: 1.0908539295196533
   202     1.691184e+01     4.359375e-03
 * time: 1.0938360691070557
   203     1.691183e+01     3.980418e-03
 * time: 1.0969390869140625
   204     1.691183e+01     4.218491e-03
 * time: 1.0998499393463135
   205     1.691182e+01     6.605921e-03
 * time: 1.102708101272583
   206     1.691182e+01     4.535802e-03
 * time: 1.105544090270996
   207     1.691182e+01     3.854994e-03
 * time: 1.108431100845337
   208     1.691182e+01     3.040143e-03
 * time: 1.1114349365234375
   209     1.691181e+01     2.826516e-03
 * time: 1.1143078804016113
   210     1.691181e+01     2.428305e-03
 * time: 1.117163896560669
   211     1.691181e+01     2.726335e-03
 * time: 1.1200408935546875
   212     1.691181e+01     3.696007e-03
 * time: 1.1229379177093506
   213     1.691181e+01     1.898799e-03
 * time: 1.12583589553833
   214     1.691181e+01     2.825648e-03
 * time: 1.12888503074646
   215     1.691181e+01     2.046252e-03
 * time: 1.1320030689239502
   216     1.691180e+01     3.357922e-03
 * time: 1.134964942932129
   217     1.691180e+01     2.902711e-03
 * time: 1.1379380226135254
   218     1.691180e+01     2.472466e-03
 * time: 1.1408441066741943
   219     1.691180e+01     1.540909e-03
 * time: 1.143765926361084
   220     1.691180e+01     1.012841e-03
 * time: 1.1466829776763916
   221     1.691180e+01     9.480843e-04
 * time: 1.1495590209960938
   222     1.691180e+01     1.077969e-03
 * time: 1.1526000499725342
   223     1.691180e+01     8.729013e-04
 * time: 1.155519962310791
   224     1.691180e+01     1.114456e-03
 * time: 1.1584300994873047
   225     1.691180e+01     8.447715e-04
 * time: 1.161329984664917
   226     1.691180e+01     9.378094e-04
 * time: 1.174696922302246
   227     1.691180e+01     1.263074e-03
 * time: 1.1779420375823975
   228     1.691180e+01     5.485489e-04
 * time: 1.1816880702972412
   229     1.691180e+01     4.761672e-04
 * time: 1.1848030090332031
   230     1.691180e+01     4.346487e-04
 * time: 1.1877479553222656
   231     1.691180e+01     3.738867e-04
 * time: 1.1907238960266113
   232     1.691180e+01     4.462871e-04
 * time: 1.1938440799713135
   233     1.691180e+01     4.043034e-04
 * time: 1.1968131065368652
   234     1.691180e+01     5.490732e-04
 * time: 1.1998319625854492
   235     1.691180e+01     7.216063e-04
 * time: 1.2028820514678955
   236     1.691180e+01     3.888962e-04
 * time: 1.2057549953460693
   237     1.691180e+01     4.625930e-04
 * time: 1.2086970806121826
   238     1.691180e+01     3.281276e-04
 * time: 1.211759090423584
   239     1.691180e+01     3.946818e-04
 * time: 1.2146999835968018
   240     1.691180e+01     4.549081e-04
 * time: 1.217576026916504
   241     1.691180e+01     5.687833e-04
 * time: 1.220479965209961
   242     1.691180e+01     3.823606e-04
 * time: 1.2234320640563965
   243     1.691180e+01     4.536191e-04
 * time: 1.2263450622558594
   244     1.691180e+01     3.992467e-04
 * time: 1.2294130325317383
   245     1.691180e+01     4.526631e-04
 * time: 1.2325749397277832
   246     1.691180e+01     6.773954e-04
 * time: 1.2355709075927734
   247     1.691180e+01     4.176940e-04
 * time: 1.2385969161987305
   248     1.691180e+01     7.068909e-04
 * time: 1.2415080070495605
   249     1.691180e+01     5.191911e-04
 * time: 1.2444961071014404
   250     1.691180e+01     5.182373e-04
 * time: 1.2475180625915527
   251     1.691180e+01     6.602901e-04
 * time: 1.250396966934204
   252     1.691180e+01     7.648179e-04
 * time: 1.2534101009368896
   253     1.691180e+01     6.098967e-04
 * time: 1.2564709186553955
   254     1.691180e+01     6.050351e-04
 * time: 1.2594070434570312
   255     1.691180e+01     6.131407e-04
 * time: 1.262294054031372
   256     1.691180e+01     4.106129e-04
 * time: 1.2651400566101074
   257     1.691180e+01     4.301512e-04
 * time: 1.2680370807647705
   258     1.691180e+01     4.554247e-04
 * time: 1.2709460258483887
   259     1.691180e+01     4.327347e-04
 * time: 1.274014949798584
   260     1.691180e+01     4.114308e-04
 * time: 1.2768750190734863
   261     1.691180e+01     3.313698e-04
 * time: 1.2797598838806152
   262     1.691180e+01     4.893822e-04
 * time: 1.293294906616211
   263     1.691180e+01     2.142755e-04
 * time: 1.2971279621124268
   264     1.691180e+01     2.510982e-04
 * time: 1.3001840114593506
   265     1.691180e+01     2.066115e-04
 * time: 1.303184986114502
   266     1.691180e+01     1.692066e-04
 * time: 1.3061459064483643
   267     1.691180e+01     1.651260e-04
 * time: 1.3090600967407227
   268     1.691180e+01     1.720328e-04
 * time: 1.3120861053466797
   269     1.691180e+01     1.818282e-04
 * time: 1.3150010108947754
   270     1.691180e+01     1.406715e-04
 * time: 1.317868947982788
   271     1.691180e+01     1.517848e-04
 * time: 1.3207709789276123
   272     1.691180e+01     1.116558e-04
 * time: 1.323702096939087
   273     1.691180e+01     9.050349e-05
 * time: 1.3266448974609375
   274     1.691180e+01     1.160342e-04
 * time: 1.3295550346374512
Out[5]: