MultiRegionRefs.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) 2023-2024 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 "MultiRegionRefs.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class Region>
32 {
33  return regions_.size() > 1;
34 }
35 
36 
37 template<class Region>
39 {
40  string::size_type n = 0;
41 
42  if (prefixes())
43  {
44  forAll(regions_, regioni)
45  {
46  n = max(n, regionName(regions_[regioni]).size() + 1);
47  }
48  }
49 
50  return n;
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
56 template<class Region>
57 template<class NonConstRegion>
59 (
61  const label regioni,
62  Region& region
63 )
64 :
65  mrr_(*reinterpret_cast<const MultiRegionRefs<Region>*>(&mrr)),
66  regioni_(regioni),
67  region_(region)
68 {
69  if (mrr_.prefixes() && regioni_ != -1)
70  {
71  const string::size_type dn =
72  mrr_.prefixWidth()
73  - regionName(mrr_.regions_[regioni]).size();
74 
75  Sout.prefix() =
76  regionName(mrr_.regions_[regioni]) + string(dn, ' ');
77  }
78 }
79 
80 
81 template<class Region>
83 :
84  RegionRef(rp.mrr_, rp.regioni_, rp.region_)
85 {
86  rp.regioni_ = -1;
87 }
88 
89 
90 template<class Region>
92 :
93  regions_(regions),
94  previousPrefix_(Sout.prefix()),
95  indices_()
96 {
97  forAll(regions, regioni)
98  {
99  indices_.insert(regionName(regions_[regioni]), regioni);
100  }
101 
102  if (prefixes())
103  {
104  Sout.prefix() = string(prefixWidth(), ' ');
105  }
106  else
107  {
108  Sout.prefix() = word::null;
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
114 
115 template<class Region>
117 {
118  if (mrr_.prefixes() && regioni_ != -1)
119  {
120  Sout.prefix() = string(mrr_.prefixWidth(), ' ');
121  }
122 }
123 
124 
125 template<class Region>
127 {
128  Sout.prefix() = previousPrefix_;
129 }
130 
131 
132 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
133 
134 template<class Region>
136 {
137  return regions_.size();
138 }
139 
140 
141 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
142 
143 template<class Region>
145 {
146  return region_;
147 }
148 
149 
150 template<class Region>
152 {
153  return region_;
154 }
155 
156 
157 template<class Region>
159 (
160  const label regioni
161 ) const
162 {
163  return RegionRef<const Region>(*this, regioni, regions_[regioni]);
164 }
165 
166 
167 template<class Region>
169 (
170  const label regioni
171 )
172 {
173  return RegionRef<Region>(*this, regioni, regions_[regioni]);
174 }
175 
176 
177 template<class Region>
179 (
180  const word& regionName
181 ) const
182 {
183  return operator[](indices_[regionName]);
184 }
185 
186 
187 template<class Region>
189 (
190  const word& regionName
191 )
192 {
193  return operator[](indices_[regionName]);
194 }
195 
196 
197 // ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Class to wrap a UPtrList of of region-associated objects (meshes, solvers, domainDecompositions,...
MultiRegionRefs(UPtrList< Region > &regions)
Construct from a list of region pointers.
label size() const
Return the size.
~MultiRegionRefs()
Destructor.
~RegionRef()
Destructor.
Region & operator()() const
Obtain the reference.
RegionRef(const MultiRegionRefs< NonConstRegion > &mrr, const label regioni, Region &region)
Construct form components.
const string & prefix() const
Return the prefix of the stream.
A class for handling character strings derived from std::string.
Definition: string.H:79
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
Foam::word regionName
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & regionName(const solver &region)
Definition: solver.H:209
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
prefixOSstream Sout(cout, "Sout")
Definition: IOstreams.H:51