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-2025 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 word& previousPrefix,
62  const label regioni,
63  Region& region
64 )
65 :
66  mrr_(*reinterpret_cast<const MultiRegionRefs<Region>*>(&mrr)),
67  previousPrefix_(previousPrefix),
68  regioni_(regioni),
69  region_(region)
70 {
71  if (mrr_.prefixes() && regioni_ != -1)
72  {
73  const string::size_type dn =
74  mrr_.prefixWidth()
75  - regionName(mrr_.regions_[regioni]).size();
76 
77  Sout.prefix() =
78  regionName(mrr_.regions_[regioni]) + string(dn, ' ');
79  }
80 }
81 
82 
83 template<class Region>
85 :
86  RegionRef(rp.mrr_, rp.previousPrefix_, rp.regioni_, rp.region_)
87 {
88  rp.regioni_ = -1;
89 }
90 
91 
92 template<class Region>
94 :
95  regions_(regions),
96  previousPrefix_(Sout.prefix()),
97  indices_()
98 {
99  forAll(regions, regioni)
100  {
101  indices_.insert(regionName(regions_[regioni]), regioni);
102  }
103 
104  if (prefixes())
105  {
106  Sout.prefix() = string(prefixWidth(), ' ');
107  }
108  else
109  {
110  Sout.prefix() = word::null;
111  }
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
116 
117 template<class Region>
119 {
120  if (mrr_.prefixes() && regioni_ != -1)
121  {
122  Sout.prefix() = previousPrefix_;
123  }
124 }
125 
126 
127 template<class Region>
129 {
130  Sout.prefix() = previousPrefix_;
131 }
132 
133 
134 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
135 
136 template<class Region>
138 {
139  return regions_.size();
140 }
141 
142 
143 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
144 
145 template<class Region>
147 {
148  return region_;
149 }
150 
151 
152 template<class Region>
154 {
155  return region_;
156 }
157 
158 
159 template<class Region>
161 (
162  const label regioni
163 ) const
164 {
165  return
167  (
168  *this,
169  Sout.prefix(),
170  regioni,
171  regions_[regioni]
172  );
173 }
174 
175 
176 template<class Region>
178 (
179  const label regioni
180 )
181 {
182  return
184  (
185  *this,
186  Sout.prefix(),
187  regioni,
188  regions_[regioni]
189  );
190 }
191 
192 
193 template<class Region>
195 (
196  const word& regionName
197 ) const
198 {
199  return operator[](indices_[regionName]);
200 }
201 
202 
203 template<class Region>
205 (
206  const word& regionName
207 )
208 {
209  return operator[](indices_[regionName]);
210 }
211 
212 
213 // ************************************************************************* //
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:449
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.
RegionRef(const MultiRegionRefs< NonConstRegion > &mrr, const word &previousPrefix, const label regioni, Region &region)
Construct form components.
Region & operator()() const
Obtain the reference.
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:63
static const word null
An empty word.
Definition: word.H:78
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:218
const fvMesh & region(const dictionary &dict)
Cast the give dictionary to the corresponding region fvMesh.
Definition: fvMesh.C:1831
prefixOSstream Sout(cout, "Sout")
Definition: IOstreams.H:51
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Foam::word regionName
Definition: setRegionName.H:1