Loading...
Searching...
No Matches
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 (
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 }
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 =
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 }
104 }
105 }
106}
107
108
109template<class Type>
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 Pair<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// ************************************************************************* //
Various functions to operate on Lists.
label n
Generic GeometricField class.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
An ordered pair of two objects of type <T> with first() and second() elements.
Definition Pair.H:66
const T & first() const noexcept
Access the first element.
Definition Pair.H:137
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:81
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
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
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
const fvMesh & mesh_
Reference to the fvMesh.
bool foundObject(const word &fieldName) const
Find object (eg, a field) in the (sub) objectRegistry.
void updateSolverInfo(const word &fieldName)
Calculate the solver information.
void createResidualField(const word &fieldName)
Create and store a residual field on the mesh database.
Definition solverInfo.C:73
void initialiseResidualField(const word &fieldName)
Initialise a residual field.
void writeFileHeader(Ostream &os)
Output file header information.
Definition solverInfo.C:39
void setResult(const word &entryName, const Type &value)
Add result.
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition writeFile.C:334
virtual OFstream & file()
Return access to the file (if only 1).
Definition writeFile.C:270
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
@ TAB
Tab [isspace].
Definition token.H:142
A class for handling words, derived from Foam::string.
Definition word.H:66
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:49