patchMeanVelocityForce.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-2016 OpenFOAM Foundation
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 "patchMeanVelocityForce.H"
31 
32 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fv
37 {
38  defineTypeNameAndDebug(patchMeanVelocityForce, 0);
39 
41  (
42  option,
43  patchMeanVelocityForce,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 Foam::fv::patchMeanVelocityForce::patchMeanVelocityForce
53 (
54  const word& sourceName,
55  const word& modelType,
56  const dictionary& dict,
57  const fvMesh& mesh
58 )
59 :
60  meanVelocityForce(sourceName, modelType, dict, mesh),
61  patch_(coeffs_.get<word>("patch")),
62  patchi_(mesh.boundaryMesh().findPatchID(patch_))
63 {
64  if (patchi_ < 0)
65  {
67  << "Cannot find patch " << patch_
68  << exit(FatalError);
69  }
70 }
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
76 (
77  const volVectorField& U
78 ) const
79 {
80  vector2D sumAmagUsumA
81  (
82  sum
83  (
84  (flowDir_ & U.boundaryField()[patchi_])
85  *mesh_.boundary()[patchi_].magSf()
86  ),
87  sum(mesh_.boundary()[patchi_].magSf())
88  );
89 
90 
91  // If the mean velocity force is applied to a cyclic patch
92  // for parallel runs include contributions from processorCyclic patches
93  // generated from the decomposition of the cyclic patch
94  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
95 
96  if (Pstream::parRun() && isA<cyclicPolyPatch>(patches[patchi_]))
97  {
98  labelList processorCyclicPatches
99  (
100  processorCyclicPolyPatch::patchIDs(patch_, patches)
101  );
102 
103  forAll(processorCyclicPatches, pcpi)
104  {
105  const label patchi = processorCyclicPatches[pcpi];
106 
107  sumAmagUsumA.x() +=
108  sum
109  (
110  (flowDir_ & U.boundaryField()[patchi])
111  *mesh_.boundary()[patchi].magSf()
112  );
113 
114  sumAmagUsumA.y() += sum(mesh_.boundary()[patchi].magSf());
115  }
116  }
117 
118  mesh_.reduce(sumAmagUsumA, sumOp<vector2D>());
119 
120  return sumAmagUsumA.x()/sumAmagUsumA.y();
121 }
122 
123 
124 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::fv::patchMeanVelocityForce::magUbarAve
virtual scalar magUbarAve(const volVectorField &U) const
Calculate and return the magnitude of the mean velocity.
Definition: patchMeanVelocityForce.C:76
patchMeanVelocityForce.H
Foam::Vector2D< scalar >
processorCyclicPolyPatch.H
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(option, 0)
Foam::fv::meanVelocityForce
Calculates and applies the force necessary to maintain the specified mean velocity.
Definition: meanVelocityForce.H:70
U
U
Definition: pEqn.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, fixedTemperatureConstraint, dictionary)
Foam::List< label >
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::Vector2D::y
const Cmpt & y() const
Access to the vector y component.
Definition: Vector2DI.H:78
Foam::GeometricField< vector, fvPatchField, volMesh >
Foam::Vector2D::x
const Cmpt & x() const
Access to the vector x component.
Definition: Vector2DI.H:71