Moukalled F., Mangani L., Darwish M. The finite volume method in computational fluid dynamics. An advanced introduction with OpenFOAM and Matlab (811443), страница 34
Текст из файла (страница 34)
It is worth noting that the class itself doesnot recognize boundaries or domain interfaces. Boundaries and domain interfacesare defined in the polyMesh class, which is derived from the primitiveMesh class.In addition to possessing all the attributes of the derived class, the polyMesh classintroduces the handling of boundary definition and information, as shown inListing 7.39. Again this class does not require any particular discretization scheme.7 The Finite Volume Mesh in OpenFOAM® and uFVM194const labelUList & owner () const//Internal face owner.const labelUList & neighbour () const//Internal face neighbour.const DimensionedField< scalar, volMesh > &V0 () constReturn old-time cell volumes.const DimensionedField< scalar, volMesh > &V00 () constReturn old-old-time cell volumes.tmp< surfaceVectorField >delta () constReturn face deltas as surfaceVectorFieldListing 7.39 Information that can be obtained from the polymesh classWhile primitiveMesh and polyMesh are the basic classes of the polyhedralmesh, the fvMesh class is derived from polyMesh and adds the particular data andfunctions needed for the finite-volume discretization.
Addressing information aswell as boundary information and specific mesh data are accessible for finite volume discretization.OpenFOAM® decomposes the boundary mesh into patches stored in a listdesignated by polyPatchList under the class polyBoundaryMesh. Then, similar tointerior mesh, a specialized class denoted by fvBoundaryMesh is derived frompolyBoundaryMesh that inherits its functionalities and expands on it to includespecific functions and data needed for finite-volume discretization. As for internaldiscretization, a similar hierarchy of classes composed of primitivePatch,polyPatch, and fvPatch is defined for boundary discretization.
These classes arespecific for the boundary mesh and contain the geometric information of eachboundary. But it is the fvPatch that is used to implement the boundary conditionsduring the finite volume discretization. Figure 7.9 presents a schematic of the basicmesh description used in OpenFOAM®.In a similar way the fvMesh is used to access all mesh functionalities. Thus, it ismainly with fvMesh and fvPatch that the discretization classes and functionsinteract.Patch 3boundary facesPatch 1Patch 2interior facesFig.
7.9 Schematic of the basic mesh description used in OpenFOAM® [1]7.2 OpenFOAM®195Examples of codes for reading and accessing the main properties of a meshwithin the OpenFOAM® framework are now presented.To read a mesh, the fvMesh class that handles the finite volume mesh anddiscretization is needed along with a special constructor as shown in Listing 7.40.#include "setRootCase.H"#include "createTime.H"Foam::Info<< "Create mesh for time = "<< runTime.timeName() << Foam::nl << Foam::endl;Foam::fvMesh mesh(Foam::IOobject(Foam::fvMesh::defaultRegion,runTime.timeName(),runTime,Foam::IOobject::MUST_READ));Listing 7.40 Script to read a mesh in OpenFOAM®The include statements in Listing 7.40 are required for initialization beforereading the mesh files.Once the fvMesh instantiation is constructed under the variable named mesh, themanipulation of the loaded mesh and collection of the necessary data for furtherprogramming can proceed, as shown in Listing 7.41.// read the element centroidsvolVectorField C = mesh.C();// element volumesvolScalarField V = mesh.V();// surface centroidssurfaceVectorField Cf = mesh.Cf();Listing 7.41 Extracting data after reading a mesh in OpenFOAM®To loop over the cell volumes, the dedicated class function for information onvolumes should first be called (Listing 7.42).
This is accomplished viaconst DimensionedField< scalar, volMesh >&cellVolumes = mesh.V();Listing 7.42 Getting information on volumesand then a loop over the cell volumes can be performed as shown in Listing 7.43.1967 The Finite Volume Mesh in OpenFOAM® and uFVMforAll(cellVolumes, cellI){scalar cellVolume = cellVolumes[cellI];}Listing 7.43 Looping over all cell volumesIn OpenFOAM® the standard “for” loop is replaced by a more compact syntaxusing a macro definition named forAll (Listing 7.44) defined in the UList.H file as#define forAll(list, i) \for (Foam::label i=0; i<(list).size(); i++)Listing 7.44 Script used to replace the standard “for” loop by the macro forAllIn a similar way access to other mesh information can be performed as shown inListing 7.45.// internal accessforAll(cellCenters.internalField(), cellI){vector cellCenter = cellCenters[cellI];}// internal accessforAll(faceNormals.internalField(), faceI){vector faceNormal = faceNormals.internalField()[faceI];}]Listing 7.45 Script used to access mesh informationFor boundary patches the access procedure is similar except that now each patchhas its own class definition, and the full list of patches is defined in thefvBoundaryMesh class containing the fvPatches list.
Therefore to access boundary data the following is used (Listing 7.46):const fvBoundaryMesh& boundaryMesh = mesh.boundary();forAll(boundaryMesh, patchI){const fvPatch& patch = boundaryMesh[patchI];forAll(patch, faceI){vector faceNormal = patch.Sf()[faceI];scalar faceArea = patch.magSf()[faceI];vector unitFaceNormal = patch.nf()()[faceI];vector faceCenter = patch.Cf()[faceI];label owner = patch.faceCells()[faceI];}}Listing 7.46 Accessing data on boundary patches7.2 OpenFOAM®1977.2.1 Fields and MemoryWithin the OpenFOAM® generic framework, lists, arrays, and in general containersof different types and sizes can be defined. For a given mesh and computationalstructure, it would be useful to define a specific class capable of combining fields,lists, and vectors directly with the mesh.
A useful class that satisfies this requirement is the template class GeometricField<Type,…>. Each data defined using thisclass is strictly related to the mesh dimensions, both for the boundaries and interiordomain (be it the number of elements, the number of interior faces or even thenumber of interior vertices).In general the template class GeometricField<Type,…> stores the followingdata structure based on three main different characteristics of the mesh:• volField<Type> A field defined at cell centers;• surfaceField<Type> A field defined on cell faces;• pointField<Type> A field defined on cell vertices.The class also inherits the following properties:• Dimensions: OpenFOAM® provides a useful feature in handling fields underthe class GeometricField.
OpenFOAM® associates with each field a dimension(meter, kg, seconds, etc.) characterizing the physical meaning of the variable.Based on that all operations carried out with GeometricField have to be performed with fields of the same dimension (e.g., velocity can be summed up withvelocity not pressure) otherwise a runtime error transpires during execution.Moreover the dimension of any new field defined as a combination of existingfields in GeometricField, is automatically generated by OpenFOAM® throughapplying the same algebraic relation utilized to generate the new field on thedimensions of the used fields (e.g., dividing a mass field with a volume fieldresults in a field having the dimension of density).• InternalField: This is a repository of size equal to the size of the internal meshproperties (cell centers, vertices, or faces) in which internal information of adefined field is stored.• BoundaryField: contains all information pertinent to a defined variable at theboundary.
A list of patches is developed and each field is defined for the patchesof the boundary with the name GeometricBoundaryField. Operations can beperformed either on the full set of boundaries or on a specific patch usingfvPatchField.• Mesh: Being a class strictly related to the mesh, each GeometricField containsa reference to the corresponding mesh.• Time Values and Previous Values: This class is required to handle the specificfield during simulation.
It stores information of the previous two time steps forsecond order accuracy in time.1987 The Finite Volume Mesh in OpenFOAM® and uFVMIn the following, examples on the use of the specific class GeometricField toaccess the main properties of a field associated with a mesh are provided.In the first example it is required to define the two variables U and T, representing a velocity and a temperature field, respectively, at the cell center of themesh. This will be done using the templates of the specialized classGeometricField, which supports scalars, vectors, and tensors data type.