21 Hans Petter Langtangen Kent-Andre Mardal Introduction to Numerical Methods for Variational Problems Editorial Board T. J.Barth M.Griebel D.E.Keyes R.M.Nieminen D.Roose T.Schlick Texts in Computational 21 Science and Engineering Editors TimothyJ.Barth MichaelGriebel DavidE.Keyes RistoM.Nieminen DirkRoose TamarSchlick Moreinformationaboutthisseriesathttp://www.springer.com/series/5151 Hans Petter Langtangen • Kent-Andre Mardal Introduction to Numerical Methods for Variational Problems 123 HansPetterLangtangen(deceased) Kent-AndreMardal BioComp DepartmentofMathematics SimulaResearchLaboratory UniversityofOslo Lysaker,Norway Oslo,Norway ISSN1611-0994 ISSN2197-179X (electronic) TextsinComputationalScienceandEngineering ISBN978-3-030-23787-5 ISBN978-3-030-23788-2 (eBook) https://doi.org/10.1007/978-3-030-23788-2 MathematicsSubjectClassification(2010):65K05,74S05,68N01,35R10 ©SpringerNatureSwitzerlandAG2019 Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpartof thematerialisconcerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation, broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,andtransmissionorinformation storageandretrieval,electronicadaptation,computersoftware,orbysimilarordissimilarmethodology nowknownorhereafterdeveloped. Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublication doesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevant protectivelawsandregulationsandthereforefreeforgeneraluse. Thepublisher,theauthors,andtheeditorsaresafetoassumethattheadviceandinformationinthisbook arebelievedtobetrueandaccurateatthedateofpublication.Neitherthepublishernortheauthorsor theeditorsgiveawarranty,expressorimplied,withrespecttothematerialcontainedhereinorforany errorsoromissionsthatmayhavebeenmade.Thepublisherremainsneutralwithregardtojurisdictional claimsinpublishedmapsandinstitutionalaffiliations. ThisSpringerimprintispublishedbytheregisteredcompanySpringerNatureSwitzerlandAG. Theregisteredcompanyaddressis:Gewerbestrasse11,6330Cham,Switzerland Thiseasy-to-readbookintroducesthebasic ideasandtechnicalitiesofleastsquares, Galerkin,andweightedresidualmethodsfor solvingpartial differentialequations.Special emphasisisputonfiniteelementmethods. Preface The present book is essentially a book on the finite element method, although we discuss many other choices of basis functions and other applications than partial differential equations. The literature on finite elements contains books of many different flavors, ranging from an abstract view of the method [5, 6, 9, 13, 26] to amorepractical,algorithmictreatmentofthesubject[18,33].Thepresentbookhas a very strong algorithmic focus (“how to compute”), but formulate the method in abstractformwithvariationalformsandfunctionspaces. Onehighlyvaluedfeatureofthefiniteelementmethodistheprospectofrigorous analysis provided by the functional analysis framework. In particular, for elliptic problems (or, in general, symmetric problems) the theory provides error control via sharp estimates and efficient computations via multiscale algorithms. In fact, the development of this mathematical theory of finite element methods is one of the highlights of numerical analysis. However, within scientific computing the computationalengineofthefiniteelementmethodisbeingusedfaroutsidewhatis theoreticallyunderstood.Obviously,thisisatrendthatwillcontinueinthefuture. Hence, it is not our aim to present the established mathematical theory here, but ratherprovidethereaderwiththegorydetailsoftheimplementationinanexplicit, user-friendly and simplistic manner to lower the threshold of usage. At the same time, we want to present tools for verification and debugging that are applicable in general situations such that the method can be used safely beyond what is theoreticallyproven. An important motivation for writing this book was to provide an intuitive approach to the finite element method, using mathematical language frameworks such as the FEniCS software [23]. FEniCS is a modern, very powerful tool for solving partial differential equations by the finite element method, and it was designedtomakeimplementationsverycompact,whichisattractiveforthosewho are used to the abstract formulation of the method. Our aim here is different. Through explicit, detailed and sometimes lengthy derivations, the reader will be abletogetdirectexpositionofallcomponentsinafiniteelementengine. A standard reference for FEniCS users has been the excellent text by Brenner and Scott [6], but for many students with weak formal mathematical background vii viii Preface the learning curve still becomes too steep. The present book grew out of the need to explain variational formulations in the most intuitive way so FEniCS users can transformtheirPDEproblemintotheproperformulationforFEniCSprogramming. We then added material such that also the details of the most fundamental finite elementalgorithmscouldeasilybeunderstood. Thelearningoutcomesofthisbookarefive-fold: 1. understandingvarioustypesofvariationalformulationsofPDEproblems, 2. understandingthemachineryoffiniteelementalgorithms,withanemphasison one-dimensionalproblems, 3. understandingpotentialartifactsinsimulationresults, 4. understanding how variational formulations can be used in other contexts (generalizedboundaryconditions,solvinglinearsystems) 5. understanding how variational methods may be used for complicated PDEs (systemsofnon-linearandtime-dependentPDEs) The exposition is recognized by very explicit mathematics, i.e., we have tried to writeoutalldetailsofthefiniteelement“engine”suchthatareadercancalculatea finiteelementproblembyhand.Explainingalldetailsandcarryingthemoutbyhand areformidabletasksintwo-andthree-dimensionalPDEproblems,sowerestrictthe attentiontoonespacedimensionwhenitcomestodetailedcalculations.Although we imagine that the reader will use FEniCS or other similar software to actually solve finite element problems, we strongly believe that successful application of suchcomplexsoftwarerequiresathoroughunderstandingoftheunderlyingmethod, whichisbestgainedbyhandcalculationsofthestepsinthealgorithms.Also,hand calculationsareindispensablefordebuggingfiniteelementprograms:onecanruna one-dimensionalproblem,printoutintermediateresults,andcomparewithseparate hand calculations. When the program is fully verified in 1D, ideally the program shouldbeturnedintoa2D/3Dsimulationsimplybyswitchingfroma1Dmeshto therelevant2D/3Dmesh. When working with algorithms and hand calculations in the present book, we emphasize the usefulness of symbolic computing. Our choice is the free SymPy package,whichisveryeasytouseforstudentsandwhichgivesaseamlesstransition from symbolic to numerical computing. Most of the numerical algorithms in this bookaresummarizedascompactSymPyprograms.However,symboliccomputing certainly has its limitations, especially when it comes to speed, so their numerical counterparts are usually also developed in the text. The reader should be able to writeherownfiniteelementprogramforone-dimensionalproblems,butotherwise we have no aim to educate the reader to write fast, state-of-the-art finite element programs! Anotherlearningoutcome(althoughnotneededtobeasuccessfulFEniCSuser) is to understand how the finite element method is a special case of more general variationalapproachestosolvingequations.Weconsiderapproximationingeneral, solution of PDEs, as well as solving linear systems in a way that hopefully gives the reader an understanding of how seemingly very different numerical methods actuallyarejustvariantsofacommonwayofreasoning. Preface ix Manycommontopicsfoundinfiniteelementbooksarenotpresentinthisbook. A striking feature is perhaps the presence of the abstract formulation of the finite elementmethod,butwithoutanyclassicalerroranalysis.Thereasonisthatwehave taken a very practical approach to the contents: what does a user need to know to safely apply finite element software? A thorough understanding of the errors is obviously essential, but the classical error analysis of elliptic problems is of limited practical interest for the practitioner, except for the final results regarding convergenceratesofdifferenttypesoffiniteelements. In time-dependent problems, on the other hand, a lot of things can go wrong withfiniteelementsolutions,buttheextensionsoftheclassicalfiniteelementerror analysis to time dependency quickly meets limitations with respect to explaining typical numerical artifacts. We therefore follow a completely different type of analysis, namely the one often used for finite difference methods: insight through numericaldispersionrelationsandsimilarresultsbasedonexactdiscretesolutions via Fourier wave components. Actually, all the analysis of the quality of finite elementsolutionsareinthisbookdonewiththeaidoftechniquesforanalyzingfinite difference methods, so a knowledge of finite differences is needed. This approach also makes it very easy to compare the two methods, which is frequently done throughoutthetext. The mathematical notation in this text makes deviations from the literature trends. Especially books on the abstract formulation of the finite element method often denote the numerical solution by u . Our mathematical notation is dictated h by the natural notation in a computer code, so if u is the unknown in the code, we let u be the corresponding quantity in the mathematical description as well. When also the exact solution of the PDE problem is needed, it is usually denoted byue.Especiallyinthechapteronnonlinearproblemsweintroducenotationsthat arehandyinaprogramandusethesamenotationinthemathematicssuchthatwe achieveasclosecorrespondenceaspossiblebetweenthemathematicsandthecode. Contents TheveryfirstchapterstartswithaquickoverviewofhowPDEproblems are solved by the finite element method. The next four chapters go into deep detail of the algorithms. We employ a successful idea, pursued by Larson and Bengzon [22] in particular, of first treating finite element approximation before attackingPDEproblems.Chapter2explainsapproximationoffunctionsinfunction spacesfromageneralpointofview,wherefiniteelementbasisfunctionsconstitute one example to be explored in Chap.3. The principles of variational formulations constitute the subject of Chap.4. A lot of details of the finite element machinery aremetalreadyintheapproximationprobleminChap.3,sowhenthesetopicsare familiartogetherwiththevariationalformulationsofChap.4,itiseasiertoputthe entire finite element method together in Chap.5 with variational formulations of PDE problems, boundary conditions, and the necessary finite element computing algorithms.Ourexperienceisthatthispedagogicalapproachgreatlysimplifiesthe learning process for students. Chapter 6 explains how time-dependent problems are attacked, primarily by using finite difference discretizations in time. Here we develop the corresponding finite difference schemes and analyze them via x Preface Fourier components and numerical dispersion relations. How to set up variational formulations of systems of PDEs, and in particular the way systems are treated in FEniCS, is the topic of Chap.7. Nonlinear ODE and PDE problems are treated quite comprehensively in Chap.9. Finally, the applicability of variational thinking appearsinadifferentcontextinChap.10whereweconstructiterativemethodsfor linearsystemsandderivemethodsintheConjugategradientfamily. SupplementaryMaterials Allprogramanddatafilesreferredtointhisbookare available from the book’s primary web site: http://folk.uio.no/kent-and/hpl-fem- book/doc/web/. Lysaker,Norway HansPetterLangtangen(deceased) Oslo,Norway Kent-AndreMardal September2016