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) 2021 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 "limitVelocity.H"
29 #include "areaFields.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fa
37 {
40  (
41  option,
44  );
45 }
46 }
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 Foam::fa::limitVelocity::limitVelocity
51 (
52  const word& name,
53  const word& modelType,
54  const dictionary& dict,
55  const fvPatch& patch
56 )
57 :
58  faceSetOption(name, modelType, dict, patch),
59  UName_(coeffs_.getOrDefault<word>("U", "U")),
60  max_(coeffs_.get<scalar>("max"))
61 {
62  fieldNames_.setSize(1, UName_);
63  applied_.setSize(1, false);
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
70 {
72  {
73  coeffs_.readEntry("max", max_);
74 
75  return true;
76  }
77 
78  return false;
79 }
80 
81 
83 {
84  const scalar maxSqrU = sqr(max_);
85 
86  vectorField& Uif = U.primitiveFieldRef();
87 
88  for (const label facei : faces_)
89  {
90  const scalar magSqrUi = magSqr(Uif[facei]);
91 
92  if (magSqrUi > maxSqrU)
93  {
94  Uif[facei] *= sqrt(maxSqrU/max(magSqrUi, SMALL));
95  }
96  }
97 
98  // Handle boundaries in the case of 'all'
100  {
101  for (faPatchVectorField& Up : U.boundaryFieldRef())
102  {
103  if (!Up.fixesValue())
104  {
105  forAll(Up, facei)
106  {
107  const scalar magSqrUi = magSqr(Up[facei]);
108 
109  if (magSqrUi > maxSqrU)
110  {
111  Up[facei] *= sqrt(maxSqrU/max(magSqrUi, SMALL));
112  }
113  }
114  }
115  }
116  }
117 
118  // We've changed internal values so give boundary conditions opportunity
119  // to correct.
120  U.correctBoundaryConditions();
121 }
122 
123 
124 // ************************************************************************* //
Foam::fa::limitVelocity
Limits the maximum velocity magnitude to the specified max value.
Definition: limitVelocity.H:107
Foam::faPatchField
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:50
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
limitVelocity.H
Foam::fa::faceSetOption
Intermediate abstract class for handling face-set options for the derived faOptions.
Definition: faceSetOption.H:134
Foam::fa::limitVelocity::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitVelocity.C:69
Foam::fa::defineTypeNameAndDebug
defineTypeNameAndDebug(limitVelocity, 0)
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::fa::faceSetOption::useSubMesh
bool useSubMesh() const noexcept
True if sub-selection should be used.
Definition: faceSetOptionI.H:63
Foam::Field< vector >
Foam::fa::limitVelocity::max_
scalar max_
Maximum velocity magnitude.
Definition: limitVelocity.H:119
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::fa::option::coeffs_
dictionary coeffs_
Dictionary containing source coefficients.
Definition: faOption.H:161
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:302
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
areaFields.H
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
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fa::faceSetOption::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faceSetOption.C:230
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fa::limitVelocity::correct
virtual void correct(areaVectorField &U)
Correct the velocity field.
Definition: limitVelocity.C:82
U
U
Definition: pEqn.H:72
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::fa::option
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:133
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::fa::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, limitVelocity, dictionary)
Foam::GeometricField< vector, faPatchField, areaMesh >