regionSolvers.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) 2022-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 "regionSolvers.H"
27 #include "solver.H"
28 #include "Time.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 Foam::regionSolvers::regionSolvers(const Time& runTime)
33 {
34  List<Pair<word>> regionSolverNames;
35 
36  if (runTime.controlDict().found("regionSolvers"))
37  {
38  const dictionary& regionSolversDict =
39  runTime.controlDict().subDict("regionSolvers");
40 
41  forAllConstIter(dictionary, regionSolversDict, iter)
42  {
43  const word regionName(iter().keyword());
44  const word solverName(iter().stream());
45 
46  regionSolverNames.append(Pair<word>(regionName, solverName));
47  }
48  }
49  else
50  {
51  // Partial backward-compatibility
52  // Converts the regions entry in the regionProperties dictionary into
53  // the regionSolvers list
54  // Only supports fluid and solid regions
55 
56  typeIOobject<IOdictionary> regionPropertiesHeader
57  (
58  IOobject
59  (
60  "regionProperties",
61  runTime.time().constant(),
62  runTime.db(),
64  )
65  );
66 
67  if (regionPropertiesHeader.headerOk())
68  {
69  HashTable<wordList> regions
70  (
71  IOdictionary(regionPropertiesHeader).lookup("regions")
72  );
73 
74  if (regions.found("solid"))
75  {
76  const wordList& fluidRegions = regions["solid"];
77  forAll(fluidRegions, i)
78  {
79  regionSolverNames.append
80  (
81  Pair<word>(fluidRegions[i], "solid")
82  );
83  }
84  }
85 
86  if (regions.found("fluid"))
87  {
88  const wordList& fluidRegions = regions["fluid"];
89  forAll(fluidRegions, i)
90  {
91  regionSolverNames.append
92  (
93  Pair<word>(fluidRegions[i], "fluid")
94  );
95  }
96  }
97  }
98  else
99  {
100  FatalIOErrorInFunction(runTime.controlDict())
101  << "regionSolvers list missing from "
102  << runTime.controlDict().name()
103  << exit(FatalIOError);
104  }
105  }
106 
107  regions_.setSize(regionSolverNames.size());
108  solvers_.setSize(regionSolverNames.size());
109  prefixes_.setSize(regionSolverNames.size());
110 
111  string::size_type nRegionNameChars = 0;
112 
113  // Load the solver libraries
114  forAll(regionSolverNames, i)
115  {
116  const word& solverName = regionSolverNames[i].second();
117 
118  solver::load(solverName);
119  }
120 
121  // Construct the region meshes
122  forAll(regionSolverNames, i)
123  {
124  const word& regionName = regionSolverNames[i].first();
125 
126  regions_.set
127  (
128  i,
129  new fvMesh
130  (
131  IOobject
132  (
133  regionName,
134  runTime.name(),
135  runTime,
137  ),
138  false
139  )
140  );
141  }
142 
143  forAll(regions_, i)
144  {
145  regions_[i].postConstruct(true, fvMesh::stitchType::geometric);
146  }
147 
148  // Select the solvers
149  forAll(regionSolverNames, i)
150  {
151  const word& regionName = regionSolverNames[i].first();
152  const word& solverName = regionSolverNames[i].second();
153 
154  solvers_.set(i, solver::New(solverName, regions_[i]));
155 
156  prefixes_[i] = regionName;
157  nRegionNameChars = max(nRegionNameChars, regionName.size());
158  }
159 
160  nRegionNameChars++;
161 
162  prefix0_.append(nRegionNameChars, ' ');
163 
164  forAll(regionSolverNames, i)
165  {
166  prefixes_[i].append(nRegionNameChars - prefixes_[i].size(), ' ');
167  }
168 }
169 
170 
171 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
172 
174 {}
175 
176 
177 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
178 
180 {
181  Sout.prefix() = prefix0_;
182 }
183 
184 
185 void Foam::regionSolvers::setPrefix(const label i) const
186 {
187  Sout.prefix() = prefixes_[i];
188 }
189 
190 
192 {
194 }
195 
196 
197 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
198 
200 {
201  setPrefix(i);
202  return solvers_[i];
203 }
204 
205 
206 // ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
void setSize(const label)
Reset size of List.
Definition: List.C:281
const string & prefix() const
Return the prefix of the stream.
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.
~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.
void resetPrefix() const
Reset the Info prefix to null.
Abstract base class for run-time selectable region solvers.
Definition: solver.H:56
static autoPtr< solver > New(const word &solverName, fvMesh &mesh)
Select, construct and return the solver.
Definition: solverNew.C:37
static void load(const word &solverName)
Load the specified solver library.
Definition: solverNew.C:30
static const string null
An empty string.
Definition: string.H:88
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
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)
IOerror FatalIOError
prefixOSstream Sout(cout, "Sout")
Definition: IOstreams.H:51