Moukalled F., Mangani L., Darwish M. The finite volume method in computational fluid dynamics. An advanced introduction with OpenFOAM and Matlab (811443), страница 31
Текст из файла (страница 31)
Ann Rev Fluid Mech 29:473–514Lerner RG, Trigg GL (1994) Encyclopaedia of physics. VHC, New YorkByron F, Fuller R (1992) Mathematics of classical and quantum physics. Dover Publications,MineolaOpenFOAM Doxygen (2015) Version 2.3.x. http://www.openfoam.org/docs/cpp/Chapter 7The Finite Volume Mesh in OpenFOAM®and uFVMAbstract The implementation of the finite volume mesh can follow many directions whether in the definition of the mesh fields, the storing of the variables, oreven in determining the connectivity relations. This chapter aims at outlining thedesign decisions that shape the implementation of two CFD codes, uFVM aneducational unstructured Finite Volume code and OpenFOAM® an industrialstrength open source code.
The two codes are thus presented, initially in terms oftheir data structure and memory management schemes, and then in terms of howcases are setup. Finally the format of the system of equations generated by each ofthe two codes are detailed. The reader will notice that while uFVM shares many ofthe implementation details with OpenFOAM®, its simplicity allows for the use ofsimpler implementation techniques and data structure.7.1 uFVMThe unstructured finite volume code uFVM was written to illustrate the variousnumerical techniques and algorithms, which collectively form a CFD program.Furthermore its numerics are in many ways similar to those in OpenFOAM® [1],making it a good vehicle to understand and present the internals of OpenFOAM®.The main data structures used in uFVM generally mirrors those in OpenFOAM®especially in terms of mesh fields and boundary conditions.
Still differencesbetween uFVM and OpenFOAM® will be used to underline various optionsavailable to CFD coders and thus to better present some implementation details.7.1.1 An OpenFOAM® Test CaseThe uFVM code is capable of reading an OpenFOAM® mesh included as part ofany OpenFOAM® test case. An OpenFOAM® test case is a directory that generally© Springer International Publishing Switzerland 2016F. Moukalled et al., The Finite Volume Method in Computational Fluid Dynamics,Fluid Mechanics and Its Applications 113, DOI 10.1007/978-3-319-16874-6_71731747 The Finite Volume Mesh in OpenFOAM® and uFVMFig. 7.1 The cavityOpenFOAM® casecontains at least three folders.
Figure 7.1 shows the innards of the cavity test casefolder, which consists of the following three sub-folders:The ‘time’ directories contain initialization and boundary condition informationabout the fields used in the test case. It is also the folder where results for varioustime steps are stored. The name of each sub-folder refers to the time at whichsimulation was performed. For example, in the cavity tutorial shown in Fig. 7.1, thevelocity field U and pressure field p are initialized from files in the ‘0’ folder 0/Uand 0/p, respectively.The system directory contains at least three files with information about the casesetup, the schemes to be used, and the various solution parameters. These files are:(i) controlDict which is concerned with the general control parameters of the testcase such as the simulation starting and ending times, the time step to be used, andrequired parameters for data output; (ii) fvSchemes in which the discretizationschemes used in the simulation are defined; (iii) fvSolution that contains information related to the solution algorithms and relaxations used during simulation.The constant directory contains information about relevant physical properties,e.g., transportProperties, and the data describing the grid system used within afolder denoted by polyMesh.For the purpose of understanding the finite volume mesh structure in uFVM,attention will be focussed on the polyMesh folder in which the information neededto construct the finite volume mesh is defined.7.1 uFVM1757.1.2 The polyMesh FolderThe polyMesh subdirectory contains the following files:pointsThe file points is a list of vectors denoting the cell vertices, with vertex 0 being thethe first vector in the list, vertex 1 the second vector, etc.
The format of the pointsfile is shown in Listing 7.1.#number of points((#x #y #z))Listing 7.1 Storing vertices as vectors of coordinates x, y and zAn example points file is shown in Listing 7.2.1074((32 16 0.9377383239)(33.9429245 16.11834526 0.9377383239)(35.84160614 16.46798134 0.9377383239)(37.67648315 17.04080009 0.9377383239)(39.42799377 17.82870483 0.9377383239)(41.07658768 18.82359314 0.9377383239))Listing 7.2 An example showing how vertices are storedfacesThe file faces represents a list of faces, with each face described by a list of indices tovertices in the points list, where again, the first entry in the list represents face 0, thesecond entry represents face 1, etc.
The format of the faces file is shown in Listing 7.3.#number of faces(#number of points for face 1 (#p1 #p2 #p3#number of points for face 2 (#p1 #p2 #p3)))Listing 7.3 Storing faces in the form of points of which the face is composed and their indices1767 The Finite Volume Mesh in OpenFOAM® and uFVMExample of a faces file is shown in Listing 7.4.3290(4(36 573 589 52)4(41 578 634 97)4(44 81 618 581)4(30 82 619 567)4(121 50 587 658)4(39 120 657 576))Listing 7.4 An example showing how faces are storedownersThe file owners is a list in which the owner of faces are stored (Listing 7.5).
Theposition of the owner in the list refers to the face it belongs to. Thus, the owner offace 0 is the index stored in the first entry, the owner of face 1 is the index stored inthe second entry, etc. The number of owners is equal to the total number of faces(interior + boundary faces).The number of Elements is equal to the largest index of the owners.#number of owners(#owner of face1#owner of face2)Listing 7.5 The format used to store ownersAn example of an owners file is shown in Listing 7.6.3290(0123456)Listing 7.6 An example showing how owners are stored7.1 uFVM177The total number of cells (nCells) in the domain can be found in the ownersfile header as shown in Listing 7.7.note "nPoints:1074nCells:918nFaces:3290nInternalFaces:1300";Listing 7.7 Header of owners fileneighboursA list of neighbor cell labels (Listing 7.8).
The number of neighbors is basicallyequal to the number of interior faces.#number of neighbour(#neighbour of face1#neighbour of face2)Listing 7.8 The format used to store neighborsAn example of a neighbours file is shown in Listing 7.9.1300(226829963134)Listing 7.9 An example showing how neighbors are storedboundaryFile boundary lists the boundaries of the domain, with the faces of each boundarytype referred to as a patch and assigned a name. The type of each boundary patch(type) is declared along with its number of faces (nFaces) and the starting face(startFace), which refers to the index of the first face in the list (Listing 7.10).7 The Finite Volume Mesh in OpenFOAM® and uFVM178#boundary patch name{type #patchtype;nFaces #number of face in patch set;startFace #starting face index for patch;}Listing 7.10 Format of a boundary patchAn example of a wall-type boundary patch is depicted in Listing 7.11.wall-4{typenFacesstartFace}wall;100;1300;Listing 7.11 An example of a wall-type boundary patch7.1.3 The uFVM MeshIn uFVM an OpenFOAM® mesh is read using the cfdReadOpenFoamMesh script.The script starts by reading the points file into the arrays of struct nodes where the(x, y, z) data is stored.
Then file faces is read and the indices of the nodes are storedinto the arrays of struct faces. Information about the face patches is then read from thefile boundary. Finally the files owners and neighbours are read and the structelements is composed. The loaded data is processed to compute additional geometricand topological information in script cfdProcessOpenFoamMesh. The details of amesh generated over an elbow and read by uFVM is shown in Listing 7.12.m = cfdReadOpenFoamMesh('elbow')m =nodes: [1x1074 struct]numberOfNodes: 1074caseDirectory: 'elbow'numberOfFaces: 3290numberOfElements: 918faces: [1x3290 struct]numberOfInteriorFaces: 1300boundaries: [1x6 struct]numberOfBoundaries: 6numberOfPatches: 6elements: [1x918 struct]numberOfBElements: 1990numberOfBFaces: 1990Listing 7.12 Information uFVM can display about a mesh7.1 uFVM179As shown in Fig.
7.2 the mesh can be plotted using the cfdPlotMesh command.Fig. 7.2 a Three dimensionaland b two dimensional viewsof the mesh over an elbowdisplayed using thecfdPlotMesh commandExample of information stored in struct nodes is presented in Listing 7.13 bydisplaying values for the node of index 1.n1= m.nodes(1)n1 =centroid:index:iFaces:iElements:[3x1 double]1[172 328 1355 1386 1677 1891 1893][112 219 220]Listing 7.13 An example of information related to a node7 The Finite Volume Mesh in OpenFOAM® and uFVM180As shown, the centroid contains the coordinates of the node in question, whileiFaces and iElements are lists of indices of the faces and elements, respectively, thatare connected to the node.Information stored in struct faces can be obtained in a similar way. For example,the attributes of the face indexed 3 are given by (Listing 7.14).m.faces(3)ans =iNodes:index:iOwner:iNeighbour:centroid:Sf:area:CN:geoDiff:T:gf:walldist:iOwnerNeighbourCoef:iNeighbourOwnerCoef:[45 82 619 582]3330[3x1 double][3x1 double]5.3046[3x1 double]4.5940[3x1 double]0.4226011Listing 7.14 An example of information related to a faceThe above example shows that the struct faces contains the list of indices of thenodes defining the face, the indices of the owner and neighbor to the face, thecentroid of the face, its surface vector, and its area.