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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "limitVelocity.H"
30 #include "volFields.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace fv
38 {
39  defineTypeNameAndDebug(limitVelocity, 0);
40  addToRunTimeSelectionTable(option, limitVelocity, dictionary);
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 (
49  const word& name,
50  const word& modelType,
51  const dictionary& dict,
52  const fvMesh& mesh
53 )
54 :
55  fv::cellSetOption(name, modelType, dict, mesh),
56  UName_(coeffs_.getOrDefault<word>("U", "U")),
57  max_(coeffs_.get<scalar>("max"))
58 {
59  fieldNames_.resize(1, UName_);
60  fv::option::resetApplied();
61 }
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
67 {
69  {
70  coeffs_.readEntry("max", max_);
71 
72  return true;
73  }
74 
75  return false;
76 }
77 
78 
80 {
81  const scalar maxSqrU = sqr(max_);
82 
83  vectorField& Uif = U.primitiveFieldRef();
84 
85  for (const label celli : cells_)
86  {
87  const scalar magSqrUi = magSqr(Uif[celli]);
88 
89  if (magSqrUi > maxSqrU)
90  {
91  Uif[celli] *= sqrt(maxSqrU/magSqrUi);
92  }
93  }
94 
95  // Handle boundaries in the case of 'all'
97  {
98  for (fvPatchVectorField& Up : U.boundaryFieldRef())
99  {
100  if (!Up.fixesValue())
101  {
102  forAll(Up, facei)
103  {
104  const scalar magSqrUi = magSqr(Up[facei]);
105 
106  if (magSqrUi > maxSqrU)
107  {
108  Up[facei] *= sqrt(maxSqrU/magSqrUi);
109  }
110  }
111  }
112  }
113  }
114 
115  // We've changed internal values so give
116  // boundary conditions opportunity to correct
117  U.correctBoundaryConditions();
118 }
119 
120 
121 // ************************************************************************* //
Foam::fvPatchField< vector >
volFields.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:163
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::fv::limitVelocity::limitVelocity
limitVelocity(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: limitVelocity.C:48
Foam::fv::limitVelocity::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitVelocity.C:66
Foam::Field< vector >
Foam::fv::option::coeffs_
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:145
Foam::fv::cellSetOption::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: cellSetOption.C:255
Foam::fv::cellSetOption::useSubMesh
bool useSubMesh() const noexcept
True if sub-selection should be used.
Definition: cellSetOptionI.H:64
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:302
dict
dictionary dict
Definition: searchingEngine.H:14
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
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
fv
labelList fv(nPoints)
Foam::fv::limitVelocity::correct
virtual void correct(volVectorField &U)
Correct the velocity field.
Definition: limitVelocity.C:79
Foam::fv::limitVelocity::max_
scalar max_
Maximum velocity magnitude.
Definition: limitVelocity.H:134
U
U
Definition: pEqn.H:72
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
limitVelocity.H
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::GeometricField< vector, fvPatchField, volMesh >