solverInfoTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "solverInfo.H"
30 #include "volFields.H"
31 #include "ListOps.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 template<class Type>
38 (
39  Ostream& os,
40  const word& fieldName
41 ) const
42 {
44 
45  if (foundObject<fieldType>(fieldName))
46  {
47  writeTabbed(os, fieldName + "_solver");
48 
49  typename pTraits<Type>::labelType validComponents
50  (
51  mesh_.validComponents<Type>()
52  );
53 
54  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; ++cmpt)
55  {
56  if (component(validComponents, cmpt) != -1)
57  {
58  const word cmptName(pTraits<Type>::componentNames[cmpt]);
59  const word fieldBase(fieldName + cmptName);
60 
61  writeTabbed(os, fieldBase + "_initial");
62  writeTabbed(os, fieldBase + "_final");
63  writeTabbed(os, fieldBase + "_iters");
64  }
65  }
66 
67  writeTabbed(os, fieldName + "_converged");
68  }
69 }
70 
71 
72 template<class Type>
74 (
75  const word& fieldName
76 )
77 {
79 
80  if (foundObject<volFieldType>(fieldName))
81  {
82  const Foam::dictionary& solverDict =
83  mesh_.data().solverPerformanceDict();
84 
85  if (solverDict.found(fieldName))
86  {
87  typename pTraits<Type>::labelType validComponents
88  (
89  mesh_.validComponents<Type>()
90  );
91 
92  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; ++cmpt)
93  {
94  if (component(validComponents, cmpt) != -1)
95  {
96  const word resultName
97  (
98  fieldName + word(pTraits<Type>::componentNames[cmpt])
99  );
100 
101  createResidualField(resultName);
102  }
103  }
104  }
105  }
106 }
107 
108 
109 template<class Type>
110 void Foam::functionObjects::solverInfo::updateSolverInfo(const word& fieldName)
111 {
112  typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
113  typedef typename pTraits<Type>::labelType labelType;
114 
115  if (foundObject<volFieldType>(fieldName))
116  {
117  const Foam::dictionary& solverDict =
118  mesh_.data().solverPerformanceDict();
119 
120  if (solverDict.found(fieldName))
121  {
122  const List<SolverPerformance<Type>> sp
123  (
124  solverDict.lookup(fieldName)
125  );
126 
127  const SolverPerformance<Type>& sp0 = sp.first();
128  const word& solverName = sp0.solverName();
129  const Type& initialResidual = sp0.initialResidual();
130  const Type& finalResidual = sp0.finalResidual();
131  const labelType nIterations = sp0.nIterations();
132  const Switch converged(sp0.converged());
133 
134  const labelType validComponents(mesh_.validComponents<Type>());
135 
136  file() << token::TAB << solverName;
137 
138  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; ++cmpt)
139  {
140  if (component(validComponents, cmpt) != -1)
141  {
142  const scalar ri = component(initialResidual, cmpt);
143  const scalar rf = component(finalResidual, cmpt);
144  const label n = component(nIterations, cmpt);
145 
146  file()
147  << token::TAB << ri
148  << token::TAB << rf
149  << token::TAB << n;
150 
151  const word cmptName(pTraits<Type>::componentNames[cmpt]);
152  const word resultName(fieldName + cmptName);
153  setResult(resultName + "_initial", ri);
154  setResult(resultName + "_final", rf);
155  setResult(resultName + "_iters", n);
156  }
157  }
158 
159  file() << token::TAB << converged;
160  }
161  }
162 }
163 
164 
165 // ************************************************************************* //
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream. ...
Definition: dictionary.C:367
uint8_t direction
Definition: direction.H:46
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Tab [isspace].
Definition: token.H:129
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
Various functions to operate on Lists.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
void writeFileHeader(Ostream &os)
Output file header information.
Definition: solverInfo.C:39
A class for handling words, derived from Foam::string.
Definition: word.H:63
void initialiseResidualField(const word &fieldName)
Initialise a residual field.
pTraits< Type >::labelType validComponents() const
Return a labelType of valid component indicators.
void updateSolverInfo(const word &fieldName)
Calculate the solver information.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
label n
T * first()
The first entry in the list.
Definition: UILList.H:542
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
const fvMesh & mesh_
Reference to the fvMesh.
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:329