preservePatchTypes.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "preservePatchTypes.H"
28 #include "polyBoundaryMesh.H"
29 
30 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
31 
33 (
34  const objectRegistry& obr,
35  const word& meshInstance,
36  const fileName& meshDir,
37  const wordList& patchNames,
38  PtrList<dictionary>& patchDicts,
39  const word& defaultFacesName,
40  word& defaultFacesType
41 )
42 {
43  patchDicts.setSize(patchNames.size());
44 
45  dictionary patchDictionary;
46 
47  // Read boundary file as single dictionary
48  {
49  IOobject patchEntriesHeader
50  (
51  "boundary",
52  meshInstance,
53  meshDir,
54  obr,
55  IOobject::MUST_READ,
56  IOobject::NO_WRITE,
57  false
58  );
59 
60  if (patchEntriesHeader.typeHeaderOk<polyBoundaryMesh>(true))
61  {
62  // Create a list of entries from the boundary file.
63  polyBoundaryMeshEntries patchEntries(patchEntriesHeader);
64 
65  forAll(patchEntries, patchi)
66  {
67  patchDictionary.add(patchEntries[patchi]);
68  }
69  }
70  }
71 
72  forAll(patchNames, patchi)
73  {
74  if (patchDictionary.found(patchNames[patchi]))
75  {
76  const dictionary& patchDict =
77  patchDictionary.subDict(patchNames[patchi]);
78 
79  patchDicts.set(patchi, patchDict.clone());
80  patchDicts[patchi].remove("nFaces");
81  patchDicts[patchi].remove("startFace");
82  }
83  }
84 
85  if (patchDictionary.found(defaultFacesName))
86  {
87  const dictionary& patchDict =
88  patchDictionary.subDict(defaultFacesName);
89 
90  patchDict.readIfPresent("geometricType", defaultFacesType);
91  }
92 
93  Info<< nl << "Default patch type set to " << defaultFacesType << endl;
94 }
95 
96 
97 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
bool typeHeaderOk(const bool checkType=true)
Read header (uses typeFilePath to find file) and check header.
A class for handling file names.
Definition: fileName.H:69
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:340
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:814
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:692
A class for handling words, derived from string.
Definition: word.H:59
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
preservePatchTypes
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
Foam::polyBoundaryMesh.
static const char nl
Definition: Ostream.H:265
void preservePatchTypes(const objectRegistry &obr, const word &meshInstance, const fileName &meshDir, const wordList &patchNames, PtrList< dictionary > &patchDicts, const word &defaultFacesName, word &defaultFacesType)
Preserve patch types.
label patchi
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:63
messageStream Info
Registry of regIOobjects.
Foam::polyBoundaryMeshEntries.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92