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-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 \*---------------------------------------------------------------------------*/
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  forAll(regionSolverNames, i)
114  {
115  const word& regionName = regionSolverNames[i].first();
116  const word& solverName = regionSolverNames[i].second();
117 
118  // Load the solver library
119  solver::load(solverName);
120 
121  regions_.set
122  (
123  i,
124  new fvMesh
125  (
126  IOobject
127  (
128  regionName,
129  runTime.name(),
130  runTime,
132  )
133  )
134  );
135 
136  solvers_.set(i, solver::New(solverName, regions_[i]));
137 
138  prefixes_[i] = regionName;
139  nRegionNameChars = max(nRegionNameChars, regionName.size());
140  }
141 
142  nRegionNameChars++;
143 
144  prefix0_.append(nRegionNameChars, ' ');
145 
146  forAll(regionSolverNames, i)
147  {
148  prefixes_[i].append(nRegionNameChars - prefixes_[i].size(), ' ');
149  }
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
162 {
163  Sout.prefix() = prefix0_;
164 }
165 
166 
167 void Foam::regionSolvers::setPrefix(const label i) const
168 {
169  Sout.prefix() = prefixes_[i];
170 }
171 
172 
174 {
176 }
177 
178 
179 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
180 
182 {
183  setPrefix(i);
184  return solvers_[i];
185 }
186 
187 
188 // ************************************************************************* //
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:55
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
Foam::word regionName
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
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
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
IOerror FatalIOError
prefixOSstream Sout(cout, "Sout")
Definition: IOstreams.H:51