Residuals.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) 2019-2022 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 "Residuals.H"
27 #include "Time.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 :
35  <
36  polyMesh,
38  Residuals<Type>
39  >(mesh),
40  prevTimeIndex_(-1)
41 {}
42 
43 
44 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
45 
46 template<class Type>
48 {
50  <
51  polyMesh,
54  >::New
55  (
56  mesh
57  ).HashTable<DynamicList<SolverPerformance<Type>>>::toc();
58 }
59 
60 
61 template<class Type>
62 bool Foam::Residuals<Type>::found(const polyMesh& mesh, const word& fieldName)
63 {
65  <
66  polyMesh,
69  >::New
70  (
71  mesh
72  ).HashTable<DynamicList<SolverPerformance<Type>>>::found(fieldName);
73 }
74 
75 
76 template<class Type>
79 (
80  const polyMesh& mesh,
81  const word& fieldName
82 )
83 {
85  <
86  polyMesh,
89  >::New
90  (
91  mesh
92  )[fieldName];
93 }
94 
95 
96 template<class Type>
98 (
99  const polyMesh& mesh,
100  const SolverPerformance<Type>& sp
101 )
102 {
103  Residuals<Type>& residuals = const_cast<Residuals<Type>&>
104  (
106  <
107  polyMesh,
110  >::New
111  (
112  mesh
113  )
114  );
115 
117 
118  const label timeIndex =
119  mesh.time().subCycling()
120  ? mesh.time().prevTimeState().timeIndex()
121  : mesh.time().timeIndex();
122 
123  if (residuals.prevTimeIndex_ != timeIndex)
124  {
125  // Reset solver performance between iterations
126  residuals.prevTimeIndex_ = timeIndex;
127  table.clear();
128  }
129 
130  if (table.found(sp.fieldName()))
131  {
132  table[sp.fieldName()].append(sp);
133  }
134  else
135  {
136  table.insert
137  (
138  sp.fieldName(),
140  );
141  }
142 }
143 
144 
145 // ************************************************************************* //
bool found
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
An STL-conforming hash table.
Definition: HashTable.H:127
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
void clear()
Clear all entries from table.
Definition: HashTable.C:468
DemandDrivenMeshObject to store the solver performance residuals of all the fields of the type it is ...
Definition: Residuals.H:61
static bool found(const polyMesh &mesh, const word &fieldName)
Return true if residuals for the given field are stored.
Definition: Residuals.C:62
static const DynamicList< SolverPerformance< Type > > & field(const polyMesh &mesh, const word &fieldName)
Return the list of solver performance residuals for the given field.
Definition: Residuals.C:79
Residuals(const polyMesh &mesh)
Construct for given mesh.
Definition: Residuals.C:32
static List< word > fieldNames(const polyMesh &mesh)
Return the list of field names of the particular type.
Definition: Residuals.C:47
static void append(const polyMesh &mesh, const SolverPerformance< Type > &)
Append the given solver performance residuals.
Definition: Residuals.C:98
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
const word & fieldName() const
Return field name.
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:28
const TimeState & prevTimeState() const
Return previous TimeState if time is being sub-cycled.
Definition: Time.H:440
bool subCycling() const
Return true if time currently being sub-cycled, otherwise false.
Definition: Time.H:434
const Time & time() const
Return time.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A class for handling words, derived from string.
Definition: word.H:62
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
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
label timeIndex
Definition: getTimeIndex.H:4