caseInfo.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 OpenFOAM Foundation
9 Copyright (C) 2015-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "caseInfo.H"
30#include "Time.H"
31#include "boundaryInfo.H"
32#include "boundaryTemplates.H"
33
34using namespace Foam;
35
36// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37
39(
40 const label patchI,
41 const word& patchName
42) const
43{
44 const wordList& patchGroups = boundaryInfo_.groups()[patchI];
45
46 // Assign condition according to last condition applied, wins
47 forAllReverse(conditionNames_, conditionI)
48 {
49 const wordRes& patchNames = patchNames_[conditionI];
50
51 for (const wordRe& select : patchNames)
52 {
53 if (select == patchName)
54 {
55 // Literal match
56 return conditionI;
57 }
58 else if (select.match(patchName))
59 {
60 // Regex match
61 return conditionI;
62 }
63 else
64 {
65 // Check for group match
66 for (const word& groupName : patchGroups)
67 {
68 if (select == groupName)
69 {
70 return conditionI;
71 }
72 }
73 }
74 }
75 }
76
78 << "Boundary patch " << patchName << " not defined"
79 << exit(FatalError);
80
81 return -1;
82}
83
84
85void Foam::caseInfo::updateGeometricBoundaryField()
86{
87 forAll(boundaryInfo_.names(), i)
88 {
89 const word& patchName = boundaryInfo_.names()[i];
90
91 if (!boundaryInfo_.constraint()[i])
92 {
93 // Condition ID to apply to mesh boundary patch name
94 const label conditionI = findPatchConditionID(i, patchName);
95
96 const word& category = patchCategories_[conditionI];
97
98 boundaryInfo_.setType(i, category);
99 }
100 }
101
102 boundaryInfo_.write();
103}
104
105
106// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107
109:
110 properties_
111 (
113 (
114 "caseProperties",
115 runTime.system(),
117 runTime,
118 IOobject::MUST_READ,
119 IOobject::NO_WRITE
120 )
121 ),
122 boundaryInfo_(runTime, regionName),
123 bcDict_(properties_.subDict("boundaryConditions")),
124 conditionNames_(bcDict_.toc()),
125 patchNames_(conditionNames_.size()),
126 patchCategories_(conditionNames_.size()),
127 patchTypes_(conditionNames_.size())
128{
129 // Read the (user-supplied) boundary condition information
130 Info<< " Reading case properties" << endl;
131
132 forAll(conditionNames_, i)
133 {
134 const dictionary& dict = bcDict_.subDict(conditionNames_[i]);
135 dict.readEntry("category", patchCategories_[i]);
136 dict.readEntry("type", patchTypes_[i]);
137 dict.readEntry("patches", patchNames_[i]);
138 }
139
140 updateGeometricBoundaryField();
141}
142
143
144// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145
147(
148 const word& regionPrefix,
149 const boundaryTemplates& bcTemplates
150) const
151{
152 // Check that all conditions have been specified correctly wrt templates
153 forAll(conditionNames_, i)
154 {
155 bcTemplates.checkPatch
156 (
157 regionPrefix,
158 conditionNames_[i],
159 patchCategories_[i],
160 patchTypes_[i]
161 );
162 }
163}
164
165
167{
168 return patchNames_;
169}
170
171
172const Foam::word& Foam::caseInfo::conditionName(const label patchI) const
173{
174 return conditionNames_[patchI];
175}
176
177
178const Foam::word& Foam::caseInfo::patchCategory(const label patchI) const
179{
180 return patchCategories_[patchI];
181}
182
183
184const Foam::word& Foam::caseInfo::patchType(const label patchI) const
185{
186 return patchTypes_[patchI];
187}
188
189
191(
192 const word& regionPrefix,
193 const word& fieldName,
194 const boundaryTemplates& bcTemplates
195) const
196{
197 dictionary boundaryField;
198
199 forAll(boundaryInfo_.names(), j)
200 {
201 const word& patchName = boundaryInfo_.names()[j];
202
203 if (boundaryInfo_.constraint()[j])
204 {
205 dictionary patchDict;
206 patchDict.add("type", boundaryInfo_.types()[j]);
207
208 // Add value for processor patches
209 patchDict.add("value", "${:internalField}");
210 boundaryField.add(patchName.c_str(), patchDict);
211 }
212 else
213 {
214 // Condition ID to apply to mesh boundary patch name
215 const label conditionI = findPatchConditionID(j, patchName);
216
217 if (conditionI == -1)
218 {
220 << "Unable to find patch " << patchName
221 << " in list of boundary conditions"
222 << exit(FatalError);
223 }
224
225 const word& condition = conditionNames_[conditionI];
226
227 const word& category = patchCategories_[conditionI];
228
229 const word& patchType = patchTypes_[conditionI];
230
231 dictionary optionDict;
232 if (bcTemplates.optionsRequired(regionPrefix, category, patchType))
233 {
234 optionDict = bcDict_.subDict(condition).subDict("options");
235 }
236
237 // Create the patch dictionary entry
238 dictionary patchDict
239 (
240 bcTemplates.generatePatchDict
241 (
242 regionPrefix,
243 fieldName,
244 condition,
245 category,
246 patchType,
247 optionDict
248 )
249 );
250
251 boundaryField.add(patchName.c_str(), patchDict);
252 }
253 }
254
255 return boundaryField;
256}
257
258
259// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
const List< wordList > & groups() const
Groups.
Class to store boundary template specifications.
void checkPatch(const word &regionPrefix, const word &condition, const word &category, const word &patchType) const
Check that user supplied patch info is valid.
dictionary generatePatchDict(const word &regionPrefix, const word &fieldName, const word &condition, const word &category, const word &patchType, const dictionary &conditionOptions) const
Generate a dictionary representation of patch boundary condition.
bool optionsRequired(const word &regionPrefix, const word &category, const word &patchType) const
Return true if condition requires additional user options.
Class to hold information related to the simaulation case.
Definition: caseInfo.H:57
void checkPatches(const word &regionPrefix, const boundaryTemplates &bcTemplates) const
Check patches.
label findPatchConditionID(const label patchI, const word &patchName) const
Return the condition ID for a boundary patch.
const List< wordRes > & patchNames() const
Return the list of patch names.
const word & patchCategory(const label patchI) const
Return the category name for patch with index patchI.
dictionary generateBoundaryField(const word &regionPrefix, const word &fieldName, const boundaryTemplates &bcTemplates) const
Generate boundary field (dictionary)
const word & conditionName(const label patchI) const
Return the condition name for patch with index patchI.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
This is the point-patch responsible for managing the force integration on a 'lumped-point' basis,...
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:83
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
Foam::word regionName(Foam::polyMesh::defaultRegion)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
List< bool > select(const label n, const labelUList &locations)
Definition: BitOps.C:142
List< label > toc(const UList< bool > &bools)
Return the (sorted) values corresponding to 'true' entries.
Definition: BitOps.C:166
Namespace for OpenFOAM.
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: MSwindows.C:1158
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:346