pressurePIDControlInletVelocityFvPatchVectorFieldTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "surfaceFields.H"
29 #include "syncTools.H"
30 
31 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
32 
33 template <class Type>
34 void Foam::pressurePIDControlInletVelocityFvPatchVectorField::faceZoneAverage
35 (
36  const word& name,
37  const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
38  scalar& area,
39  Type& average
40 ) const
41 {
42  const fvMesh& mesh = patch().boundaryMesh().mesh();
43  const auto& pbm = mesh.boundaryMesh();
44 
45  bitSet isMasterFace(syncTools::getInternalOrMasterFaces(mesh));
46 
47  const faceZone& zone = mesh.faceZones()[name];
48 
49  area = 0;
50  average = Type(Zero);
51 
52  for (const label meshFacei : zone)
53  {
54  if (mesh.isInternalFace(meshFacei))
55  {
56  const scalar da = mesh.magSf()[meshFacei];
57 
58  area += da;
59  average += da*field[meshFacei];
60  }
61  else if (isMasterFace[meshFacei])
62  {
63  const label patchi = pbm.patchID(meshFacei);
64  const label patchFacei = pbm[patchi].whichFace(meshFacei);
65  const scalar da = mesh.magSf().boundaryField()[patchi][patchFacei];
66 
67  area += da;
68  average += da*field.boundaryField()[patchi][patchFacei];
69  }
70  }
71 
72  reduce(area, sumOp<scalar>());
73  reduce(average, sumOp<Type>());
74 
75  average /= (area + VSMALL);
76 }
77 
78 
79 // ************************************************************************* //
Foam::surfaceFields.
const polyBoundaryMesh & pbm
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1)
rDeltaTY field()
tmp< GeometricField< Type, faPatchField, areaMesh > > average(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Area-weighted average a edgeField creating a areaField.
Definition: facAverage.C:40
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const wordList area
Standard area field types (scalar, vector, tensor, etc)
static bitSet getInternalOrMasterFaces(const polyMesh &mesh)
Get per face whether it is internal or a master of a coupled set of faces.
Definition: syncTools.C:141
const std::string patch
OpenFOAM patch number as a std::string.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127