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-2020 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  cellSetOption(name, modelType, dict, mesh),
56  UName_(coeffs_.getOrDefault<word>("U", "U")),
57  max_(coeffs_.get<scalar>("max"))
58 {
59  fieldNames_.setSize(1, UName_);
60  applied_.setSize(1, false);
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'
96  if (selectionMode_ == smAll)
97  {
98  volVectorField::Boundary& Ubf = U.boundaryFieldRef();
99 
100  forAll(Ubf, patchi)
101  {
102  fvPatchVectorField& Up = Ubf[patchi];
103 
104  if (!Up.fixesValue())
105  {
106  forAll(Up, facei)
107  {
108  const scalar magSqrUi = magSqr(Up[facei]);
109 
110  if (magSqrUi > maxSqrU)
111  {
112  Up[facei] *= sqrt(maxSqrU/magSqrUi);
113  }
114  }
115  }
116  }
117  }
118 
119  // We've changed internal values so give
120  // boundary conditions opportunity to correct
121  U.correctBoundaryConditions();
122 }
123 
124 
125 // ************************************************************************* //
Foam::fvPatchField< vector >
volFields.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:163
Foam::fvPatchField::fixesValue
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: fvPatchField.H:318
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::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
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::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
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:121
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:83
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
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::GeometricField< vector, fvPatchField, volMesh >
limitVelocity.H