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 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);
41  (
42  option,
43  limitVelocity,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 Foam::fv::limitVelocity::limitVelocity
53 (
54  const word& name,
55  const word& modelType,
56  const dictionary& dict,
57  const fvMesh& mesh
58 )
59 :
60  cellSetOption(name, modelType, dict, mesh),
61  UName_(coeffs_.lookupOrDefault<word>("U", "U")),
62  max_(coeffs_.get<scalar>("max"))
63 {
64  fieldNames_.setSize(1, UName_);
65  applied_.setSize(1, false);
66 }
67 
68 
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 
72 {
74  {
75  coeffs_.readEntry("max", max_);
76 
77  return true;
78  }
79 
80  return false;
81 }
82 
83 
85 {
86  const scalar maxSqrU = sqr(max_);
87 
88  vectorField& Uif = U.primitiveFieldRef();
89 
90  for (const label celli : cells_)
91  {
92  const scalar magSqrUi = magSqr(Uif[celli]);
93 
94  if (magSqrUi > maxSqrU)
95  {
96  Uif[celli] *= sqrt(maxSqrU/magSqrUi);
97  }
98  }
99 
100  // handle boundaries in the case of 'all'
101  if (selectionMode_ == smAll)
102  {
103  volVectorField::Boundary& Ubf = U.boundaryFieldRef();
104 
105  forAll(Ubf, patchi)
106  {
107  fvPatchVectorField& Up = Ubf[patchi];
108 
109  if (!Up.fixesValue())
110  {
111  forAll(Up, facei)
112  {
113  const scalar magSqrUi = magSqr(Up[facei]);
114 
115  if (magSqrUi > maxSqrU)
116  {
117  Up[facei] *= sqrt(maxSqrU/magSqrUi);
118  }
119  }
120  }
121  }
122  }
123 
124  // We've changed internal values so give boundary conditions opportunity
125  // to correct.
126  U.correctBoundaryConditions();
127 }
128 
129 
130 // ************************************************************************* //
Foam::fvPatchField< vector >
volFields.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fv::cellSetOption
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:72
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:290
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::fv::limitVelocity::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitVelocity.C:71
Foam::label
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:62
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:88
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:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
fv
labelList fv(nPoints)
Foam::fv::limitVelocity::correct
virtual void correct(volVectorField &U)
Correct the energy field.
Definition: limitVelocity.C:84
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(option, 0)
Foam::fv::limitVelocity::max_
scalar max_
Maximum velocity magnitude.
Definition: limitVelocity.H:77
U
U
Definition: pEqn.H:72
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, fixedTemperatureConstraint, dictionary)
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::GeometricField< vector, fvPatchField, volMesh >
limitVelocity.H