Moukalled F., Mangani L., Darwish M. The finite volume method in computational fluid dynamics. An advanced introduction with OpenFOAM and Matlab (811443), страница 24
Текст из файла (страница 24)
In all other situations, it is more advantageous to use the cell-centeredarrangement as it leads to a more straightforward implementation in a computer code.5.8 Implicit Versus Explicit Numerical MethodsAs described in Sect. 5.1, once the number of integration points and the type oflinearization are defined, the cell-centered finite volume discretization methodresults in a set of equations with the values of the dependent variables at the cellcenters as unknowns.
The way these unknowns are organized and solved, classifiesthe adopted computational approach. Numerical solution schemes are often referredto as being either explicit or implicit.An explicit numerical method is one in which the dependent variables arecomputed directly via already known values. In this case any discretization operatorcan be directly evaluated based on the actual variable values.On the other hand, a numerical method is said to be implicit when the dependentvariables are treated as unknowns and assembled to form a coupled set of equationswhich are then solved via special numerical tools using either a direct or an iterativesolution algorithm.The conservation equations dealt with in computational fluid dynamics arenonlinear and the implicit approach is most often preferred over the explicit methodfor solving them.
Once the proper discretization and linearization are performed, the5.8 Implicit Versus Explicit Numerical Methods127last step is to solve the set or system of algebraic equations to get the solution.Solving the corresponding system with a direct equation solver, as discussed in aprevious chapter, is not feasible. The iterative approach being more economical, isthe most widely, if not the only one, used. In difference with a direct approach,starting from an initial guess an iterative method progresses toward solution byusing results obtained at the end of an iteration as the initial guess for the followingiteration. The sequence of events is said to be converging if the intermediatecomputed solution is approaching the final solution, otherwise it is said to bediverging.
The process is general and is used whether solving for one time step in atransient problem or for a final solution in a steady state problem. In fact adoptingan iterative approach to obtain a steady state solution is computationally cheaperthan marching in time until steady state is reached. Additional details about matrixiterative solvers will be covered in Chap. 10.5.9 The Mesh SupportNow that the basis of the numerics of the FVM and its properties have beenpresented, it is worth outlining the needed mesh support.
In all preceding derivations it has been implicitly assumed that certain geometric and topological information is readily available. Even though the description of the finite volume meshwill be the subject of the next two chapters, based on the covered material so far, ithas become possible to draw a simplified list of its characteristics.The application of the FVM as a numerical discretization technique necessitatesa mesh support that provides a range of information both geometric and topological,as described next.For an element, the needed information includes: its index, its centroid, a list ofbounding faces, and a list of neighboring elements. For a face, information isneeded about its index, its centroid, its surface vector, a list of neighboring elements(2 for an interior face and one for a boundary face), in addition to a list of verticesthat defines it.
Also needed is information about the boundaries of the computational domain, i.e., the boundary faces that define each boundary patch.Another issue to be resolved is the orientation of the normal vector to an elementface. In the above derivations it was assumed that the normal to all faces of theelement were pointing outward. The normal vectors to faces in a computationaldomain cannot be all pointing outward. Generally any element will have some of itsfaces with their normal vectors pointing outward while for the remaining faces theywill be pointing inward. This indicates that a proper account should be made of theface sign.Why and how the above is defined and used will be the focus of the next chapter.1285 The Finite Volume Method5.10 Computational PointersThroughout this book uFVM, a Matlab®-based finite volume CFD educationalcode, and openFOAM® [17], an open source finite volume code capable of solvingindustrial type problems, will be used to illustrate implementation details andconcretize various numerical procedures.
Generally, comments about implementation techniques, adopted methods, and data structure in these two codes will beadded, unless otherwise stated, in the Computational Pointers’s section of everychapter to follow. Moreover, a number of uFVM test cases (testDiffusion,testAdvection, testFlow, testSource, etc.) are available for the reader and can bedownloaded from the book website at the URL address mentioned earlier.5.10.1 uFVMThe computer program uFVM is an unstructured three dimensional finite volumecode that was developed for academic purposes. It is written in Matlab® and as suchlends itself substantially to any type of dissection by the user. Moreover, theMatlab® environment allows users to unroll the various data structures adopted inthe code at any time during the running of a case.
Furthermore because it isintended for academic and teaching use, clarity of coding was high on the prioritylist while devising the implementation details of the various algorithms andschemes. Still all of its numerics and algorithms are similar in many ways to thoseused in industrial oriented CFD codes and thus uFVM is quite useful as a guide foranyone interested in developing a CFD code.The discretized system of equations in uFVM is stored in a matrix format suchthat each row represents the discretized equation in one element, with theoff-diagonal coefficients representing the mutual influence of neighboring elements.The computational representation of this matrix usually takes into account the factthat each row will contain only a small number of non-zero elements, specifically ineach row there will be as many non-zero elements as neighbors to the elementassociated with the row.For the example shown in Fig.
5.18, the mesh consists of 7 elements, andelement 3 has four neighbors. Thus the discretized equation for element 3 willinclude 4 coefficients in addition to the diagonal coefficient. It is clear why for largemeshes many of the non-diagonal elements are zero.In both uFVM and as is shown later in OpenFOAM®, and indeed in all CFDcodes, a sparse matrix is used to store the various coefficients of the resultingsystem of equations.
In uFVM, the matrix A is stored in an array of arrays, wherethe first element of each row represents the diagonal element, while the remainingelements of the array store the non-diagonal coefficients. The right hand side of thesystem is stored in a separate array B. This is illustrated in Fig.
5.18.5.10Computational Pointers756234129=1Connectivity1234567AB[3][3,7][1 2 5 4][3 6][3 6 7][4 5][2 5]Fig. 5.18 Coefficients for an element equation with element connectivity5.10.2 OpenFOAM®OpenFOAM® (Open source Field Operation And Manipulation) is an object-orientedC++ framework that can be used to build a variety of computational solvers forproblems in continuum mechanics with a focus on finite volume discretization.OpenFOAM® also includes several ready solvers, utilities, and applications that canbe directly used.
At the core of these libraries are a set of object classes that allow theprogrammer to manipulate meshes, geometries, and discretization techniques at a highlevel of coding. Tables 5.1, 5.2, 5.3 and 5.4 present a list of the main OpenFOAM®classes and their functions. These classes represent the basic bricks for the development of OpenFOAM® based applications and utilities. They enable programmersconstructing a variety of algorithms while allowing for extensive code re-use.Another characteristic of OpenFOAM® is its use of operator overloading thatallows algorithms to be expressed in a natural way. For example, the discretizationof the transport equation for a generic scalar / given byTable 5.1 Numerics and discretizationObjectsType of dataOpenFOAM® ClassInterpolationExplicit discretization:differential operatorImplicit discretization:differential operatorDifferencing schemesddt, div, grad, curlsurfaceInterpolation<template>fvc::ddt, d2dt2, div, laplacianfvm::1305 The Finite Volume MethodTable 5.2 Computational domainObjectsType of dataOpenFOAM® ClassVariablesMesh componentsFinite volume meshTimePrimitive variablesPoint, face, cellComputational meshTime databasescalar, vector, tensorpoint, face, cellfvMesh, polyMeshTimeTable 5.3 Field operationObjectsType of dataOpenFOAM® ClassFieldDimensionsVariable fieldAlgebraList of valuesDimension set upField + mesh + boundaries + dimension+, −, pow, = , sin, cos…Field<template>dimensionSetGeometricField<template>field operatorsTable 5.4 Linear equation systems and linear solversObjectsType of dataOpenFOAM® ClassSparse matrixIterative solverPreconditionerMatrix coefficients and manipulationIterative matrix solversMatrix preconditionerlduMatrix, fvMatrixlduMatrix::solverlduMatrix::preconditioner@ð/Þ þ r ðv/Þ ¼ r D/ r/ þ|fflfflfflfflffl{zfflfflfflfflffl}@t|fflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflffl}|fflffl{zfflffl}unsteady termconvection termdiffusion termP/ C|fflfflfflffl{zfflfflfflffl}ð5:43Þsource and sink termis basically written in OpenFOAM® as (Listing 5.1)Listing 5.1 Script for solving a simple transport equation using OpenFOAM®The fvm::div operator for example, takes the convective flux as a coefficient fielddefined over the faces of the control elements and phi as the variable field definedover the cell centroids, and returns a system of equations including a LHS matrixand a RHS source that represent the discretization of the convection operator.These LHS matrices and RHS vectors are generated for each of the operators andthen added or subtracted as needed to yield the final system of equations that5.10Computational PointersFig.