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 -------------------------------------------------------------------------------
11 License
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 
34 using 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 
85 void 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  (
112  IOobject
113  (
114  "caseProperties",
115  runTime.system(),
116  regionName,
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 
172 const Foam::word& Foam::caseInfo::conditionName(const label patchI) const
173 {
174  return conditionNames_[patchI];
175 }
176 
177 
178 const Foam::word& Foam::caseInfo::patchCategory(const label patchI) const
179 {
180  return patchCategories_[patchI];
181 }
182 
183 
184 const 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 // ************************************************************************* //
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
const List< wordRes > & patchNames() const
Return the list of patch names.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
dictionary generateBoundaryField(const word &regionPrefix, const word &fieldName, const boundaryTemplates &bcTemplates) const
Generate boundary field (dictionary)
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:637
Class to store boundary template specifications.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:453
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:414
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect...
Foam::word regionName(Foam::polyMesh::defaultRegion)
label findPatchConditionID(const label patchI, const word &patchName) const
Return the condition ID for a boundary patch.
A class for handling words, derived from Foam::string.
Definition: word.H:63
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.
wordList patchNames(nPatches)
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
bool optionsRequired(const word &regionPrefix, const word &category, const word &patchType) const
Return true if condition requires additional user options.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
const word & patchCategory(const label patchI) const
Return the category name for patch with index patchI.
const word & patchType(const label patchI) const
Return the type name for patch with index patchI.
caseInfo(const Time &runTime, const word &regionName)
Constructor.
messageStream Info
Information stream (stdout output on master, null elsewhere)
const word & conditionName(const label patchI) const
Return the condition name for patch with index patchI.
void checkPatch(const word &regionPrefix, const word &condition, const word &category, const word &patchType) const
Check that user supplied patch info is valid.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:430
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: POSIX.C:1702
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:171
void checkPatches(const word &regionPrefix, const boundaryTemplates &bcTemplates) const
Check patches.
List< label > toc(const UList< bool > &bools)
Return the (sorted) values corresponding to &#39;true&#39; entries.
Definition: BitOps.C:158
Namespace for OpenFOAM.