patchExprDriver.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) 2019 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 "patchExprDriver.H"
29 #include "patchExprScanner.H"
30 #include "error.H"
31 #include "fvPatch.H"
32 #include "fvMesh.H"
33 #include "className.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace expressions
41 {
42 namespace patchExpr
43 {
44 
46 
48 (
51  dictionary,
52  patch
53 );
54 
56 (
59  idName,
60  patch
61 );
62 
63 } // End namespace patchExpr
64 } // End namespace expressions
65 } // End namespace Foam
66 
67 
68 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
69 
70 namespace Foam
71 {
72  static label getPatchID(const fvMesh& mesh, const word& patchName)
73  {
74  const auto& bMesh = mesh.boundaryMesh();
75 
76  const label patchId = bMesh.findPatchID(patchName);
77 
78  if (patchId < 0)
79  {
81  << "No patch " << patchName << " found in "
82  << flatOutput(bMesh.names()) << nl
83  << exit(FatalError);
84  }
85  return patchId;
86  }
87 
88 
89  static inline const fvPatch& findFvPatch
90  (
91  const fvMesh& mesh,
92  const word& patchName
93  )
94  {
95  return mesh.boundary()[getPatchID(mesh, patchName)];
96  }
97 
98 } // End namespace Foam
99 
100 
101 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
102 
103 const Foam::fvPatch& Foam::expressions::patchExpr::parseDriver::getFvPatch
104 (
105  const fvMesh& fvm,
106  const dictionary& dict
107 )
108 {
109  return findFvPatch
110  (
111  regionMesh(dict, fvm, true),
112  dict.get<word>("patch")
113  );
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118 
120 :
121  parsing::genericRagelLemonDriver(),
122  expressions::fvExprDriver(),
123  patch_(p)
124 {}
125 
126 
128 (
129  const fvPatch& p,
130  const dictionary& dict
131 )
132 :
135  patch_(p)
136 {}
137 
138 
140 (
141  const fvPatch& p,
142  const parseDriver& driver_
143 )
144 :
146  expressions::fvExprDriver(driver_),
147  patch_(p)
148 {}
149 
150 
152 (
153  const word& patchName,
154  const fvMesh& mesh
155 )
156 :
157  parseDriver(findFvPatch(mesh, patchName))
158 {}
159 
160 
162 (
163  const dictionary& dict,
164  const fvMesh& mesh
165 )
166 :
167  parseDriver(getFvPatch(mesh, dict), dict)
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
174 (
175  const std::string& expr,
176  size_t pos,
177  size_t len
178 )
179 {
180  scanner scan(this->debugScanner());
181 
182  scan.process(expr, pos, len, *this);
183 
184  return 0;
185 }
186 
187 
188 // ************************************************************************* //
patchExprScanner.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
patchExprDriver.H
Foam::expressions::patchExpr::parseDriver::parse
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)
Execute the parser.
Definition: patchExprDriver.C:174
Foam::expressions::fvExprDriver
Base driver for parsing value expressions associated with an fvMesh.
Definition: fvExprDriver.H:138
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
Foam::getPatchID
static label getPatchID(const fvMesh &mesh, const word &patchName)
Definition: patchExprDriver.C:72
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
error.H
Foam::parsing::genericRagelLemonDriver
Generic interface code for Ragel/Lemon combination Subclasses should implement one or more process() ...
Definition: genericRagelLemonDriver.H:59
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
Foam::expressions::patchExpr::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(fvExprDriver, parseDriver, dictionary, patch)
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
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::patchExpr::parseDriver
Driver for patch expressions.
Definition: patchExprDriver.H:140
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::fvMesh::boundary
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:589
Foam::findFvPatch
static const fvPatch & findFvPatch(const fvMesh &mesh, const word &patchName)
Definition: patchExprDriver.C:90
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::expressions::exprDriver::dict
const dictionary & dict() const
The dictionary with all input data/specification.
Definition: exprDriver.H:298
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::expressions::patchExpr::scanner::process
bool process(const std::string &str, size_t pos, size_t len, parseDriver &driver_)
Evaluate sub-string.
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::expressions::patchExpr::defineTypeNameAndDebug
defineTypeNameAndDebug(parseDriver, 0)
fvPatch.H
patchId
label patchId(-1)
Foam::expressions::fvExprDriver::regionMesh
static const fvMesh & regionMesh(const dictionary &dict, const fvMesh &mesh, bool readIfNecessary)
Definition: fvExprDriver.C:533
Foam::expressions::patchExpr::parseDriver::parseDriver
parseDriver(const parseDriver &)=delete
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:90
Foam::expressions::patchExpr::scanner
Ragel lexer/scanner interface for patch expressions.
Definition: patchExprScanner.H:68
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177