Loading...
Searching...
No Matches
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-2023 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 * * * * * * * * * * * * * * //
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.
39static Ostream& printMaps(Ostream& os, const labelListList& maps)
40{
41 if (os.format() == IOstreamOption::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() == IOstreamOption::BINARY || maps.empty())
65 {
66 os.writeEntry(key, maps);
67 }
68 else
69 {
70 os << indent << key;
71 printMaps(os, maps);
72 os.endEntry();
73 }
75
76} // End namespace Foam
77
78
79// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80
82(
83 const dictionary& dict,
84 const label comm
85)
90}
91
92
95 is >> *this;
96}
97
98
99// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
100
102{
103 constructSize_ = dict.get<label>("constructSize");
104
105 // The subMap
106 {
107 const dictionary& subdict = dict.subDict("subMap");
108
109 subdict.readEntry("flip", subHasFlip_);
110 subdict.readEntry("maps", subMap_);
111 }
112
113 // The constructMap
114 {
115 const dictionary& subdict = dict.subDict("constructMap");
117 subdict.readEntry("flip", constructHasFlip_);
118 subdict.readEntry("maps", constructMap_);
119 }
120}
121
122
123void Foam::mapDistributeBase::writeEntries(Ostream& os) const
124{
125 os.writeEntry("constructSize", constructSize_);
126
127 os << nl;
128 os.beginBlock("subMap");
129 os.writeEntry("flip", subHasFlip_);
130 writeMaps(os, "maps", subMap_);
131 os.endBlock();
132
133 os << nl;
134 os.beginBlock("constructMap");
135 os.writeEntry("flip", constructHasFlip_);
136 writeMaps(os, "maps", constructMap_);
137 os.endBlock();
138}
139
140
141// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
142
143Foam::Istream& Foam::operator>>(Istream& is, mapDistributeBase& map)
144{
146
147 is >> map.constructSize_
148 >> map.subMap_ >> map.constructMap_
149 >> map.subHasFlip_ >> map.constructHasFlip_
150 >> map.comm_;
151
152 return is;
153}
154
155
156Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributeBase& map)
157{
158 os << map.constructSize_ << token::NL;
159
160 printMaps(os, map.subMap_) << token::NL;
161 printMaps(os, map.constructMap_) << token::NL;
162
163 os << map.subHasFlip_ << token::SPACE
164 << map.constructHasFlip_ << token::SPACE
165 << map.comm_ << token::NL;
166
167 return os;
168}
169
170
171template<>
172Foam::Ostream& Foam::operator<<
173(
174 Ostream& os,
175 const InfoProxy<mapDistributeBase>& iproxy
176)
177{
178 const auto& map = *iproxy;
179
180 // Output as compact pseudo dictionary entries
181
182 os.writeEntry("constructSize", map.constructSize());
183
184 os << indent << "local { flip " << map.subHasFlip()
185 << "; sizes ";
186 map.subMapSizes().writeList(os) << "; }" << nl;
187
188 os << indent << "remote { flip " << map.constructHasFlip()
189 << "; sizes ";
190 map.constructMapSizes().writeList(os) << "; }" << nl;
191
192 return os;
193}
194
195
196// ************************************************************************* //
streamFormat format() const noexcept
Get the current stream format.
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:51
A helper class for outputting values to Ostream.
Definition InfoProxy.H:49
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition Ostream.H:331
virtual Ostream & endEntry()
Write end entry (';') followed by newline.
Definition Ostream.C:117
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
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,...
Class containing processor-to-processor mapping information.
mapDistributeBase() noexcept
Default construct (uses worldComm).
void readDict(const dictionary &dict)
Read entries from dictionary format.
void writeEntries(Ostream &os) const
Write entries in dictionary format.
label comm() const noexcept
The communicator used.
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
@ SPACE
Space [isspace].
Definition token.H:144
@ NL
Newline [isspace].
Definition token.H:143
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
Namespace for OpenFOAM.
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
static Ostream & printMaps(Ostream &os, const labelListList &maps)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Ostream & indent(Ostream &os)
Indent stream.
Definition Ostream.H:481
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:50
dictionary dict