Moukalled F., Mangani L., Darwish M. The finite volume method in computational fluid dynamics. An advanced introduction with OpenFOAM and Matlab (811443), страница 30
Текст из файла (страница 30)
InOpenFOAM® this is provided in faceList (Listing 6.4), which is a list of identitiesof the points defining the faces of the mesh.const faceList& fs = faces();forAll(fs, facei){const labelList& f = fs[facei];label nPoints = f.size();Listing 6.4 List of the identities of points defining facesThen a for loop is performed for each face. Inside the loop, the number of pointsdescribing the face and their identities are first read in order to access the1666 The Finite Volume Meshcoordinates of the corresponding vertices. When a face is defined by only threevertices, then direct calculations of its centroid location and area are performed, asshown in Listing 6.5.// If the face is a triangle, do a directcalculationfor efficiency// and to avoid round-off error-related problemsif (nPoints == 3){fCtrs[facei] = (1.0/3.0)*(p[f[0]] + p[f[1]] +p[f[2]]);fAreas[facei] = 0.5*((p[f[1]] - p[f[0]])^(p[f[2]] p[f[0]]));}else{Listing 6.5 Equations used in calculating the geometric center and area of a triangular faceIn this case the face center fCtrs[facei] is evaluated directly using Eq.
(6.21) withk = 3, while the face area is calculated using Eq. (6.23) where the symbol “^”represents vector product.For a generic polygonal shape, the face is first decomposed into triangles. Forthat purpose, OpenFOAM® defines estimated centers for faces based on the averagevalue of vertices defining the face, as displayed in Listing 6.6.vector sumN = vector::zero;scalar sumA = 0.0;vector sumAc = vector::zero;point fCentre = p[f[0]];for (label pi = 1; pi < nPoints; pi++){fCentre += p[f[pi]];}fCentre /= nPoints;Listing 6.6 Compute estimated centers for facesListing 6.7 indicates that a loop over all faces is performed for calculating thegeometric centers and areas of the triangles into which these faces are decomposed.6.6 Computational Pointers167for (label pi = 0; pi < nPoints; pi++){const point& nextPoint = p[f[(pi + 1) % nPoints]];vector c = p[f[pi]] + nextPoint + fCentre;vector n = (nextPoint - p[f[pi]])^(fCentrescalar a = mag(n);-p[f[pi]]);sumN += n;sumA += a;sumAc += a*c;}Listing 6.7 Decomposing the polygonal faces into triangles and calculating the geometric centersand areas of these trianglesThis is done by finding the face center “c” of each triangle using Eq.
(6.21) (thefactor 1=3 is applied later), the face normal vector “n” and its magnitude “a” thatdefines the triangle area as stated by Eq. (6.23) (again the factor 1=2 will be appliedlater). All metrics of the decomposed triangles are then summed up and normalizedin accordance with Eq. (6.22), where now the factors 1=3 and 1=2 are applied, asdepicted in Listing 6.8.// This is to deal with zero-area faces.
Mark very smallfaces// to be detected in e.g., processorPolyPatch.if (sumA < ROOTVSMALL){fCtrs[facei] = fCentre;fAreas[facei] = vector::zero;}else{fCtrs[facei] = (1.0/3.0)*sumAc/sumA;fAreas[facei] = 0.5*sumN;}Listing 6.8 Calculating the centroids and areas of facesIn case of a degenerate face, i.e., when “sumA < a very small number”, a rescuevalue is set for the face.6.6.2.2Volume and Centroid of ElementsAfter computing the normals, areas, and centers of faces, it is possible to evaluatethe metrics of cells.
Similar to faces, the basic idea for a polyhedral cell is todecompose it into a sum of tetrahedra elements. The operations that calculate1686 The Finite Volume Meshvolumes and centroids of elements are then defined in the file “$FOAM_SRC/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C” usingthe function shown in Listing 6.9.void Foam::primitiveMesh::makeCellCentresAndVols(const vectorField& fCtrs,const vectorField& fAreas,vectorField& cellCtrs,scalarField& cellVols) const{Listing 6.9 Function used to calculate volumes and centers of elementsThis function uses four arguments where the first two represent, respectively,centers and areas of faces. The remaining two arguments return objects containingcenters and volumes of cells.
As shown in Listing 6.10, the “for” loops are definedtwice. This redundancy is related to the LDU addressing used in OpenFOAM®,which will be introduced and described in the Chap. 7.// Clear the fields for accumulationcellCtrs = vector::zero;cellVols = 0.0;const labelList& own = faceOwner();const labelList& nei = faceNeighbour();vectorField cEst(nCells(), vector::zero);labelField nCellFaces(nCells(), 0);forAll(own, facei){cEst[own[facei]] += fCtrs[facei];nCellFaces[own[facei]] += 1;}forAll(nei, facei){cEst[nei[facei]] += fCtrs[facei];nCellFaces[nei[facei]] += 1;}forAll(cEst, celli){cEst[celli] /= nCellFaces[celli];}Listing 6.10 Compute estimated cell centersIn order to calculate the cells centroids and volumes, the first step is the evaluation of xG , the geometric centers of cells denoted in Listing 6.10 by cEst, using6.6 Computational Pointers169the first relation in Eq. (6.25).
Once the xG values are obtained, calculations of thepyramids’ volumes and cell centroids proceed by applying Eq. (6.25) using thecode displayed in Listing 6.11.forAll(own, facei){// Calculate 3*face-pyramid volumescalar pyr3Vol =max(fAreas[facei] & (fCtrs[facei]cEst[own[facei]]), VSMALL);// Calculate face-pyramid centrevector pc = (3.0/4.0)*fCtrs[facei](1.0/4.0)*cEst[own[facei]];-+// Accumulate volume-weighted face-pyramid centrecellCtrs[own[facei]] += pyr3Vol*pc;// Accumulate face-pyramid volumecellVols[own[facei]] += pyr3Vol;}forAll(nei, facei){// Calculate 3*face-pyramid volumescalar pyr3Vol =max(fAreas[facei] & (cEst[nei[facei]] fCtrs[facei]), VSMALL);// Calculate face-pyramid centrevector pc = (3.0/4.0)*fCtrs[facei](1.0/4.0)*cEst[nei[facei]];+// Accumulate volume-weighted face-pyramid centrecellCtrs[nei[facei]] += pyr3Vol*pc;// Accumulate face-pyramid volumecellVols[nei[facei]] += pyr3Vol;}Listing 6.11 Calculating cell centers and volumesIn the above code, fCtrs corresponds to xCE while “cEst—fCtrs” corresponds tothe distance vector dGf displayed in Fig.
6.21. The final values are obtained, asshown in Listing 6.12, by dividing cell centroids by cell volumes and then dividingcell volumes by 3.cellCtrs /= cellVols;cellVols *= (1.0/3.0);Listing 6.12 The final values of cell centroids and volumesThe mesh data structure for uFVM and OpenFOAM® will be described in detailin Chap. 7.1706.76 The Finite Volume MeshClosureThe geometric data defining a finite volume mesh were presented in this chapter.
Itwas stressed that the finite volume mesh is not simply the set of non-overlappingelements and nodes. It also includes the set of all geometric quantities withinformation about their topologies. The collection of all this represents the infrastructure needed by the equation discretization method adopted in this book,namely the Finite Volume Method (FVM).6.8ExercisesExercise 1Compare the equations presented in the book to the ones used in OpenFOAM® forcomputing the interpolation weights at the faces, the owner-Neighbor elementdistances, and the non orthogonal coefficient. These can be found in OpenFOAM®using Doxygen [14] in the functions makeWeights(), makeDeltaCoeffs(), andmakeNonOrthDeltaCoeffs().Exercise 2Write a program that reads an OpenFOAM® mesh and checks that for each elementthe sum of the surface vectors is zero.Exercise 3Start by reading a mesh into uFVM and then investigate the mesh structure (use m =cfdGetMesh to get access to the mesh data, and then investigate the structure ofan element, a face, and a vertex).References1.
Thompson JF, Warsi Z, Mastin C (1985) Numerical grid generation. Elsevier SciencePublishers, New York2. Cheng S, Dey T, Shewchuk JR (2012) Delaunay mesh generation. CRC Press, Boca Raton3. Thompson JF, Soni BK, Weatherill NP (eds) (1999) Handbook of grid generation, Chapter 17.CRC Press, Boca Raton4. George PL (1991) Automatic mesh generation. Wiley, New York5. Frey P, George PL (2010) Mesh generation. Wiley, New York6. Bern M, Plassmann P (2000) Mesh generation. Handbook of computational geometry.Elsevier Science, North Holland7. Mavriplis DJ (1996) Mesh generation and adaptivity for complex geometries and flows.
In:Peyret R (ed) Handbook of computational fluid mechanics. Academic Press, London8. Thompson JF, Soni BK, Weatherill NP (1998) Handbook of grid generation. CRC Press, BocaRaton9. Chappell JA, Shaw JA, Leatham M (1996) The generation of hybrid grids incorporatingprismatic regions for viscous flow calculations. In: Soni BK, Thompson JF, Hauser J,References10.11.12.13.14.171Eiseman, PR (eds) Numerical grid generation in computational field simulations. MississippiState University, MS, pp 537–546OpenFOAM (2015) Version 2.3.x. http://www.openfoam.orgMavriplis DJ (1997) Unstructured grid techniques.