residualsTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2015-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "residuals.H"
27 #include "volFields.H"
28 #include "Residuals.H"
29 #include "ListOps.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 {
36  if (obr_.foundObject<VolField<Type>>(fieldName))
37  {
38  typename pTraits<Type>::labelType validComponents
39  (
40  mesh_.validComponents<Type>()
41  );
42 
43  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
44  {
45  if (component(validComponents, cmpt) != -1)
46  {
48  (
49  file(),
50  fieldName + word(pTraits<Type>::componentNames[cmpt])
51  );
52  }
53  }
54  }
55 }
56 
57 
58 template<class Type>
60 {
61  if (obr_.foundObject<VolField<Type>>(fieldName))
62  {
63  typename pTraits<Type>::labelType validComponents
64  (
65  mesh_.validComponents<Type>()
66  );
67 
68  if
69  (
70  mesh_.foundObject<Residuals<Type>>(Residuals<Type>::typeName)
71  && Residuals<Type>::found(mesh_, fieldName)
72  )
73  {
75  (
76  Residuals<Type>::field(mesh_, fieldName)
77  );
78 
79  const Type& residual = sp.first().initialResidual();
80 
81  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
82  {
83  if (component(validComponents, cmpt) != -1)
84  {
85  file() << tab << component(residual, cmpt);
86  }
87  }
88  }
89  else
90  {
91  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
92  {
93  if (component(validComponents, cmpt) != -1)
94  {
95  writeTabbed(file(), "N/A");
96  }
97  }
98  }
99  }
100 }
101 
102 
103 // ************************************************************************* //
Various functions to operate on Lists.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
Generic GeometricField class.
DemandDrivenMeshObject to store the solver performance residuals of all the fields of the type it is ...
Definition: Residuals.H:61
T & first()
Return the first element of the list.
Definition: UListI.H:114
const fvMesh & mesh_
Reference to the fvMesh.
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:113
const objectRegistry & obr_
Reference to the objectRegistry.
void writeResidual(const word &fieldName)
Calculate the field min/max.
void writeFileHeader(const word &fieldName)
Output field header information.
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:121
pTraits< Type >::labelType validComponents() const
Return a labelType of valid component indicators.
bool foundObject(const word &name) const
Is the named Type in registry.
Traits class for primitives.
Definition: pTraits.H:53
A class for handling words, derived from string.
Definition: word.H:62
static const char tab
Definition: Ostream.H:266
void component(LagrangianPatchField< typename LagrangianPatchField< Type >::cmptType > &sf, const LagrangianPatchField< Type > &f, const direction d)
uint8_t direction
Definition: direction.H:45