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 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 {
39  defineTypeNameAndDebug(patchFluxToFace, 0);
40  addToRunTimeSelectionTable(topoSetSource, patchFluxToFace, word);
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().timeName(),
140  mesh(),
143  false
144  );
145 
146  if (fieldObject.headerOk())
147  {
148  IFstream str(fieldObject.filePath());
149 
150  // Read dictionary
151  const fieldDictionary fieldDict
152  (
153  fieldObject,
154  fieldObject.headerClassName()
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().timeName() << endl;
171  }
172 }
173 
174 
175 // ************************************************************************* //
Foam::surfaceFields.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:453
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool headerOk()
Read header (uses typeGlobalFile to find file) and check.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Templated form of IOobject providing type information for file reading and header type checking...
Definition: IOobject.H:537
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:372
IOobject fieldObject(fieldNames[var2field[nVar]], runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE)
fvMesh & mesh
fileName filePath() const
Return the path for the file for this Type.
Definition: IOobject.H:572
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
A class for handling words, derived from string.
Definition: word.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
patchFluxToFace(const polyMesh &mesh, const word &fieldName, const word &patchName, const bool inflow)
Construct from components.
word timeName
Definition: getTimeIndex.H:3
Read field as dictionary (without mesh).
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Input from file stream.
Definition: IFstream.H:81
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
#define WarningInFunction
Report a warning using Foam::Warning.
virtual ~patchFluxToFace()
Destructor.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobject.H:321
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864