Exploring Capabilities Within Fortrilinos by Solving the 3D Burgers Equation
Total Page:16
File Type:pdf, Size:1020Kb
Scientific Programming 20 (2012) 275–292 275 DOI 10.3233/SPR-2012-0353 IOS Press Exploring capabilities within ForTrilinos by solving the 3D Burgers equation Karla Morris a,∗, Damian W.I. Rouson a, M. Nicole Lemaster a and Salvatore Filippone b a Sandia National Laboratories, Livermore, CA, USA b Università di Roma “Tor Vergata”, Roma, Italy Abstract. We present the first three-dimensional, partial differential equation solver to be built atop the recently released, open-source ForTrilinos package (http://trilinos.sandia.gov/packages/fortrilinos). ForTrilinos currently provides portable, object- oriented Fortran 2003 interfaces to the C++ packages Epetra, AztecOO and Pliris in the Trilinos library and framework [ACM Trans. Math. Softw. 31(3) (2005), 397–423]. Epetra provides distributed matrix and vector storage and basic linear algebra cal- culations. Pliris provides direct solvers for dense linear systems. AztecOO provides iterative sparse linear solvers. We demon- strate how to build a parallel application that encapsulates the Message Passing Interface (MPI) without requiring the user to make direct calls to MPI except for startup and shutdown. The presented example demonstrates the level of effort required to set up a high-order, finite-difference solution on a Cartesian grid. The example employs an abstract data type (ADT) calculus [Sci. Program. 16(4) (2008), 329–339] that empowers programmers to write serial code that lower-level abstractions resolve into distributed-memory, parallel implementations. The ADT calculus uses compilable Fortran constructs that resemble the mathe- matical formulation of the partial differential equation of interest. Keywords: ForTrilinos, Trilinos, Fortran 2003/2008, object oriented programming 1. Introduction Burgers [4]. As one of the few nonlinear PDEs with known analytical solutions, the Burgers equation (in The story of modern, scientific programming is the both its 1D and 3D forms) often plays a role in theo- story of modern, mainstream programming: perfor- retical investigations as a proxy for the more compli- mance gains derive primarily from increasing levels cated 3D Navier–Stokes equations (NSE). The Burg- of parallel execution. Likewise, the story of modern, ers equation retains the unsteady, advective, and dif- scientific programming languages resembles the glob- fusive nature of the NSE without the many additional alization of modern society: mixed-language environ- complications associated with pressure gradients. The ments increasingly predominate. The ForTrilinos soft- Burgers equation also provides qualitative insights into phenomena ranging from charge density waves, vor- ware package sits at the intersection of these two trends tex lines in high-temperature superconductors, and the and was first released in the August 2010 Trilinos large-scale structure of the universe. See [5] and [6] for open-source library and framework (release 10.4.1). surveys of applications for the Burgers equation and ForTrilinos brings to the Fortran community the see [2] and [3] for exact analytical solutions of the 1D object-oriented (OO), native interfaces to C++ pack- and 3D Burgers equation, respectively. ages in the Trilinos library and framework. The goal of the current effort was to investigate the The current article presents the first attempt to level of programming effort required to build a repre- construct a three-dimensional (3D) partial differen- sentative scientific software application atop ForTrili- tial equation (PDE) solver based on ForTrilinos. We nos and provide a detailed guide for future users on present a case study that involves solving a 3D gener- ways to exploit the available capabilities. Our study alization of the classical one-dimensional (1D) PDE of employs one of the compact finite difference schemes developed by Lele [9]. In these schemes, the finite- *Corresponding author: Karla V. Morris, PhD, Combustion Re- search Facility, Sandia National Laboratories, 7011 East Avenue, difference approximations to the nodal derivatives re- MS 9055, Livermore, CA 94550, USA. Tel.: +1 925 294 3287; sult from inverting a linear system of equations with E-mail: [email protected]. the nodal function values as the right-hand side (RHS). 1058-9244/12/$27.50 © 2012 – IOS Press and the authors. All rights reserved 276 K. Morris et al. / Exploring capabilities within ForTrilinos by solving the 3D Burgers equation These schemes’ compact stencil and high-order accu- mining the Burgers equation for insights into fluid be- racy have made them popular for computing complex havior. fluid flows in geometries amenable to finite difference From a software demonstration standpoint, the Burg- approximations [12]. In the current context, the solu- ers equation offers two primary benefits. First, it mod- tion of the linear systems required by compact finite els some of the basic numerical properties of many of difference schemes provides a useful showcase for the the more complicated governing equations of interest linear solver interfaces ForTrilinos provides. to engineering and science. Second, the equation itself In the interest of brevity and to avoid repetition, (most often in the 1D form) has been used to model the remainder of this article assumes familiarity with phenomena such as gas dynamics, traffic flow, flood Fortran 2003. We refer readers who are familiar with waves in rivers, chemical reactions, shock and sound Fortran 90/95 but unfamiliar with OO programming waves and many others. (OOP) in Fortran 2003 to the scientific software de- We solve Eq. (1) in a 3D cube with periodic bound- sign text by Rouson et al. [16]. We refer readers who ary conditions in each direction, approximating all spa- are unfamiliar with Fortran 90/95 – including the ra- tial derivatives with a sixth-order-accurate finite differ- tionale for using modules and derived types – to the ence scheme from [9]. The chosen family of finite dif- modern Fortran text by Metcalf et al. [10]. Section 2 of ference schemes have the general form the current article presents the mathematical methodol- ogy employed in the current demonstration application and the software design methodology employed in For- Af = Bf,(2) Trilinos. Section 3 presents the resulting demonstration Cf = Df,(3) application and the recommended approach for access- ing the requisite ForTrilinos capabilities. Section 4 dis- where f, f and f are nodal solution values and first cusses the results. Section 5 concludes and presents the and second derivatives, respectively, and where A, B, path forward. C and D are all sparse coefficient matrices. The Ap- pendix provides the stencils that generate the coeffi- 2. Methodology cient matrices. The tridiagonal matrix structure of the corresponding 1D problem generates a band-diagonal 2.1. Mathematical model system in 3D. We employ a second-order Runge–Kutta algorithm The 3D Burgers equation describes the nonlinear ad- to advance the governing equation in time. The tempo- vection and diffusion of a vector quantity: rally discrete form of Eq. (1) is thus ∂u 2 Δ = −u ·∇u + ν∇ u,(1)n+1/2 n n n t ∂t u = u + [N(u ) + L(u )] ,(4) 2 where u is a vector field with components u, v and un+1 = un + [N(un+1/2) + L(un+1/2)]Δt,(5) w and ν is a constant parameter. The analogy to the 3D NSE lies in viewing u as a fluid velocity vec- where L is a discrete linear operator that approximates tor field with ν playing the role of the fluid’s kine- the diffusive term in (1) and N is the discrete nonlin- matic viscosity. There are some limits to this view- ear operator that approximates the advective term. We point: arriving at a NSE viscous term of the same form calculate the time step Δt based on the stability re- as the corresponding term in Eq. (1) requires apply- ing an incompressibility constraint to the velocity field quirements of the linear term, which is more restrictive and enforcing that constraint via a pressure gradient asymptotically than the stability restriction on the non- term, but Eq. (1) contains no pressure gradient and its linear term (the Courant condition) in the context of an solution therefore does not satisfy incompressibility. explicit time advancement algorithm. Due to similar reservations, [17], for example, refer to the medium in their Burgers-equation study of turbu- 2.2. Software methodology lence in a self-gravitating medium as a “sticky dust” rather than as “viscous matter”. Nonetheless, the Burg- The solver presented here demonstrates several For- ers equation’s formal similarity to the incompressible Trilinos capabilities and, in doing so, showcases sev- NSE and the existence of exact solutions to the Burg- eral object-oriented features of Fortran 2003. The cho- ers equation have inspired considerable activity around sen example is intended to inform users interested in K. Morris et al. / Exploring capabilities within ForTrilinos by solving the 3D Burgers equation 277 creating and operating on ForTrilinos objects within a The Epetra package hosts classes that support paral- fully objected-oriented application. The software de- lel and serial basic linear algebra functionality. Epe- sign philosophy employed herein closely resembles tra classes provide the foundation for all Trilinos pack- that of the ForTrilinos package. ages. AztecOO is the OO interface to the Aztec pack- A ForTrilinos-enabled application leverages a deep age, providing massively scalable iterative solvers for software stack. This stack resolves issues related to sparse linear systems. AztecOO accepts external pre- language interoperability, portability and memory conditioners. The Pliris package supports a parallel, management in ways that remove such concerns from OO interface to the solution of dense linear systems, the end user. The top layer corresponds to user code employing LU factorization on double precision data. of the kind presented in the current paper. The bottom Additionally, ForTrilinos contains the procedural in- layer comprises the Trilinos package of interest. Typ- frastructure for accessing Amesos, Galeri and Ifpack ically the Trilinos layer does all of the heavy lifting from Fortran.