AppliedComputationalPhysics
JosephF.BoudreauandEricS.Swanson
withcontributionsfromRiccardoMariaBianchi
GreatClarendonStreet,Oxford,OX26DP, UnitedKingdom
OxfordUniversityPressisadepartmentoftheUniversityofOxford. ItfurtherstheUniversity’sobjectiveofexcellenceinresearch,scholarship, andeducationbypublishingworldwide.Oxfordisaregisteredtrademarkof OxfordUniversityPressintheUKandincertainothercountries
©JosephF.BoudreauandEricS.Swanson2018
Themoralrightsoftheauthorshavebeenasserted
FirstEditionpublishedin2018 Impression:1
Allrightsreserved.Nopartofthispublicationmaybereproduced,storedin aretrievalsystem,ortransmitted,inanyformorbyanymeans,withoutthe priorpermissioninwritingofOxfordUniversityPress,orasexpresslypermitted bylaw,bylicenceorundertermsagreedwiththeappropriatereprographics rightsorganization.Enquiriesconcerningreproductionoutsidethescopeofthe aboveshouldbesenttotheRightsDepartment,OxfordUniversityPress,atthe addressabove
Youmustnotcirculatethisworkinanyotherform andyoumustimposethissameconditiononanyacquirer
PublishedintheUnitedStatesofAmericabyOxfordUniversityPress 198MadisonAvenue,NewYork,NY10016,UnitedStatesofAmerica
BritishLibraryCataloguinginPublicationData Dataavailable
LibraryofCongressControlNumber:2017946193
ISBN978–0–19–870863–6(hbk.) ISBN978–0–19–870864–3(pbk.) DOI10.1093/oso/9780198708636.001.0001
PrintedinGreatBritainby ClaysLtd,StIvesplc
Qt isaregisteredtrademarkofTheQtCompanyLtd.anditssubsidiaries. Linux istheregisteredtrademark ofLinusTorvaldsintheU.S.andothercountries. Allothertrademarksarethepropertyoftheirrespectiveowners. LinkstothirdpartywebsitesareprovidedbyOxfordingoodfaithand forinformationonly.Oxforddisclaimsanyresponsibilityforthematerials containedinanythirdpartywebsitereferencedinthiswork.
ForPascale.
ForLou,Gordy,Suzy,Kris,Maura,Vin.
ForGordonV .
ForErin,Megan,Liam,andDrew. ForMaxandGudrun.
reorutspecular
Preface
Newgraduatestudentsoftenexperiencesomethinglikeshockwhentheyareaskedto solvereal-worldproblemsforthefirsttime.Theseproblemscanbeonlyrarelysolved withpenandpaperandtheuseofcomputationaltechniquesbecomesmandatory.The roleofcomputationinanyscientificendeavorisgrowing,andpresentsanincreasingset ofchallenges.Numericalalgorithmsplayacentralroleintheoreticalpredictionandinthe analysisofexperimentaldata.Inaddition,weseeanincreasingnumberoflessnumerical taskstakingonmajorimportanceinthelifeofyoungscientists.Forexample,howdo youblendtogethertwocomputinglanguagesorsplitacomputationbetweenmultiple computers?Howdoesonedesignprogramlibrariesofnumericalorscientificcodefor thousandsofusers?Howisfunctionalityaddedtoamillion-linereconstructionprogram? Howcancomplicateddatasetsbevisualized?Whatgoesintoamonitoringprogramthat runsinacontrolroom?Thesetasksarenotparticularlynumericalorevenscientific, buttheyarenonethelessimportantintheprofessionallivesofscientists.Fromdata acquisitionsystemstosolvingquantumfieldtheoryorpresentinginformation,students faceanintimidatingcomputationalenvironmentwithmanylanguagesandoperating systems,multipleuserswithconflictinggoalsandmethods,andcomplexcodesolving subtleandcomplicatedproblems.
Unfortunately,thetypicalstudentismarginallypreparedforthechallengesfaced inmoderncomputationalecosystems.Moststudentshavehadsomeexposuretoa programminglanguagesuchasC,C++,Java,orFortran.Intheirfirstcontactwith “real”code,theymaywellbeexposedtoaproliferationoflegacysoftwarethatin somecasesisbetterusedasacounterexampleofgoodmoderncodingpractices. Underthesecircumstancestheusualsolutionistolearnonthefly.Inabygone erawhenthecomputingenvironmentwassimplethislearningprocesswasperfectly satisfactory,buttodayundirectedlearningleadstomanyfalsestartsandsometraining hasbecomeindispensable.Thesearchforhelpcanbedifficultbecausethenearbysenior physicistprobablygrewupinaneraprecedingtheexplosivedevelopmentoflanguages, paradigms,andcomputationalhardware.
Thisbookaimstofillsomeoftheholesbyintroducingstudentstomoderncomputationalenvironments,object-orientedcomputing,andalgorithmictechniques.Wewillrely on‘canned’codewherereasonable.However,cannedcodeis,bydefinition,incapableof solvingresearchproblems.Itcanatbestsolveportionsofproblems.Atworst,itcanlead thestudentresearchertofalseorincompleteconclusions.Itisthereforeimperativethat thestudentunderstandswhatunderlieshiscode.Thusanexplanationofthenumerical issuesinvolvedincommoncomputationaltaskswillbepresented.
Sometimesthenumericalmethodsandapplicationswillbequitetechnical;forthis reasonweregardthisbookasappropriatefornewlygraduatedstudents.Ourexamples
willbedrawnprimarilyfromexperimentalandtheoreticalphysics.Nevertheless,the bookisalsousefulforstudentsinchemistry,biology,atmosphericscience,engineering, oranyfieldinwhichcomplexanalyticalproblemsmustbesolved.
Thistextismeantforadvanced(orgraduate)studentsinthesciencesandengineering. Thephysicsrangesfromadvancedundergraduatetopicsinclassicalandquantum mechanics,toveryadvancedsubjectmattersuchasquantumfieldtheory,renormalization,andscaling.Theconceptsofobjectorientedcomputingareintroducedearlyin thetextandsteadilyexpandedasoneprogressesthroughthechapters.Themethodsof parallelcomputationarealsointroducedearlyandareappliedinexamplesthroughout. Sinceboththephysicsandthecodingtechniquescanberepletewithjargon,weattempt tobepracticalandprovidemanyexamples.Wehavenotmadeanyefforttopruneaway anydiscussionoffairlypedestrianmaterialonthepretextthatitisnotadvancedenough forasophisticatedaudience.Ourcriterionisthatthetopicswediscussbe useful,notthat theybegraduate-level,particularlysincesometopicsareinterdisciplinaryinnature.
Thenumericalalgorithmsweconsiderarethoseappliedinthemajordomainareas ofphysics.Classicalproblemsinvolvingafinitenumberofdegreesoffreedomaremost oftenreducedtoacoupledsetoffirst-orderdifferentialequations.Thoseinvolvingan infinitenumberofdegreesoffreedomrequiretechniquesusedtosolvepartialdifferential equations.Thestudyofquantummechanicalsystemsinvolvesrandomprocesses,hence thetemporalevolutionofthesystemishandledthoughsimulationoftheunderlying randomness.Thecomputationofphysicalprocessesthuscanbegenerallycategorized accordingtothenumberofdegreesoffreedomandthestochasticordeterministicnature ofthesystem.Morecomplicatedsituationscanmixthese.Forexample,tofollowa chargedparticlethroughamagneticfieldinthepresenceofmultiplescatteringinvolves bothdeterministicandstochasticprocesses.
Theflipsideofsimulationisdatamodeling.Thisistheprocedurebywhicha mathematicaldescriptionofdata,oftenalongwiththevaluesofphysicallyinteresting parameters,isobtained.Datamodelingisanactivitythatconsumesmuchofthetimeand creativityofexperimentalphysicistsworkingwithdatasets,largeorsmall.Whilemany treatisesexistonthestatisticalanalysisofdata,thegoalhereistoexplore,insomewhat greaterdetailthanisusuallyfound,thecomputationalaspectsofthisfield.
Thistextisneitheratreatiseonnumericalanalysisnoraguidetoprogramming,but ratherstrivestodeveloppracticalskillsinnumericalandnon-numericalmethodsapplied torealworldproblems.Becauseoftheemphasisonpracticalskills,studentsshould expecttowriteprogramsandtorefineanddeveloptheirprogrammingtechniquesalong theway.WeassumeabasicknowledgeofC++(thepartofthelanguagetakendirectly fromC,minustheanachronisms),andtreatthenewerfeaturesindedicatedchapters.We donot,however,giveacompletelessononthesyntaxandsymanticsofanylanguage, soweadvisethereaderwhohasnotmasteredC++tolearnitinparallelusinganyone ofanumberofsources.Ouremphasiscanthenfallonusingthelanguage effectively for problemsarisinginphysics.
Akeyingredienttoeffectiveprogrammingnowadaysismasteryofobject-oriented programmingtechniques—westrivetodevelopthatmasterywithinthecontextof greatestinteresttothetargetaudience,namelyphysics.Asnotedin NumericalRecipes
(Press2007),object-orientedprogramminghasbeen“recognizedasthealmostunique successfulparadigmforcreatingcomplexsoftware”.Asaresult,object-orientedtechniquesarewidespreadinthesciencesandtheiruseisgrowing.Thephysicistappreciates objectorientedprogrammingbecausehisday-to-daylifeisfilledwitharichmenagerie ofinterestingobjects,notjustintegersandrealnumbers,butalsovectors,four-vectors, spinors,matrices,rotationgroupelements,Euclideangroupelements,functionsofone variable,functionsofmorethanonevariable,differentialoperators,etc.Oneusuallygets morefromaprogrammingparadigmthatallowsuser-defineddatatypestofillingapsleft atthelanguagelevel.Encapsulationandpolymorphismcanbeeffectivelyusedtobuild upamorefunctionalsetofmathematicalprimitivesforaphysicist—andalsotobuildup animportantsetofnot-so-mathematicalobjectssuchasarefoundinothernonscientific code.
Manybooksaredevotedtoobjectorientedanalysisanddesign,andwhilesomeof thesetreatisesareperfectfortheirtargetaudience,atypicalscientistorengineermost likelygetstiredofexamplesfeaturingthepayrolldepartmentandlooksforadiscussion ofobjectorientedprogrammingthat“speakshislanguage”.Accordingly,weinclude threechaptersonobjectorientedprogramminginC++:Encapsulation,Polymorphism, andTemplates.Otherchaptersofthebookprovideexcellentexamplesofobject-oriented techniquesappliedtovariouspracticalproblems.
Acompanionwebsitehasbeenestablishedforthistextat:
• http://www.oup.co.uk/companion/acp
Thesiteincludesexamplecode(EXAMPLES area),skeletonswhichstudentscanuse asastartingpointforcertainexercisesappearinginthetext(SKELETONS area),and rawdataforotherexercises(DATA area).Inadditionthesiteprovidesuser’sguides, referencemanuals,andsourcecodeforsoftwarelibrariesprovidedfreeofchargeand usedwithinthistext.ThissoftwareislicensedundertheGNULesserGeneralPublic License.Inreferencingexamples,skeletons,data,etc.,wegenerallyomitthefullURL andrefersimplytothedirectory,e.g. EXAMPLES, SKELETONS, DATA,etc.
Courseorganization
Itisourexperiencethatmostofthematerialinthistextcanbecoveredintwoterms ofteaching.Therearethreemainstrandsofemphasis:computational,numerical,and physical,andthesearewoventogether,sothereaderwillfindthatemphasisalternates, thoughthebookbeginswithmorecomputationaltopics,thenbecomesmorenumerical, andfinallymorephysical.
Computationaltopicsinclude:Buildingprograms(Chap1),Encapsulation(Chap2), Someusefulclasses(Chap3),Howtowriteaclass(Chap6),Parallelcomputing (Chap9),Graphicsforphysicists(Chap10),Polymorphism(Chap12),andTemplates, thestandardlibrary,andmodernC++(Chap17).
x Preface
NumericaltopicsincludeInterpolationandextrapolation(Chap4),Numerical quadrature(Chap5),MonteCarlomethods(Chap6),Ordinarydifferentialequations (Chap11).
TopicsrelatedtoapplicationsinexperimentalandtheoreticalphysicsarePercolation anduniversality(Chap8),Nonlineardynamicsandchaos(Chap14),Rotationsand Lorentztransformations(Chap14),Simulation(Chap15),Datamodeling(Chap16), Manybodydynamics(Chap18),Continuumdynamics(Chap19),Classicalspin systems(Chap20),Quantummechanics(Chap21and23),Quantumspinsystems (Chap22),andQuantumfieldtheory(Chap24).
Finally,therearenearly400exercisesofwidelyvaryingdifficultyinthetext.Toassist studentsandinstructorsinselectingproblems,wehavelabelledthoseexercisesthatare meanttobeworkedoutwithouttheaidofacomputeras theoretical [T];exerciseswhich aremoreopen-endedandrequiresignificanteffortareelevatedtothestatusofa project andlabelledwitha[P].
Acknowledgments
Wearegratefultomanypeopleforencouragementandforlendingtheirexpertise. AmongtheseareJi
Cížek,RobCoulson,PaulGeiger,JeffGreensite,KenJordan, ColinMorningstar,JamesMueller,KevinSapp,SørenToxvaerd,andAndrewZentner. J.BoudreauwishestothankPetarMaksimovicandMarkFishlerforinspirationandhelp withthedevelopmentofFunctionObjects(Chapter3),LynnGarrenforsupportofthe originalpackagewhichappearedintheCLHEPclasslibrary,andThomasKittelmann andVakhoTsulaiafortheircollaborationovertheyears.Preliminaryversionsofthis text,andparticularlytheexercises,havebeeninflictedonourgraduatestudentsoverthe years–theirhelphasbeeninstrumentalineffectingmanyimportantrevisions.Wethank themwholeheartedly.
1BuildingprogramsinaLinuxenvironment 1
1.1Theeditor,thecompiler,andthemakesystem3
1.1.1Troubleshootingmysteriousproblems6
1.2Aquicktourofinputandoutput7
1.3WheretofindinformationontheC++standardlibrary9
1.4Commandlineargumentsandreturnvalues9
1.5Obtainingnumericalconstantsfrominputstrings11
1.6Resolvingsharedlibrariesatruntime11
1.7Compilingprogramsfrommultipleunits12
1.8Librariesandlibrarytools16
1.9MoreonMakefile18
1.10Thesubversionsourcecodemanagementsystem(SVN)20 1.10.1TheSVNrepository21
1.10.2ImportingaprojectintoSVN22 1.10.3Thebasicidea22 1.11Styleguide:adviceforbeginners25 1.12Exercises27
2.2Therepresentationofnumbers31
2.2.1Integerdatatypes32
2.2.2Floatingpointdatatypes33
2.2.3Specialfloatingpointnumbers34
2.2.4Floatingpointarithmeticonthecomputer36
2.3Encapsulation:ananalogy37 2.4Complexnumbers38
2.5Classesasuserdefineddatatypes43
2.6Styleguide:definingconstantsandconversionfactorsinoneplace45 2.7Summary47
2.8Exercises48
3.3Linearalgebrawiththe Eigen package54
3.4Complexlinearalgebraandquantummechanicalscattering frompiecewiseconstantpotentials57
3.4.1Transmissionandreflectioncoefficients59
3.5Complexlinearalgebrawith Eigen 60
3.6Geometry63
3.6.1Example:collisionsinthreedimensions64
3.7Collectionclassesandstrings65
3.8Functionobjects67
3.8.1Example:rootfinding70
3.8.2Parameterobjectsandparametrizedfunctors74
3.9Plotting76
3.10Furtherremarks77
3.11Exercises78
83 4Interpolationandextrapolation 84
4.1Lagrangeinterpolatingpolynomial85
4.2Evaluationoftheinterpolatingpolynomial87
4.2.1Interpolationinhigherdimensions89
4.3Splineinterpolation90
4.3.1Thecubicspline90
4.3.2Codingthecubicspline93
4.3.3Othersplines94
4.4Extrapolation95
4.5Taylorseries,continuedfractions,andPadéapproximants97 4.6Exercises102
5Numericalquadrature 107
5.1Someexampleproblems108
5.1.1One-dimensionalperiodicmotion108
5.1.2Quantizationofenergy110
5.1.3Twobodycentralforceproblems111
5.1.4Quantummechanicaltunneling112
5.1.5Momentsofdistributions113
5.1.6Integralsofstatisticalmechanics115
5.2Quadratureformulae118
5.2.1Accuracyandconvergencerate124
5.3Speedupsandconvergencetests126
5.4Arbitraryabscissas128
5.5Optimalabscissas129
5.6Gaussianquadrature132
5.7Obtainingtheabscissas135
5.7.1Implementationnotes137
5.8Infiniterangeintegrals139
5.9Singularintegrands140
5.10Multidimensionalintegrals141
5.11Anoteonnondimensionalization142
5.11.1Comptonscattering142
5.11.2Particleinafiniteone-dimensionalwell143
5.11.3Schrödingerequationforthehydrogenatom144
5.12Exercises145 Bibliography 150
6Howtowriteaclass 151
6.1Someexampleproblems152
6.1.1Astackofintegers152
6.1.2TheJonescalculus152
6.1.3Implementingstack154
6.2Constructors160
6.3Assignmentoperatorsandcopyconstructors162
6.4Destructors165
6.5 const memberdataand const memberfunctions166
6.6Mutablememberdata167
6.7Operatoroverloading167
6.8Friends170
6.9Typeconversionviaconstructorsandcastoperators171
6.10Dynamicmemoryallocation174
6.10.1The“bigfour”176
6.11Aworkedexample:implementingtheJonescalculus181 6.12Conclusion190 6.13Exercises191 Bibliography 195
7MonteCarlomethods 196
7.1Multidimensionalintegrals197 7.2Generationofrandomvariates198
7.2.1RandomnumbersinC++11198
7.2.2Randomengines199
7.2.3Uniformandnonuniformvariates200
7.2.4Histograms202
7.2.5Numericalmethodsfornonuniformvariategeneration204
7.2.6Therejectionmethod204
7.2.7Directsampling(orthetransformationmethod)207
7.2.8Sumoftworandomvariables210
7.2.9TheGaussian(ornormal)distribution211
7.3Themultivariatenormaldistribution, χ 2 ,andcorrelation212
xiv Contents
7.4MonteCarlointegration216
7.4.1Importancesampling219
7.4.2Example220
7.5MarkovchainMonteCarlo221
7.5.1TheMetropolis-Hastingsalgorithm223
7.5.2Slowmixing223
7.5.3Thermalization225
7.5.4Autocorrelation227
7.5.5Multimodality228
7.6Theheatbathalgorithm229
7.6.1Anapplication:Isingspinsystems229
7.6.2Markovchainsforquantumproblems231
7.7Wheretogofromhere232
7.8Exercises233 Bibliography 239
8Percolationanduniversality 240
8.1Sitepercolation241
8.1.1Theclusteralgorithm241
8.1.2Codeverification244
8.1.3Thepercolationprobability244
8.2Fractals249
8.3Scalingandcriticalexponents252
8.3.1Thecorrelationlengthandtheanomalousdimension253
8.3.2Additionalscalinglaws256
8.4Universalityandtherenormalizationgroup258
8.4.1Coarsegraining260
8.4.2MonteCarlorenormalizationgroup263
8.5Epilogue264
8.6Exercises265 Bibliography 272
9Parallelcomputing 274
9.1Highperformancecomputing274
9.2Parallelcomputingarchitecture278
9.3Parallelcomputingparadigms279
9.3.1MPI279
9.3.2openMP285
9.3.3C++11concurrencylibrary289
9.4Parallelcoding299
9.5Forkingsubprocesses300
9.6Interprocesscommunicationandsockets302
9.7Exercises308 Bibliography 310
10Graphicsforphysicists 312
10.1Graphicsengines312
10.1.13dlibrariesandsoftware313
10.1.2Generatinggraphics314
10.1.3The OpenInventor/Coin3d toolkit315
10.2Firststepsina3dworld–3dvisualization316
10.2.1Thebasicskeletonofa3dapplication316
10.2.2Athree-dimensionalgreetingtotheworld318
10.2.3Acolorfulsphericalworld321
10.2.4Deletingnodesinthescenegraph322
10.3Findingpatterns–Testingrandomnumbergenerators322 10.4Describingnature’sshapes–fractals326
10.4.1Sharednodes331
10.5Animations335
10.5.1 Coin engines:arotatingworld335
10.5.2 Coin sensors:anorbitingplanet338
10.6The Inventor system339
10.7Exercises340
11.1Introduction344
11.2Exampleapplications345
11.2.1Projectilemotionwithairresistance345
11.2.2Motionofachargedparticleinamagneticfield346 11.2.3Simplenonlinearsystems:theLorenzmodel347
11.2.4TheLagrangianformulationofclassicalmechanics348
11.2.5TheHamiltonianformulationofclassicalmechanics350
11.2.6TheSchrödingerequation351
11.3Ahigh-levellookatanODEsolver353
11.3.1Asimpleintegratorclass354
11.3.2Example:theharmonicoscillator357
11.4Numericalmethodsforintegratingordinarydifferentialequations358
11.4.1TheEulermethod359
11.4.2Themidpointmethod361
11.4.3Thetrapezoidmethod361
11.4.4The4th orderRunge-Kuttamethod361
11.4.5Propertiesof nth orderRunge-Kuttamethods362 11.5Automatedsolutionofclassicalproblems368
11.5.1Takingpartialderivativeswith GENFUNCTIONs 368
11.5.2Computing and solvingtheequationsofmotion370
11.5.3AclassicalHamiltoniansolver371
11.6Adaptivestepsizecontrol373
Contents
11.6.1Stepdoubling375 11.6.2EmbeddedRungeKuttamethods379 11.7Symplecticintegrationschemes383 11.7.1Symplectictransformations386 11.8Symplecticintegratorsoffirstandhigherorder390 11.9Algorithmicinadequacies393
11.9.1Stability393
11.9.2Solutionmixing394
11.9.3Multiscaleproblems395 11.10Exercises396
12.1Example:outputstreams404 12.2Inheritance406 12.3Constructorsanddestructors407 12.4Virtualfunctions409 12.5Virtualdestructors413 12.6Purevirtualfunctionsandabstractbaseclasses415 12.7Realexample:extendingtheGenericFunctionspackage416 12.8Object-orientedanalysisanddesign421 12.9Exercises421
13.1Introduction424 13.2Nonlinearordinarydifferentialequations426 13.3Iterativemaps429
13.3.1Thelogisticmap430
13.3.2TheHénonmap435
13.3.3Thequadraticmap436 13.4Thenonlinearoscillator438
13.4.1TheLyapunovexponent440 13.5Hamiltoniansystems443
13.5.1TheKAMtheorem444
13.5.2TheHénon-Heilesmodel445
13.5.3Billiardmodels447 13.6Epilogue449
13.7Exercises450
14.1Introduction455 14.2Rotations456
14.2.1Generators457
14.2.2Rotationmatrices458
14.3Lorentztransformations460
14.4Rotationsofvectorsandotherobjects463
14.4.1Vectors463
14.4.2Spinors464
14.4.3Higherdimensionalrepresentations465
14.5Lorentztransformationsoffour-vectorsandotherobjects467
14.5.1Four-vectors467
14.5.2Weylspinors468
14.5.3Diracspinors470
14.5.4Tensorsofhigherorder473 14.6Thehelicityformalism474 14.7Exercises479 Bibliography 482 15Simulation 483
15.1Stochasticsystems483 15.2Largescalesimulation484
15.3Afirstexample486
15.4Interactionsofphotonswithmatter488
15.5Electromagneticprocesses491
15.5.1Bremsstrahlung491
15.5.2Electromagneticshowers493
15.5.3Theneedforsimulationtoolkits493
15.6Fundamentalprocesses:Comptonscattering494
15.7Asimpleexperiment:doubleComptonscattering501
15.8Heavierchargedparticles503 15.9Conclusion505
15.10Exercises506 Bibliography 510 16Datamodeling 511 16.1Tabulardata512
16.2Linearleastsquares(or χ 2 )fit514
16.3Functionminimizationindatamodeling516
16.3.1Thequalityofa χ 2 fit522
16.3.2Amechanicalanalogy523
16.4Fittingdistributions523
16.4.1 χ 2 fittoadistribution524
16.4.2Binnedmaximumlikelihoodfittoadistribution527
16.5Theunbinnedmaximumlikelihoodfit529
16.5.1Implementation530
16.5.2ConstructionofnormalizedPDFs533
xviii Contents
16.6Orthogonalseriesdensityestimation534
16.7Bayesianinference538
16.8Combiningdata540
16.9TheKalmanfilter543
16.9.1Example:fittingapolynomialcurve545
16.9.2Completeequations546
16.10Exercises550
Bibliography 554
17Templates,thestandardC++library,andmodernC++ 556
17.1Generictypeparameters557
17.2Functiontemplates558
17.3Classtemplates560
17.3.1Classtemplatespecialization561
17.4Defaulttemplatearguments563
17.5Non-typetemplateparameters563
17.6ThestandardC++library565
17.6.1Containersanditerators566
17.6.2Algorithms575
17.7ModernC++577
17.7.1Variadictemplates578
17.7.2Auto580
17.7.3Smartpointers581
17.7.4Range-basedforloop582
17.7.5Nullptr583
17.7.6Iterators:nonmemberbeginandend583
17.7.7Lambdafunctionsandalgorithms584
17.7.8Initializerlists586
17.8Exercises590
Bibliography 593
18Manybodydynamics 594
18.1Introduction594
18.2Relationshiptoclassicalstatisticalmechanics595
18.3Noblegases597
18.3.1TheVerletmethod598
18.3.2Temperatureselection603
18.3.3Observables605
18.4Multiscalesystems608
18.4.1Constraineddynamics611
18.4.2Multipletimescales614
18.4.3Solvents616
18.5Gravitationalsystems616
18.5.1N-Bodysimulationsofgalacticstructure618
18.5.2TheBarnes-Hutalgorithm620
18.5.3Particle-meshmethods625
18.6Exercises627 Bibliography 640
19Continuumdynamics 642
19.1Introduction643
19.2Initialvalueproblems643
19.2.1Differencing644
19.2.2Continuityequations645
19.2.3Secondordertemporalmethods648
19.2.4TheCrank-Nicolsonmethod648
19.2.5Secondorderequations650
19.2.6Realisticpartialdifferentialequations651
19.2.7Operatorsplitting652
19.3TheSchrödingerequation655 19.4Boundaryvalueproblems658
19.4.1TheJacobimethod659
19.4.2Successiveover-relaxation662
19.5Multigridmethods664
19.6Fouriertechniques667
19.6.1ThefastFouriertransform669
19.6.2Thesinetransform670
19.6.3Anapplication672
19.7Finiteelementmethods673
19.7.1Thevariationalmethodinonedimension674
19.7.2Two-dimensionalfiniteelements675 19.7.3Meshgeneration677 19.8Conclusions684 19.9Exercises685 Bibliography 699 20Classicalspinsystems 701
20.2.1Definitions703
20.2.2Criticalexponentsandfinitesizescaling704
20.2.3Theheatbathalgorithmandtheinducedmagnetization706 20.2.4Reweighting709
20.2.5Autocorrelationandcriticalslowingdown710
20.2.6Clusteralgorithms713
20.3ThePottsmodelandfirstorderphasetransitions717 20.4TheplanarXYmodelandinfiniteorderphasetransitions720
20.5Applicationsandextensions724
20.5.1Spinglasses724
20.5.2Hopfieldmodel725 20.6Exercises726
Bibliography 730
21QuantummechanicsI–fewbodysystems 732
21.1Introduction732
21.2Simpleboundstates733
21.2.1Shootingmethods734
21.2.2Diagonalization735
21.2.3Discretizedeigenproblems735
21.2.4Momentumspacemethods737
21.2.5Relativistickinematics739
21.3QuantumMonteCarlo740
21.3.1Guidedrandomwalks740 21.3.2Matrixelements745 21.4ScatteringandtheT-matrix750
21.4.1ScatteringviatheSchrödingerequation750
21.4.2TheT-matrix752
21.4.3Coupledchannels757
21.5Appendix:Three-dimensionalsimpleharmonicoscillator761
21.6Appendix:scatteringformulae763
21.7Exercises763 Bibliography 771
22Quantumspinsystems 773
22.1Introduction773
22.2TheanisotropicHeisenbergantiferromagnet775
22.3TheLanczosalgorithm778
22.3.1TheLanczosmiracles779
22.3.2ApplicationoftheLanczosmethod totheHeisenbergchain781
22.4QuantumMonteCarlo785
22.5Exercises791
Bibliography 800
23QuantummechanicsII–manybodysystems 802
23.1Introduction802 23.2Atoms803
23.2.1Atomicscales803
23.2.2TheproductAnsatz804
23.2.3Matrixelementsandatomicconfigurations805 23.2.4Smallatoms807
23.2.5Theself-consistentHarteeFockmethod809
23.3Molecules814
23.3.1Adiabaticseparationofscales815
23.3.2Theelectronicproblem817
23.4Densityfunctionaltheory824
23.4.1TheKohn-Shamprocedure827
23.4.2DFTinpractice828
23.4.3Furtherdevelopments830
23.5Conclusions831
23.6Appendix:BeyondHartree-Fock831
23.7Exercises836
24.1Introduction844
24.2 ϕ 4 theory845
24.2.1Evaluatingthepathintegral849
24.2.2Particlespectrum853
24.2.3Paritysymmetrybreaking856
24.3 Z2 Gaugetheory857
24.3.1Heatbathupdates861
24.3.2AveragePlaquetteandPolyakovloop863
24.4Abeliangaugetheory:compactphotons865
24.4.1GaugeinvarianceandquenchedQED867
24.4.2Computationaldetails869
24.4.3Observables872
24.4.4Thecontinuumlimit875
24.5 SU(2) Gaugetheory877
24.5.1Implementation879
24.5.2Observables881
24.6Fermions886
24.6.1Fermionicupdating890
24.7Exercises893