Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / meshes / preservePatchTypes / preservePatchTypes.C
blobd1e667a6f1feea790f3733e577c22f601a970014
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "preservePatchTypes.H"
27 #include "polyBoundaryMeshEntries.H"
29 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
31 void Foam::preservePatchTypes
33     const objectRegistry& obr,
34     const word& meshInstance,
35     const fileName& meshDir,
36     const wordList& patchNames,
37     PtrList<dictionary>& patchDicts,
38     const word& defaultFacesName,
39     word& defaultFacesType
42     patchDicts.setSize(patchNames.size());
44     dictionary patchDictionary;
46     // Read boundary file as single dictionary
47     {
48         IOobject patchEntriesHeader
49         (
50             "boundary",
51             meshInstance,
52             meshDir,
53             obr,
54             IOobject::MUST_READ,
55             IOobject::NO_WRITE,
56             false
57         );
59         if (patchEntriesHeader.headerOk())
60         {
61             // Create a list of entries from the boundary file.
62             polyBoundaryMeshEntries patchEntries(patchEntriesHeader);
64             forAll(patchEntries, patchi)
65             {
66                 patchDictionary.add(patchEntries[patchi]);
67             }
68         }
69     }
71     forAll (patchNames, patchi)
72     {
73         if (patchDictionary.found(patchNames[patchi]))
74         {
75             const dictionary& patchDict =
76                 patchDictionary.subDict(patchNames[patchi]);
78             patchDicts.set(patchi, patchDict.clone());
79             patchDicts[patchi].remove("nFaces");
80             patchDicts[patchi].remove("startFace");
81         }
82     }
84     if (patchDictionary.found(defaultFacesName))
85     {
86         const dictionary& patchDict =
87             patchDictionary.subDict(defaultFacesName);
89         patchDict.readIfPresent("geometricType", defaultFacesType);
90     }
92     Info<< nl << "Default patch type set to " << defaultFacesType << endl;
96 void Foam::preservePatchTypes
98     const objectRegistry& obr,
99     const word& meshInstance,
100     const fileName& meshDir,
101     const wordList& patchNames,
102     wordList& patchTypes,
103     const word& defaultFacesName,
104     word& defaultFacesType,
105     wordList& patchPhysicalTypes
108     dictionary patchDictionary;
110     {
111         IOobject patchEntriesHeader
112         (
113             "boundary",
114             meshInstance,
115             meshDir,
116             obr,
117             IOobject::MUST_READ,
118             IOobject::NO_WRITE,
119             false
120         );
122         if (patchEntriesHeader.headerOk())
123         {
124             // Create a list of entries from the boundary file.
125             polyBoundaryMeshEntries patchEntries(patchEntriesHeader);
127             forAll(patchEntries, patchi)
128             {
129                 patchDictionary.add(patchEntries[patchi]);
130             }
131         }
132     }
134     if (patchDictionary.size())
135     {
136         forAll(patchNames, patchi)
137         {
138             if (patchDictionary.found(patchNames[patchi]))
139             {
140                 const dictionary& patchDict =
141                     patchDictionary.subDict(patchNames[patchi]);
143                 patchDict.lookup("type") >> patchTypes[patchi];
145                 patchDict.readIfPresent("geometricType", patchTypes[patchi]);
146                 patchDict.readIfPresent
147                 (
148                     "physicalType",
149                     patchPhysicalTypes[patchi]
150                 );
151             }
152         }
154         if (patchDictionary.found(defaultFacesName))
155         {
156             const dictionary& patchDict =
157                 patchDictionary.subDict(defaultFacesName);
159             patchDict.readIfPresent("geometricType", defaultFacesType);
160         }
161     }
163     Info << nl << "Default patch type set to " << defaultFacesType << endl;
166 // ************************************************************************* //