limitVelocity.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 | Copyright (C) 2016 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 "limitVelocity.H"
27 #include "volFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace fv
35 {
36  defineTypeNameAndDebug(limitVelocity, 0);
38  (
39  option,
40  limitVelocity,
41  dictionary
42  );
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::fv::limitVelocity::limitVelocity
50 (
51  const word& name,
52  const word& modelType,
53  const dictionary& dict,
54  const fvMesh& mesh
55 )
56 :
57  cellSetOption(name, modelType, dict, mesh),
58  UName_(coeffs_.lookupOrDefault<word>("U", "U")),
59  max_(readScalar(coeffs_.lookup("max")))
60 {
61  fieldNames_.setSize(1, UName_);
62  applied_.setSize(1, false);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 
69 {
70  if (cellSetOption::read(dict))
71  {
72  coeffs_.lookup("max") >> max_;
73 
74  return true;
75  }
76  else
77  {
78  return false;
79  }
80 }
81 
82 
84 {
85  const scalar maxSqrU = sqr(max_);
86 
87  vectorField& Uif = U.primitiveFieldRef();
88 
89  forAll(cells_, i)
90  {
91  const label celli = cells_[i];
92 
93  const scalar magSqrUi = magSqr(Uif[celli]);
94 
95  if (magSqrUi > maxSqrU)
96  {
97  Uif[celli] *= maxSqrU/magSqrUi;
98  }
99  }
100 
101  // handle boundaries in the case of 'all'
102  if (selectionMode_ == smAll)
103  {
104  volVectorField::Boundary& Ubf = U.boundaryFieldRef();
105 
106  forAll(Ubf, patchi)
107  {
108  fvPatchVectorField& Up = Ubf[patchi];
109 
110  if (!Up.fixesValue())
111  {
112  forAll(Up, facei)
113  {
114  const scalar magSqrUi = magSqr(Up[facei]);
115 
116  if (magSqrUi > maxSqrU)
117  {
118  Up[facei] *= maxSqrU/magSqrUi;
119  }
120  }
121  }
122  }
123  }
124 }
125 
126 
127 // ************************************************************************* //
defineTypeNameAndDebug(option, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
U
Definition: pEqn.H:83
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: fvPatchField.H:315
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
addToRunTimeSelectionTable(option, fixedTemperatureConstraint, dictionary)
virtual bool read(const dictionary &dict)
Read source dictionary.
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitVelocity.C:68
Macros for easy insertion into run-time selection tables.
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
label patchi
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:69
virtual void correct(volVectorField &U)
Correct the energy field.
Definition: limitVelocity.C:83
Namespace for OpenFOAM.