equationInitialResidualConditionTemplates.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) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "fvMesh.H"
29 
30 template<class Type>
33 (
34  const fvMesh& mesh,
35  const dictionary& dict,
36  const word& fieldName,
37  const label componenti,
38  bool& canSet,
39  scalar& residual
40 ) const
41 {
43 
44  if (canSet && mesh.foundObject<volFieldType>(fieldName))
45  {
46  const List<SolverPerformance<Type>> sp(dict.lookup(fieldName));
47  const Type& allComponents = sp.first().initialResidual();
48 
49  if (componenti != -1)
50  {
51  if (componenti > pTraits<Type>::nComponents - 1)
52  {
54  << "Requested component [" << componenti
55  << "] for field " << fieldName
56  << " is out of range 0.."
58  << exit(FatalError);
59  }
60 
61  residual = component(allComponents, componenti);
62  }
63  else
64  {
65  residual = cmptMax(allComponents);
66  }
67 
68  canSet = false;
69  }
70 }
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::cmptMax
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:253
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
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::functionObjects::runTimeControls::equationInitialResidualCondition::setResidual
void setResidual(const fvMesh &mesh, const dictionary &dict, const word &fieldName, const label componenti, bool &canSet, scalar &residual) const
Set the residual (scalar) value.
Definition: equationInitialResidualConditionTemplates.C:33
Foam::GeometricField< Type, fvPatchField, volMesh >