Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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"
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace 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 const word& defaultAreaName
58)
59:
60 fa::faceSetOption(name, modelType, dict, mesh, defaultAreaName),
61 hName_("h"),
62 max_(0) // overwritten later
64 read(dict);
65}
66
67
68// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69
71{
73 {
74 return false;
75 }
76
78 coeffs_.readEntry("max", max_);
79
82 applied_.resize(1, false);
83
84 return true;
85}
86
87
89{
90 // Count nTotFaces ourselves
91 // (maybe only applying on a subset)
92 label nFacesAbove = 0;
93 const label nTotFaces = returnReduce(faces_.size(), sumOp<label>());
94
95 scalarField& hif = h.primitiveFieldRef();
96
97 for (const label facei : faces_)
98 {
99 auto& hval = hif[facei];
100
101 if (hval > max_)
102 {
103 hval *= max_/max(hval, SMALL);
104 ++nFacesAbove;
105 }
106 }
107
108 // Handle boundaries in the case of 'all'
109 label nEdgesAbove = 0;
110
112 {
113 for (faPatchScalarField& hp : h.boundaryFieldRef())
114 {
115 if (!hp.fixesValue())
116 {
117 for (auto& hval : hp)
118 {
119 if (hval > max_)
120 {
121 hval *= max_/max(hval, SMALL);
122 ++nEdgesAbove;
123 }
124 }
125 }
126 }
127 }
128
129 // Percent, max 2 decimal places
130 const auto percent = [](scalar num, label denom) -> scalar
131 {
132 return (denom ? 1e-2*round(1e4*num/denom) : 0);
133 };
134
135
136 reduce(nFacesAbove, sumOp<label>());
137 reduce(nEdgesAbove, sumOp<label>());
138
139 Info<< type() << ' ' << name_ << " Limited "
140 << nFacesAbove << " ("
141 << percent(nFacesAbove, nTotFaces)
142 << "%) of faces, with max limit " << max_ << endl;
143
144 if (nFacesAbove || nEdgesAbove)
145 {
146 // We've changed internal values so give
147 // boundary conditions opportunity to correct
148 h.correctBoundaryConditions();
149 }
150}
151
152
153// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
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,...
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...
labelList faces_
Set of faces to apply source to.
virtual bool read(const dictionary &dict)
Read source dictionary.
bool useSubMesh() const noexcept
True if sub-selection should be used.
faceSetOption(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh, const word &defaultAreaName=word())
Construct from components.
Limits the film height to a specified max value.
limitHeight(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh, const word &defaultAreaName=word())
Construct from components.
Definition limitHeight.C:45
virtual void correct(areaScalarField &h)
Correct the height field.
Definition limitHeight.C:81
word hName_
Name of operand height field.
virtual bool read(const dictionary &dict)
Read dictionary.
Definition limitHeight.C:63
scalar max_
Maximum height [m].
Base abstract class for handling finite area options (i.e. faOption).
Definition faOption.H:149
const fvMesh & mesh() const noexcept
Return const access to the volume mesh.
Definition faOption.H:385
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition faOption.H:195
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition faOption.H:190
dictionary coeffs_
Dictionary containing source coefficients.
Definition faOption.H:185
const word & name() const noexcept
The source name.
Definition faOption.H:380
const word name_
Source name.
Definition faOption.H:165
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
Namespace for finite-area.
Definition limitHeight.C:30
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
messageStream Info
Information stream (stdout output on master, null elsewhere).
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
GeometricField< scalar, faPatchField, areaMesh > areaScalarField
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
faPatchField< scalar > faPatchScalarField
dictionary dict
volScalarField & h
volScalarField & e