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-------------------------------------------------------------------------------
11License
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
36template<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 (
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
72template<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
108template<class Type>
110{
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// ************************************************************************* //
Various functions to operate on Lists.
label n
Generic GeometricField class.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
const Type & finalResidual() const noexcept
Return final residual.
const labelType & nIterations() const noexcept
Return number of iterations.
bool converged() const noexcept
Has the solver converged?
const word & solverName() const noexcept
Return solver name.
const Type & initialResidual() const noexcept
Return initial residual.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:78
The TAB Method for Numerical Calculation of Spray Droplet Breakup.
Definition: TAB.H:69
T & first()
Return the first element of the list.
Definition: UListI.H:202
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:386
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
const fvMesh & mesh_
Reference to the fvMesh.
void updateSolverInfo(const word &fieldName)
Calculate the solver information.
void initialiseResidualField(const word &fieldName)
Initialise a residual field.
void writeFileHeader(Ostream &os)
Output file header information.
Definition: solverInfo.C:46
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:285
pTraits< Type >::labelType validComponents() const
Return a labelType of valid component indicators.
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
uint8_t direction
Definition: direction.H:56