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>
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  {
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 // ************************************************************************* //
volFields.H
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:77
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
solverInfo.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:236
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Foam::functionObjects::solverInfo::initialiseResidualField
void initialiseResidualField(const word &fieldName)
Initialise a residual field.
Definition: solverInfoTemplates.C:74
Foam::functionObjects::solverInfo::updateSolverInfo
void updateSolverInfo(const word &fieldName)
Calculate the solver information.
Definition: solverInfoTemplates.C:109
zeroGradientFvPatchField.H
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::fvMesh::validComponents
pTraits< Type >::labelType validComponents() const
Return a labelType of valid component indicators.
Foam::data::solverPerformanceDict
const dictionary & solverPerformanceDict() const
Definition: data.C:78
Foam::dictionary::lookup
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:386
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::functionObjects::solverInfo::writeFileHeader
void writeFileHeader(Ostream &os)
Output file header information.
Definition: solverInfo.C:46
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::token::TAB
Tab [isspace].
Definition: token.H:123
Foam::functionObjects::fvMeshFunctionObject::mesh_
const fvMesh & mesh_
Reference to the fvMesh.
Definition: fvMeshFunctionObject.H:73
Foam::direction
uint8_t direction
Definition: direction.H:52
ListOps.H
Various functions to operate on Lists.
Foam::functionObjects::stateFunctionObject::setResult
void setResult(const word &entryName, const Type &value)
Add result.
Definition: stateFunctionObjectTemplates.C:108
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::SolverPerformance
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
Definition: SolverPerformance.H:52