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 = mesh_.solverPerformanceDict();
83 
84  if (solverDict.found(fieldName))
85  {
86  typename pTraits<Type>::labelType validComponents
87  (
88  mesh_.validComponents<Type>()
89  );
90 
91  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; ++cmpt)
92  {
93  if (component(validComponents, cmpt) != -1)
94  {
95  const word resultName
96  (
97  fieldName + word(pTraits<Type>::componentNames[cmpt])
98  );
99 
100  createResidualField(resultName);
101  }
102  }
103  }
104  }
105 }
106 
107 
108 template<class Type>
109 void Foam::functionObjects::solverInfo::updateSolverInfo(const word& fieldName)
110 {
111  typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
112  typedef typename pTraits<Type>::labelType labelType;
113 
114  if (foundObject<volFieldType>(fieldName))
115  {
116  const Foam::dictionary& solverDict = mesh_.solverPerformanceDict();
117 
118  if (solverDict.found(fieldName))
119  {
120  const List<SolverPerformance<Type>> sp
121  (
122  solverDict.lookup(fieldName)
123  );
124 
125  const SolverPerformance<Type>& sp0 = sp.first();
126  const word& solverName = sp0.solverName();
127  const Type& initialResidual = sp0.initialResidual();
128  const Type& finalResidual = sp0.finalResidual();
129  const labelType nIterations = sp0.nIterations();
130  const Switch converged(sp0.converged());
131 
132  const labelType validComponents(mesh_.validComponents<Type>());
133 
134  file() << token::TAB << solverName;
135 
136  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; ++cmpt)
137  {
138  if (component(validComponents, cmpt) != -1)
139  {
140  const scalar ri = component(initialResidual, cmpt);
141  const scalar rf = component(finalResidual, cmpt);
142  const label n = component(nIterations, cmpt);
143 
144  file()
145  << token::TAB << ri
146  << token::TAB << rf
147  << token::TAB << n;
148 
149  const word cmptName(pTraits<Type>::componentNames[cmpt]);
150  const word resultName(fieldName + cmptName);
151  setResult(resultName + "_initial", ri);
152  setResult(resultName + "_final", rf);
153  setResult(resultName + "_iters", n);
154  }
155  }
156 
157  file() << token::TAB << converged;
158  }
159  }
160 }
161 
162 
163 // ************************************************************************* //
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:379
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:120
Tab [isspace].
Definition: token.H:126
A traits class, which is primarily used for primitives.
Definition: pTraits.H:50
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
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:100
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:55
OBJstream os(runTime.globalPath()/outputName)
label n
T * first()
The first entry in the list.
Definition: UILList.H:544
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