All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
regionSolvers.H
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) 2022-2023 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 Class
25  Foam::regionSolvers
26 
27 Description
28  Class to hold the lists of region meshes and solvers
29 
30  Also provides loop and iteration functionality which automatically set the
31  region Info prefix for each of the solvers returned by the '[]' operator or
32  iterator.
33 
34 Usage
35  Given the \c regionSolvers named solvers:
36  \verbatim
37  // Create the region meshes and solvers
38  regionSolvers solvers(runTime);
39  \endverbatim
40 
41  The list of solvers can be looped over:
42  \verbatim
43  forAll(solvers, i)
44  {
45  solvers[i].momentumPredictor();
46  }
47  \endverbatim
48  where the '[]' operator sets the region Info prefix. After the loop the
49  region Info prefix remains set to the last region prefix and so for global
50  messages, e.g. the global time-step the Info prefix must be specifically
51  reset to spaces by calling the \c setGlobalPrefix() function.
52 
53  Alternatively the list of solvers can be iterated over:
54  \verbatim
55  forAllIter(regionSolvers, solvers, solver)
56  {
57  solver->momentumPredictor();
58  }
59  \endverbatim
60  where the iterator increment sets the region \c Info prefix and at the end
61  automatically resets the \c Info prefix to spaces.
62 
63 SourceFiles
64  regionSolvers.C
65 
66 \*---------------------------------------------------------------------------*/
67 
68 #ifndef regionSolvers_H
69 #define regionSolvers_H
70 
71 #include "solver.H"
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
75 namespace Foam
76 {
77 
78 /*---------------------------------------------------------------------------*\
79  Class regionSolvers Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 class regionSolvers
83 {
84  // Private Member Data
85 
86  //- Region meshes
87  PtrList<fvMesh> regions_;
88 
89  //- Region solvers
90  PtrList<solver> solvers_;
91 
92  //- Global space padding prefix
93  string prefix0_;
94 
95  //- List of space padded region prefixes
96  stringList prefixes_;
97 
98 
99 public:
100 
101  // Constructors
102 
103  //- Construct from components
104  regionSolvers(const Time& runTime);
105 
106  //- Disallow default bitwise copy construction
107  regionSolvers(const regionSolvers&) = delete;
108 
109 
110  //- Destructor
111  ~regionSolvers();
112 
113 
114  // Member Functions
115 
116  //- Return the number of region solvers
117  inline label size() const;
118 
119  //- Set the Info prefix to space padding for global messages
120  void setGlobalPrefix() const;
121 
122  //- Set the Info prefix to the space padded region name
123  void setPrefix(const label i) const;
124 
125  //- Reset the Info prefix to null
126  void resetPrefix() const;
127 
128 
129  // Iterator
130 
131  class iterator;
132  friend class iterator;
133 
134  // Iterator class to loop over the solvers, setting the prefix for each
135  class iterator
136  {
137  // Private Data
138 
139  //- Reference to the regionSolvers
140  regionSolvers& regionSolvers_;
141 
142  //- Current solver index
143  label index_;
144 
145  public:
146 
147  friend class regionSolvers;
148 
149  // Constructors
150 
151  //- Construct for the regionSolvers
152  inline explicit iterator(regionSolvers&);
153 
154  // Member Operators
155 
156  inline bool operator==(const iterator&) const;
157  inline bool operator!=(const iterator&) const;
158 
159  inline solver& operator*();
160  inline solver& operator()();
161  inline solver* operator->();
162 
163  inline iterator operator++();
164  inline iterator operator++(int);
165  };
166 
167  //- Return an iterator to begin traversing the solvers
168  inline iterator begin();
169 
170  //- Return an iterator to end traversing the solvers
171  inline iterator end();
172 
173 
174  // Member Operators
175 
176  //- Cast to the list of solvers
177  inline operator PtrList<solver>&();
178 
179  //- Set the region i prefix and return the corresponding solver
180  solver& operator[](const label i);
181 
182  //- Disallow default bitwise assignment
183  void operator=(const regionSolvers&) = delete;
184 };
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 #include "regionSolversI.H"
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #endif
197 
198 // ************************************************************************* //
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
bool operator!=(const iterator &) const
bool operator==(const iterator &) const
iterator(regionSolvers &)
Construct for the regionSolvers.
Class to hold the lists of region meshes and solvers.
Definition: regionSolvers.H:82
iterator begin()
Return an iterator to begin traversing the solvers.
label size() const
Return the number of region solvers.
regionSolvers(const Time &runTime)
Construct from components.
solver & operator[](const label i)
Set the region i prefix and return the corresponding solver.
void operator=(const regionSolvers &)=delete
Disallow default bitwise assignment.
~regionSolvers()
Destructor.
void setGlobalPrefix() const
Set the Info prefix to space padding for global messages.
void setPrefix(const label i) const
Set the Info prefix to the space padded region name.
iterator end()
Return an iterator to end traversing the solvers.
void resetPrefix() const
Reset the Info prefix to null.
Abstract base class for run-time selectable region solvers.
Definition: solver.H:56
Namespace for OpenFOAM.
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