limitVelocity.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) 2016-2021 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  fvConstraint,
40  limitVelocity,
41  dictionary
42  );
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::fv::limitVelocity::readCoeffs()
50 {
51  UName_ = coeffs().lookupOrDefault<word>("U", "U");
52  max_ = coeffs().lookup<scalar>("max");
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
59 (
60  const word& name,
61  const word& modelType,
62  const dictionary& dict,
63  const fvMesh& mesh
64 )
65 :
66  fvConstraint(name, modelType, dict, mesh),
67  set_(coeffs(), mesh),
68  UName_(word::null),
69  max_(vGreat)
70 {
71  readCoeffs();
72 }
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
78 {
79  return wordList(1, UName_);
80 }
81 
82 
84 {
85  const scalar maxSqrU = sqr(max_);
86 
87  vectorField& Uif = U.primitiveFieldRef();
88 
89  const labelList& cells = set_.cells();
90 
91  forAll(cells, i)
92  {
93  const label celli = cells[i];
94 
95  const scalar magSqrUi = magSqr(Uif[celli]);
96 
97  if (magSqrUi > maxSqrU)
98  {
99  Uif[celli] *= sqrt(maxSqrU/magSqrUi);
100  }
101  }
102 
103  // handle boundaries in the case of 'all'
104  if (set_.selectionMode() == fvCellSet::selectionModeType::all)
105  {
106  volVectorField::Boundary& Ubf = U.boundaryFieldRef();
107 
108  forAll(Ubf, patchi)
109  {
110  fvPatchVectorField& Up = Ubf[patchi];
111 
112  if (!Up.fixesValue())
113  {
114  forAll(Up, facei)
115  {
116  const scalar magSqrUi = magSqr(Up[facei]);
117 
118  if (magSqrUi > maxSqrU)
119  {
120  Up[facei] *= sqrt(maxSqrU/magSqrUi);
121  }
122  }
123  }
124  }
125  }
126 
127  return cells.size();
128 }
129 
130 
132 {
133  set_.updateMesh(mpm);
134 }
135 
136 
138 {
139  if (fvConstraint::read(dict))
140  {
141  set_.read(coeffs());
142  readCoeffs();
143  return true;
144  }
145  else
146  {
147  return false;
148  }
149 }
150 
151 
152 // ************************************************************************* //
defineTypeNameAndDebug(fixedTemperatureConstraint, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual bool constrain(volVectorField &U) const
Constrain the velocity field.
Definition: limitVelocity.C: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:296
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
dimensionedScalar sqrt(const dimensionedScalar &ds)
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
virtual wordList constrainedFields() const
Return the list of fields constrained by the fvConstraint.
Definition: limitVelocity.C:77
virtual void updateMesh(const mapPolyMesh &)
Update for mesh changes.
virtual bool read(const dictionary &dict)
Read dictionary.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Macros for easy insertion into run-time selection tables.
const cellShapeList & cells
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
static const word null
An empty word.
Definition: word.H:77
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
addToRunTimeSelectionTable(fvConstraint, fixedTemperatureConstraint, dictionary)
List< word > wordList
A List of words.
Definition: fileName.H:54
label patchi
U
Definition: pEqn.H:72
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:143
limitVelocity(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: limitVelocity.C:59
Finite volume options abstract base class.
Definition: fvConstraint.H:54
Namespace for OpenFOAM.