All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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  prevTimeIndex_(-1)
36 {}
37 
38 
39 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
40 
41 template<class Type>
43 {
45  (
46  mesh
48 }
49 
50 
51 template<class Type>
52 bool Foam::Residuals<Type>::found(const polyMesh& mesh, const word& fieldName)
53 {
55  (
56  mesh
57  ).HashTable<DynamicList<SolverPerformance<Type>>>::found(fieldName);
58 }
59 
60 
61 template<class Type>
64 (
65  const polyMesh& mesh,
66  const word& fieldName
67 )
68 {
70  (
71  mesh
72  )[fieldName];
73 }
74 
75 
76 template<class Type>
78 (
79  const polyMesh& mesh,
80  const SolverPerformance<Type>& sp
81 )
82 {
83  Residuals<Type>& residuals = const_cast<Residuals<Type>&>
84  (
86  (
87  mesh
88  )
89  );
90 
92 
93  const label timeIndex =
94  mesh.time().subCycling()
95  ? mesh.time().prevTimeState().timeIndex()
96  : mesh.time().timeIndex();
97 
98  if (residuals.prevTimeIndex_ != timeIndex)
99  {
100  // Reset solver performance between iterations
101  residuals.prevTimeIndex_ = timeIndex;
102  table.clear();
103  }
104 
105  if (table.found(sp.fieldName()))
106  {
107  table[sp.fieldName()].append(sp);
108  }
109  else
110  {
111  table.insert
112  (
113  sp.fieldName(),
115  );
116  }
117 }
118 
119 
120 // ************************************************************************* //
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 & fieldName() const
Return field name.
static void append(const polyMesh &mesh, const SolverPerformance< Type > &)
Append the given solver performance residuals.
Definition: Residuals.C:78
bool subCycling() const
Return true if time currently being sub-cycled, otherwise false.
Definition: Time.H:415
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:64
const TimeState & prevTimeState() const
Return previous TimeState if time is being sub-cycled.
Definition: Time.H:421
static const Residuals< Type > & New(const polyMesh &mesh)
Definition: MeshObject.C:44
static bool found(const polyMesh &mesh, const word &fieldName)
Return true if residuals for the given field are stored.
Definition: Residuals.C:52
bool insert(const word &, const DynamicList< SolverPerformance< Type > > &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:86
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
A class for handling words, derived from string.
Definition: word.H:59
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics...
An STL-conforming hash table.
Definition: HashTable.H:61
const Time & time() const
Return time.
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
label timeIndex
Definition: getTimeIndex.H:4
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< word > toc() const
Return the table of contents.
Definition: HashTable.C:202
static void clear(objectRegistry &)
Definition: MeshObject.C:463
static List< word > fieldNames(const polyMesh &mesh)
Return the list of field names of the particular type.
Definition: Residuals.C:42
Residuals(const polyMesh &mesh)
Construct for given mesh.
Definition: Residuals.C:32
MeshObject to store the solver performance residuals of all the fields of the type it is instantiated...
Definition: Residuals.H:52