patchFluxToFace.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) 2021-2022 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 "patchFluxToFace.H"
27 #include "polyMesh.H"
28 #include "faceSet.H"
29 #include "Time.H"
30 #include "IFstream.H"
31 #include "fieldDictionary.H"
32 #include "surfaceFields.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::patchFluxToFace::applyToSet
47 (
48  const topoSetSource::setAction action,
49  const scalarField& patchFluxField,
50  topoSet& set
51 ) const
52 {
53  const polyPatch& patch = mesh().boundaryMesh()[patchName_];
54 
55  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
56  {
57  Info<< " Adding all " << fieldName_
58  << (inflow_ ? " inflow" : " outflow") << " faces" << endl;
59 
60  forAll(patch, facei)
61  {
62  if
63  (
64  (inflow_ && patchFluxField[facei] < 0)
65  || (!inflow_ && patchFluxField[facei] >= 0)
66  )
67  {
68  set.insert(patch.start() + facei);
69  }
70  }
71  }
72  else if (action == topoSetSource::DELETE)
73  {
74  Info<< " Removing all " << fieldName_
75  << (inflow_ ? " inflow" : " outflow") << " faces" << endl;
76 
77  forAll(patch, facei)
78  {
79  if
80  (
81  (inflow_ && patchFluxField[facei] < 0)
82  || (!inflow_ && patchFluxField[facei] >= 0)
83  )
84  {
85  set.erase(patch.start() + facei);
86  }
87  }
88  }
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
93 
95 (
96  const polyMesh& mesh,
97  const word& fieldName,
98  const word& patchName,
99  const bool inflow
100 )
101 :
102  topoSetSource(mesh),
103  fieldName_(fieldName),
104  patchName_(patchName),
105  inflow_(inflow)
106 {}
107 
108 
110 (
111  const polyMesh& mesh,
112  const dictionary& dict
113 )
114 :
115  topoSetSource(mesh),
116  fieldName_(dict.lookup("field")),
117  patchName_(dict.lookup("patch")),
118  inflow_(dict.lookup<Switch>("inflow"))
119 {}
120 
121 
122 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
130 void Foam::patchFluxToFace::applyToSet
131 (
132  const topoSetSource::setAction action,
133  topoSet& set
134 ) const
135 {
137  (
138  fieldName_,
139  mesh().time().name(),
140  mesh(),
143  false
144  );
145 
146  if (fieldObject.headerOk())
147  {
149 
150  // Read dictionary
151  const fieldDictionary fieldDict
152  (
153  fieldObject,
155  );
156 
157  const scalarField patchFluxField
158  (
159  "value",
160  fieldDict.subDict("boundaryField").subDict(patchName_),
161  mesh().boundaryMesh()[patchName_].size()
162  );
163 
164  applyToSet(action, patchFluxField, set);
165  }
166  else
167  {
169  << "Cannot read flux field " << fieldName_
170  << " from time " << mesh().time().name() << endl;
171  }
172 }
173 
174 
175 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
Input from file stream.
Definition: IFstream.H:85
fileName filePath(const word &typeName, const bool global) const
Return complete path + object name if the file exists.
Definition: IOobject.C:407
bool headerOk()
Read header of local object without type-checking.
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobject.H:316
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:843
Read field as dictionary (without mesh).
A topoSetSource to select patch faces according to the flux direction.
virtual ~patchFluxToFace()
Destructor.
patchFluxToFace(const polyMesh &mesh, const word &fieldName, const word &patchName, const bool inflow)
Construct from components.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh() const
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:531
A class for handling words, derived from string.
Definition: word.H:62
IOobject fieldObject(fieldNames[var2field[nVar]], runTime.name(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE)
volScalarField scalarField(fieldObject, mesh)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
defineTypeNameAndDebug(combustionModel, 0)
dictionary dict
Foam::surfaceFields.