mapDistributeBaseIO.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-------------------------------------------------------------------------------
10License
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 "mapDistributeBase.H"
29#include "dictionary.H"
30
31// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
32
33namespace Foam
34{
35
36// The maps (labelListList) are not human-modifiable but if we need to
37// inspect them in ASCII, it is much more convenient if each sub-list
38// is flattened on a single line.
40{
41 if (os.format() == IOstream::BINARY || maps.empty())
42 {
43 os << maps;
44 }
45 else
46 {
47 os << nl << maps.size() << nl
49
50 // Compact single-line output for each labelList
51 for (const labelList& map : maps)
52 {
53 map.writeList(os) << nl;
54 }
56 }
57
58 return os;
59}
60
61
62static void writeMaps(Ostream& os, const word& key, const labelListList& maps)
63{
64 if (os.format() == IOstream::BINARY || maps.empty())
65 {
66 os.writeEntry(key, maps);
67 }
68 else
69 {
70 os << indent << key;
72 }
73}
74
75} // End namespace Foam
76
77
78// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79
81(
82 const dictionary& dict,
83 const label comm
84)
85:
87{
88 mapDistributeBase::readDict(dict);
89}
90
91
93{
94 is >> *this;
95}
96
97
98// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
99
101{
102 constructSize_ = dict.get<label>("constructSize");
103
104 // The subMap
105 {
106 const dictionary& subdict = dict.subDict("subMap");
107
108 subdict.readEntry("flip", subHasFlip_);
109 subdict.readEntry("maps", subMap_);
110 }
111
112 // The constructMap
113 {
114 const dictionary& subdict = dict.subDict("constructMap");
115
116 subdict.readEntry("flip", constructHasFlip_);
117 subdict.readEntry("maps", constructMap_);
118 }
119}
120
121
123{
124 os.writeEntry("constructSize", constructSize_);
125
126 os << nl;
127 os.beginBlock("subMap");
128 os.writeEntry("flip", subHasFlip_);
129 writeMaps(os, "maps", subMap_);
130 os.endBlock();
131
132 os << nl;
133 os.beginBlock("constructMap");
134 os.writeEntry("flip", constructHasFlip_);
135 writeMaps(os, "maps", constructMap_);
136 os.endBlock();
137}
138
139
140// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
141
143{
145
146 is >> map.constructSize_
147 >> map.subMap_ >> map.constructMap_
148 >> map.subHasFlip_ >> map.constructHasFlip_
149 >> map.comm_;
150
151 return is;
152}
153
154
156{
157 os << map.constructSize_ << token::NL;
158
159 printMaps(os, map.subMap_) << token::NL;
160 printMaps(os, map.constructMap_) << token::NL;
161
162 os << map.subHasFlip_ << token::SPACE
163 << map.constructHasFlip_ << token::SPACE
164 << map.comm_ << token::NL;
165
166 return os;
167}
168
169
170template<>
171Foam::Ostream& Foam::operator<<
172(
173 Ostream& os,
175)
176{
177 const auto& map = ip.t_;
178
179 // Output as compact pseudo dictionary entries
180
181 os.writeEntry("constructSize", map.constructSize());
182
183 os << indent << "local { flip " << map.subHasFlip()
184 << "; sizes ";
185 map.subMapSizes().writeList(os) << "; }" << nl;
186
187 os << indent << "remote { flip " << map.constructHasFlip()
188 << "; sizes ";
189 map.constructMapSizes().writeList(os) << "; }" << nl;
190
191 return os;
192}
193
194
195// ************************************************************************* //
streamFormat format() const noexcept
Get the current stream format.
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:105
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:87
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Class containing processor-to-processor mapping information.
mapDistributeBase()
Default construct (uses worldComm)
void readDict(const dictionary &dict)
Read entries from dictionary format.
void writeEntries(Ostream &os) const
Write entries in dictionary format.
@ END_STATEMENT
End entry [isseparator].
Definition: token.H:154
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
@ NL
Newline [isspace].
Definition: token.H:124
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Namespace for OpenFOAM.
static Ostream & printMaps(Ostream &os, const labelListList &maps)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
static void writeMaps(Ostream &os, const word &key, const labelListList &maps)
Istream & operator>>(Istream &, directionInfo &)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict