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 {
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
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:47
volFields.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:159
Foam::List::resize
void resize(const label len)
Definition: ListI.H:132
Foam::fv::option::resetApplied
void resetApplied()
Definition: fvOption.C:41
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
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)
Definition: limitVelocity.C:41
Foam::fv::limitVelocity::read
virtual bool read(const dictionary &dict)
Definition: limitVelocity.C:59
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::fv::option::coeffs_
dictionary coeffs_
Definition: fvOption.H:141
Foam::fv::option::fieldNames_
wordList fieldNames_
Definition: fvOption.H:144
Foam::fv::cellSetOption::read
virtual bool read(const dictionary &dict)
Definition: cellSetOption.C:248
Foam::fv::cellSetOption::useSubMesh
bool useSubMesh() const noexcept
Definition: cellSetOptionI.H:57
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:295
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:119
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:81
Foam
Definition: atmBoundaryLayer.C:26
fv
labelList fv(nPoints)
Foam::fv::limitVelocity::correct
virtual void correct(volVectorField &U)
Definition: limitVelocity.C:72
Foam::fvPatchVectorField
fvPatchField< vector > fvPatchVectorField
Definition: fvPatchFieldsFwd.H:36
Foam::fv::limitVelocity::max_
scalar max_
Definition: limitVelocity.H:130
U
U
Definition: pEqn.H:72
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:44
limitVelocity.H
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:137
Foam::PtrListOps::get
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::fv::limitVelocity::UName_
word UName_
Definition: limitVelocity.H:127
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:49