Programming Finite Elements in Java™ Gennadiy Nikishkov Programming Finite Elements in Java™ 123 Gennadiy Nikishkov, DSc, PhD The University of Aizu Aizu-Wakamatsu, 965-8580 Japan ISBN 978-1-84882-971-8 e-ISBN 978-1-84882-972-5 DOI 10.1007/978-1-84882-972-5 Springer London Dordrecht Heidelberg New York British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library Library of Congress Control Number: 2009942247 © Springer-Verlag London Limited 2010 Intel® and Xeon® are registered trademarks of Intel Corporation in the U.S. and other countries. http://www.intel.com JavaTM, Java 2DTM, Java 3DTM, Sun JavaTM are trademarks of Sun Microsystems, Inc. in the United States and other countries. OpenGL® is a registered trademark of Silicon Graphics, Inc. in the United States and other countries worldwide. http://www.sgi.com Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of the publishers, or in the case of reprographic reproduction in accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. The use of registered names, trademarks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant laws and regulations and therefore free for general use. The publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this book and cannot accept any legal responsibility or liability for any errors or omissions that may be made. Cover design: eStudioCalamar, Figueres/Berlin Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com) Preface The finite elementmethodcan be applied to problemsin variousfields of science and engineering. It is well established and its algorithms are presented in numer- ouspublications.Manybooksaredevotedtodifferentaspectsofthefiniteelement method. Still, algorithms of the finite element method are difficult to understand, andprogrammingofthefiniteelementtechniquesiscomplicated. Objective This book focuses on algorithms of the finite element method and their program- ming. First, general equations of the finite element method for solving solid me- chanicsandthermalconductivityproblemsareintroduced.Then,algorithmsofthe finiteelementmethodandtheirprogramminginJavaTMareconsidered.Inaddition tosolutionmethods,thebookpresentsalgorithmsandprogrammingapproachesfor meshgenerationandvisualization. WhyJava? The Java language is selected for its numerous advantages: an object-oriented paradigm,multiplatformsupport,easeofdevelopment,reliabilityandstability,the abilitytouselegacyCorC++code,gooddocumentation,development-toolavail- ability, etc. The Java runtime environment always checks subscript legitimacy to ensure that each subscript is equal to or greater than zero and less than the num- ber of elements in the array. Even this simple feature means a lot to developers. Asaresult,Javaprogramsarelesssusceptibletobugsandsecurityflaws.Javaalso providesapplicationprogramminginterfaces(APIs) fordevelopmentof GUI, and three-dimensionalgraphicsapplications. v vi Preface IstartedprogrammingfiniteelementsinFortran.LaterIusedPascal,C,andC++, beforesettlingonJava.ComparingtheselanguagesIfoundthatprogrammingfinite elementsinJavaisnotjustefficientbecausetheproductivityishigherandthecode containsfewererrors,butisalsomorepleasant. An opinion exists that Java is not suitable for computational modeling and fi- nite elementprogrammingbecauseof itsslow executionspeed.ItistruethatJava is slower than C in performing“multiply-add”arithmetic inside double and triple loops. However, tuning of importantJava code fragments provides computational speedcomparabletothatofC. TheattractivefeaturesofJavaprevailoversomeofitsdrawbacks.Inmyopinion, Java is good for both learning finite element programming and for finite element code development with easy debugging, modification, and support. Further, Java is easy to understand even for those who do not program in Java. In most cases, methodsperformingcomputationscan be easily used with minimummodification toprocedureswritteninotherlanguagessuchasCorC++. ForWhom Is This BookWritten? Thisbookisanintroductorytextaboutfiniteelementalgorithmsandespeciallyfi- niteelementprogrammingusinganobject-orientedapproach.Allimportantaspects offiniteelementtechniquesareconsidered–finiteelementsolution,generationof finiteelementmeshes,andvisualizationoffiniteelementmodelsandresults. Thebookisusefulforgraduateandundergraduatestudentsforself-studyoffinite elementalgorithmsandprogrammingtechniques.Itcan be used as a textbookfor introductorygraduatecoursesorinadvancedundergraduatecourses.Ihopethatthe bookwillbeinterestingtoresearchersandengineerswhoarealreadyfamiliarwith finiteelementalgorithmsandcodes,sincetheprogrammingapproachesofthisbook differfromotherpublications. Organization The book is organizedinto four parts. Part I covers generalformulation of the fi- nite element method. Chapter 1 introduces the finite element formulation in the one-dimensionalcase. Both the Galerkin method and variationalformulationsare considered.Chapter 2 presentsfinite elementequationsforheat transferproblems derivedwiththeuseoftheGalerkinapproach.Chapter3containsvariationalformu- lationofgeneralfiniteelementequationsforsolidmechanicsproblems.Anobject- orientedapproachtodevelopmentofthefiniteelementcodeisdiscussedinChapter 4. PartIIisdevotedtoalgorithmsandprogrammingofthefiniteelementsolutionof solidmechanicsproblems.Chapter5considerstheclassstructureofthefiniteele- Preface vii mentprocessorcode.Datastructuresofthefiniteelementmodelandcorresponding Java class are presentedin Chapter 6. Relationsfor elastic materialandthe corre- spondingclassaregiveninChapter7.Chapters8and9describeanabstractclassfor afiniteelementandaclassfornumericalintegration.Chapters10–13presentalgo- rithms and programmingimplementation for two- and three-dimensionalisopara- metric quadratic elements. Assembly and solution of the finite element equation systemarediscussedin Chapters14–16.Chapter17isdevotedtoassemblyofthe globalload vector.Computingstress incrementsis presentedin Chapter18. Solu- tion and programmingimplementation of elastic–plastic problems is discussed in Chapter19. PartIII focuseson mesh generationfor solution of two- and three-dimensional finiteelementproblems.Theblockdecompositionmethodusedformeshgeneration andgeneralorganizationofthemeshgeneratorisgiveninChapter20.Chapter21 presentstwo-dimensionalmeshgenerators.Chapter22describesthree-dimensional mesh generation by sweeping a two-dimensional mesh. Chapters 23–25 contain algorithms and classes for pasting mesh blocks and various operations on mesh blocks,includingtheirpastingforcreationofacomplexmeshofsimpleblocks. PartIVdescribesalgorithmsforvisualizationoffiniteelementmethodsandre- sults.Chapter26introducestheJava3DTM API,whichisusedforrenderingthree- dimensionalobjects. Visualization algorithmsfor higher-orderfinite elements and visualization code structure are presented in Chapter 27. A scene graph for visu- alization of meshes and results is discussed in Chapter 28. Chapter 29 describes algorithmsforcreationofthemodelsurface.Chapters30and31aredevotedtosub- division of the model surface into polygons. Chapter 32 presents Java classes for resultsfield,color-gradationstrip,mouseinteractionandlights. AppendicesA,B,andCcontainbriefinstructionsforpreparingdataforfiniteel- ementprogramsthatperformproblemsolution,meshgeneration,andvisualization of models and results. Appendix D provides examples of finite element analysis: meshgeneration,problemsolution,andvisualizationofresults. HowThis Book Differs from Others Therearemanybooksaboutthefiniteelementmethod.Someofthemcontainfinite elementprogramsegments.Twoqualitiesdistinguishthisbookfromotherbookson thefiniteelementmethod. First,programminginthisbookisbasedupontheJavaprogramminglanguage. Inmyopinion,Javaiswellsuitedforexplainingprogrammingofthefiniteelement method.Itallowscompactandsimplecodetobewritten.Thishelpsgreatlybecause thereaderhasachancetoactuallyreadfiniteelementprogramsandtounderstand them. Secondly, algorithms presented in this book are tightly connected to program- ming.ThebookiswrittenaroundonefiniteelementJavaprogram,whichincludes solution of solid mechanicsboundaryvalue problems,mesh generation,and visu- viii Preface alizationof finite elementmodelsandresults. Presentationof computationalalgo- rithmsisfollowedbyaJavaclassorgroupofJavamethodsandthenaccompanied bycodeexplanation. WebResources TheJavaprogramsandexamplespresentedinthisbookareavailableonthe Web: http://www.springer.com/978-1-84882-971-8. Comments, sugges- tions,andcorrectionsarewelcomebye-mail:[email protected]. About theAuthor GennadiyNikishkovgothisPh.D.andD.Sc. degreesfromtheMoscowEngineer- ingPhysicsInstitute(TechnicalUniversity)incomputationalmechanics.Hehelda ProfessorpositionattheMoscowEngineeringPhysicsInstitute.Healsohadvisit- ingpositionsatGeorgiaInstituteofTechnology(USA),KarlsruheResearchCenter (Germany),RIKENInstituteofPhysicalandChemicalResearch(Japan),GKSSRe- searchCenter(Germany),andtheUniversityofCaliforniaatLosAngeles(USA). Currently, he is a Professor at the University of Aizu (Japan). His research inter- estsincludecomputationalmechanics,computationalfracturemechanics,computa- tionalnanomechanics,developmentoffiniteelementandboundaryelementcodes, scientificvisualization,andcomputergraphics. Acknowledgments TheauthorisgratefultoProf.MichaelCohen,UniversityofAizu,Japan,forhisat- tentivereadingofthebookmanuscriptandhisvaluablesuggestions,andtoDr.Yuriy Nikishkov,GeorgiaInstituteofTechnology,USA,forhisadvicerelatedtodevelop- ment of the Java program. I also acknowledge my colleagues who contributed to thisbookthroughmanydiscussionsoncomputationalmethodsovertheyears. Ithanktheanonymousreviewersfortheirpreciouscomments.Specialthanksgo tomyeditorOliverJacksonandtoMs.AislinnBunningandMs.SorinaMoosdorf fortheirhelp,whichgreatlyimprovedthequalityofthebook.Finally,Iexpressmy lovingappreciationtomywifeValentinaforhersupportandencouragement. Aizu-Wakamatsu,Japan GennadiyNikishkov July2009 Contents PartI FiniteElementFormulation 1 Introduction................................................... 3 1.1 BasicIdeasofFEM......................................... 3 1.2 FormulationofFiniteElementEquations....................... 4 1.2.1 GalerkinMethod..................................... 5 1.2.2 VariationalFormulation............................... 8 1.3 ExampleofShape-functionDetermination ..................... 9 Problems ...................................................... 10 2 FiniteElementEquationsforHeatTransfer....................... 13 2.1 ProblemStatement ......................................... 13 2.2 FiniteElementDiscretizationofHeatTransferEquations ......... 14 2.3 DifferentTypeProblems..................................... 16 2.4 TriangularElement ......................................... 17 Problems ...................................................... 19 3 FEMforSolidMechanicsProblems .............................. 21 3.1 ProblemStatement ......................................... 21 3.2 FiniteElementEquations.................................... 23 3.3 StiffnessMatrixofaTriangularElement ....................... 26 3.4 AssemblyoftheGlobalEquationSystem ...................... 27 3.5 ExampleoftheGlobalMatrixAssembly ....................... 29 Problems ...................................................... 30 4 FiniteElementProgram ........................................ 33 4.1 Object-orientedApproachtoFiniteElementProgramming........ 33 4.2 RequirementsfortheFiniteElementApplication ................ 34 4.2.1 OverallDescription .................................. 34 4.2.2 UserDescription..................................... 35 4.2.3 UserInterface ....................................... 35 ix x Contents 4.2.4 Functions........................................... 35 4.2.5 OtherRequirements.................................. 36 4.3 GeneralStructureoftheFiniteElementCode ................... 36 Problems ...................................................... 38 PartII FiniteElementSolution 5 FiniteElementProcessor........................................ 43 5.1 ClassStructure............................................. 43 5.2 ProblemData.............................................. 49 5.2.1 DataStatements ..................................... 49 5.2.2 ModelData ......................................... 51 5.2.3 LoadSpecification ................................... 52 5.2.4 DataExample ....................................... 54 5.3 DataScanner .............................................. 57 Problems ...................................................... 61 6 FiniteElementModel........................................... 63 6.1 DatafortheFiniteElementModel ............................ 63 6.2 ClassfortheFiniteElementModel............................ 66 6.3 AddingNewDataItem...................................... 72 Problems ...................................................... 72 7 ElasticMaterial................................................ 75 7.1 Hooke’sLaw .............................................. 75 7.2 ClassforaMaterial......................................... 76 7.3 ClassforElasticMaterial.................................... 79 Problems ...................................................... 81 8 Elements ...................................................... 83 8.1 ElementMethods........................................... 83 8.2 AbstractClassElement...................................... 84 8.2.1 ElementData ....................................... 84 8.2.2 ElementConstructor ................................. 85 8.2.3 MethodsofParticularElements ........................ 87 8.2.4 MethodsCommontoAllElements ..................... 88 8.2.5 ContainerforStresses ................................ 90 8.3 AddingNewElementType .................................. 91 Problems ...................................................... 92 9 NumericalIntegration .......................................... 93 9.1 GaussIntegrationRule ...................................... 93 9.2 ImplementationofNumericalIntegration....................... 95 Problems ...................................................... 99