convergenceControlTemplates.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) 2018-2019 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 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class ResidualData>
32 (
33  const word& fieldName,
34  const List<ResidualData>& residualControl,
35  const bool useRegEx
36 )
37 {
38  forAll(residualControl, i)
39  {
40  if (useRegEx && residualControl[i].name.match(fieldName))
41  {
42  return i;
43  }
44  else if (residualControl[i].name == fieldName)
45  {
46  return i;
47  }
48  }
49 
50  return -1;
51 }
52 
53 
54 template<class Type>
56 (
57  const fvMesh& mesh,
58  DynamicList<word>& fieldNames
59 )
60 {
61  fieldNames.append(Residuals<Type>::fieldNames(mesh));
62 }
63 
64 
65 template<class Type>
67 (
68  const fvMesh& mesh,
69  const word& fieldName,
70  const label solvei,
71  scalar& r0,
72  scalar& r
73 )
74 {
76 
77  if (mesh.foundObject<fieldType>(fieldName))
78  {
80  (
81  Residuals<Type>::field(mesh, fieldName)
82  );
83 
84  r0 = cmptMax(sp[0].initialResidual());
85  r = cmptMax(sp[solvei].initialResidual());
86  }
87 }
88 
89 
90 // ************************************************************************* //
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
bool foundObject(const word &name) const
Is the named Type found?
Generic GeometricField class.
static void getFieldTypeNames(const fvMesh &mesh, DynamicList< word > &fieldNames)
Append the of names of the fields of this Type to the given list.
bool match(const std::string &) const
True when strings match literally.
Definition: stringI.H:194
A class for handling words, derived from string.
Definition: word.H:59
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static label residualControlIndex(const word &fieldName, const List< ResidualData > &residualControl, const bool useRegEx=true)
Return the index of the named field in residual control data, or -1.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
static void getInitialTypeResiduals(const fvMesh &mesh, const word &fieldName, const label solvei, scalar &r0, scalar &r)
Get the initial residuals for the first and the i-th solves in this.
MeshObject to store the solver performance residuals of all the fields of the type it is instantiated...
Definition: Residuals.H:52