limitHeight.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) 2022 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 "limitHeight.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 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
52 (
53  const word& name,
54  const word& modelType,
55  const dictionary& dict,
56  const fvMesh& mesh
57 )
58 :
59  faceSetOption(name, modelType, dict, mesh),
60  hName_("h"),
61  max_(0) // overwritten later
62 {
63  read(dict);
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
70 {
72  {
73  return false;
74  }
75 
77  coeffs_.readEntry("max", max_);
78 
80 
81  applied_.resize(1, false);
82 
83  return true;
84 }
85 
86 
88 {
89  // Count nTotFaces ourselves
90  // (maybe only applying on a subset)
91  label nFacesAbove = 0;
92  const label nTotFaces = returnReduce(faces_.size(), sumOp<label>());
93 
94  scalarField& hif = h.primitiveFieldRef();
95 
96  for (const label facei : faces_)
97  {
98  auto& hval = hif[facei];
99 
100  if (hval > max_)
101  {
102  hval *= max_/max(hval, SMALL);
103  ++nFacesAbove;
104  }
105  }
106 
107  // Handle boundaries in the case of 'all'
108  label nEdgesAbove = 0;
109 
111  {
112  for (faPatchScalarField& hp : h.boundaryFieldRef())
113  {
114  if (!hp.fixesValue())
115  {
116  for (auto& hval : hp)
117  {
118  if (hval > max_)
119  {
120  hval *= max_/max(hval, SMALL);
121  ++nEdgesAbove;
122  }
123  }
124  }
125  }
126  }
127 
128  // Percent, max 2 decimal places
129  const auto percent = [](scalar num, label denom) -> scalar
130  {
131  return (denom ? 1e-2*round(1e4*num/denom) : 0);
132  };
133 
134 
135  reduce(nFacesAbove, sumOp<label>());
136  reduce(nEdgesAbove, sumOp<label>());
137 
138  Info<< type() << ' ' << name_ << " Limited "
139  << nFacesAbove << " ("
140  << percent(nFacesAbove, nTotFaces)
141  << "%) of faces, with max limit " << max_ << endl;
142 
143  if (nFacesAbove || nEdgesAbove)
144  {
145  // We've changed internal values so give
146  // boundary conditions opportunity to correct
147  h.correctBoundaryConditions();
148  }
149 }
150 
151 
152 // ************************************************************************* //
addToRunTimeSelectionTable(option, limitHeight, dictionary)
dictionary dict
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: faOption.H:171
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
scalar max_
Maximum height [m].
Definition: limitHeight.H:123
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:129
Macros for easy insertion into run-time selection tables.
bool useSubMesh() const noexcept
True if sub-selection should be used.
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect...
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
defineTypeNameAndDebug(limitHeight, 0)
limitHeight(const limitHeight &)=delete
No copy construct.
Limits the film height to a specified max value.
Definition: limitHeight.H:107
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
const dimensionedScalar h
Planck constant.
word hName_
Name of operand height field.
Definition: limitHeight.H:118
virtual void correct(areaScalarField &h)
Correct the height field.
Definition: limitHeight.C:80
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitHeight.C:62
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
virtual bool read(const dictionary &dict)
Read source dictionary.
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition: faOption.H:176
dictionary coeffs_
Dictionary containing source coefficients.
Definition: faOption.H:166
Namespace for OpenFOAM.