mapDistributePolyMeshIO.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) 2022 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 "mapDistributePolyMesh.H"
29 #include "dictionary.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 (
35  const dictionary& dict,
36  const label comm
37 )
38 :
40 {
41  mapDistributePolyMesh::readDict(dict);
42 }
43 
44 
46 {
47  is >> *this;
48 }
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
54 {
55  // Cell information
56  {
57  const dictionary& subdict = dict.subDict("cellMap");
58 
59  subdict.readEntry("oldSize", nOldCells_);
60  cellMap_.readDict(subdict);
61  }
62 
63  // Face information
64  {
65  const dictionary& subdict = dict.subDict("faceMap");
66 
67  subdict.readEntry("oldSize", nOldFaces_);
68  faceMap_.readDict(subdict);
69  }
70 
71  // Point information
72  {
73  const dictionary& subdict = dict.subDict("pointMap");
74 
75  subdict.readEntry("oldSize", nOldPoints_);
76  pointMap_.readDict(subdict);
77  }
78 
79  // Patch information
80  {
81  const dictionary& subdict = dict.subDict("patchMap");
82 
83  subdict.readEntry("oldSizes", oldPatchSizes_);
84  subdict.readEntry("oldStarts", oldPatchStarts_);
85  subdict.readEntry("oldPointSizes", oldPatchNMeshPoints_);
86  patchMap_.readDict(subdict);
87  }
88 }
89 
90 
92 {
93  os.beginBlock("cellMap");
94  os.writeEntry("oldSize", nOldCells_);
95  cellMap_.writeEntries(os);
96  os.endBlock();
97 }
98 
99 
101 {
102  os.beginBlock("faceMap");
103  os.writeEntry("oldSize", nOldFaces_);
104  faceMap_.writeEntries(os);
105  os.endBlock();
106 }
107 
108 
110 {
111  os.beginBlock("pointMap");
112  os.writeEntry("oldSize", nOldPoints_);
113  pointMap_.writeEntries(os);
114  os.endBlock();
115 }
116 
117 
119 {
120  os.beginBlock("patchMap");
121  oldPatchSizes_.writeEntry("oldSizes", os);
122  oldPatchStarts_.writeEntry("oldStarts", os);
123  oldPatchNMeshPoints_.writeEntry("oldPointSizes", os);
124  patchMap_.writeEntries(os);
125  os.endBlock();
126 }
127 
128 
130 {
131  writeCellMapEntries(os);
132 
133  os << nl;
134  writeFaceMapEntries(os);
135 
136  os << nl;
137  writePointMapEntries(os);
138 
139  os << nl;
140  writePatchMapEntries(os);
141 }
142 
143 
144 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
145 
146 Foam::Istream& Foam::operator>>(Istream& is, mapDistributePolyMesh& map)
147 {
149 
150  is >> map.nOldPoints_
151  >> map.nOldFaces_
152  >> map.nOldCells_
153 
154  >> map.oldPatchSizes_
155  >> map.oldPatchStarts_
156  >> map.oldPatchNMeshPoints_
157 
158  >> map.pointMap_
159  >> map.faceMap_
160  >> map.cellMap_
161  >> map.patchMap_;
162 
163  return is;
164 }
165 
166 
167 Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributePolyMesh& map)
168 {
169  os << map.nOldPoints_ << token::SPACE
170  << map.nOldFaces_ << token::SPACE
171  << map.nOldCells_ << token::NL
172 
173  << map.oldPatchSizes_ << token::NL
174  << map.oldPatchStarts_ << token::NL
175  << map.oldPatchNMeshPoints_ << token::NL
176 
177  << map.pointMap_ << token::NL
178  << map.faceMap_ << token::NL
179  << map.cellMap_ << token::NL
180  << map.patchMap_;
181 
182  return os;
183 }
184 
185 
186 template<>
187 Foam::Ostream& Foam::operator<<
188 (
189  Ostream& os,
190  const InfoProxy<mapDistributePolyMesh>& iproxy
191 )
192 {
193  const auto& map = *iproxy;
194 
195  os.beginBlock("cellMap");
196  os.writeEntry("oldSize", map.nOldCells());
197  os << map.cellMap().info();
198  os.endBlock();
199 
200  os.beginBlock("faceMap");
201  os.writeEntry("oldSize", map.nOldFaces());
202  os << map.faceMap().info();
203  os.endBlock();
204 
205  os.beginBlock("pointMap");
206  os.writeEntry("oldSize", map.nOldPoints());
207  os << map.pointMap().info();
208  os.endBlock();
209 
210  return os;
211 }
212 
213 
214 // ************************************************************************* //
dictionary dict
void writePointMapEntries(Ostream &os) const
Write pointMap entries in dictionary format.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void writeEntries(Ostream &os) const
Write all map entries in dictionary format.
Newline [isspace].
Definition: token.H:130
InfoProxy< IOstream > info() const noexcept
Return info proxy, used to print IOstream information to a stream.
Definition: IOstream.H:517
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
mapDistributePolyMesh()
Default construct - uses worldComm.
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...
void writeCellMapEntries(Ostream &os) const
Write cellMap in dictionary format.
Istream & operator>>(Istream &, directionInfo &)
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:108
Space [isspace].
Definition: token.H:131
void writeFaceMapEntries(Ostream &os) const
Write faceMap in dictionary format.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
void writePatchMapEntries(Ostream &os) const
Write patchMap in dictionary format.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:90
void readDict(const dictionary &dict)
Read entries from dictionary format.