limitMag.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "limitMag.H"
27 #include "volFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace fv
35 {
38  (
40  limitMag,
42  );
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::fv::limitMag::readCoeffs(const dictionary& dict)
50 {
51  fieldName_ = dict.lookup<word>("field");
52  max_ = dict.lookup<scalar>("max");
53 }
54 
55 
56 template<class Type>
57 inline bool Foam::fv::limitMag::constrainType
58 (
59  VolField<Type>& psi
60 ) const
61 {
62  const scalar maxSqrPsi = sqr(max_);
63 
64  Field<Type>& psiif = psi.primitiveFieldRef();
65 
66  zone_.regenerate();
67  const labelList& cells = zone_.zone();
68 
69  forAll(cells, i)
70  {
71  const label celli = cells[i];
72 
73  const scalar magSqrPsii = magSqr(psiif[celli]);
74 
75  if (magSqrPsii > maxSqrPsi)
76  {
77  psiif[celli] *= sqrt(maxSqrPsi/magSqrPsii);
78  }
79  }
80 
81  // handle boundaries in the case of 'all'
82  if (zone_.all())
83  {
84  typename VolField<Type>::Boundary& psibf =
85  psi.boundaryFieldRef();
86 
87  forAll(psibf, patchi)
88  {
89  fvPatchField<Type>& psip = psibf[patchi];
90 
91  if (!psip.fixesValue())
92  {
93  forAll(psip, facei)
94  {
95  const scalar magSqrPsii = magSqr(psip[facei]);
96 
97  if (magSqrPsii > maxSqrPsi)
98  {
99  psip[facei] *= sqrt(maxSqrPsi/magSqrPsii);
100  }
101  }
102  }
103  }
104  }
105 
106  return cells.size();
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111 
113 (
114  const word& name,
115  const word& modelType,
116  const fvMesh& mesh,
117  const dictionary& dict
118 )
119 :
120  fvConstraint(name, modelType, mesh, dict),
121  zone_(mesh, coeffs(dict)),
122  fieldName_(word::null),
123  max_(vGreat)
124 {
125  readCoeffs(coeffs(dict));
126 }
127 
128 
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 
132 {
133  return wordList(1, fieldName_);
134 }
135 
136 
138 (
140  fv::limitMag
141 );
142 
143 
145 {
146  zone_.movePoints();
147  return true;
148 }
149 
150 
152 {
153  zone_.topoChange(map);
154 }
155 
156 
158 {
159  zone_.mapMesh(map);
160 }
161 
162 
164 {
165  zone_.distribute(map);
166 }
167 
168 
170 {
172  {
173  zone_.read(coeffs(dict));
174  readCoeffs(coeffs(dict));
175  return true;
176  }
177  else
178  {
179  return false;
180  }
181 }
182 
183 
184 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
GeometricBoundaryField< Type, GeoMesh, PrimitiveField > Boundary
Type of the boundary field.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Finite volume options abstract base class.
Definition: fvConstraint.H:57
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:163
const dictionary & coeffs(const dictionary &) const
Return the coefficients sub-dictionary.
Definition: fvConstraintI.H:41
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
Limits the magnitude of the specified field to the specified max value.
Definition: limitMag.H:69
virtual bool movePoints()
Update for mesh motion.
Definition: limitMag.C:144
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: limitMag.C:151
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: limitMag.C:163
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitMag.C:169
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: limitMag.C:157
limitMag(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from components.
Definition: limitMag.C:113
virtual wordList constrainedFields() const
Return the list of fields constrained by the fvConstraint.
Definition: limitMag.C:131
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define IMPLEMENT_FV_CONSTRAINT_CONSTRAIN_FIELD(Type, constraintType)
Definition: fvConstraintM.H:49
label patchi
const cellShapeList & cells
const volScalarField & psi
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
List< label > labelList
A List of labels.
Definition: labelList.H:56
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:59
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
tmp< DimensionedField< scalar, GeoMesh, Field > > magSqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
labelList fv(nPoints)
dictionary dict