sampledInterface.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) 2020 DLR
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 "sampledInterface.H"
29 #include "dictionary.H"
30 #include "volFields.H"
31 #include "volPointInterpolation.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(sampledInterface, 0);
40  (
41  sampledSurface,
42  sampledInterface,
43  word,
44  interface
45  );
46 }
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 
51 bool Foam::sampledInterface::updateGeometry() const
52 {
53  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
54 
55  // No update needed
56  if (fvm.time().timeIndex() == prevTimeIndex_)
57  {
58  return false;
59  }
60 
61  prevTimeIndex_ = fvm.time().timeIndex();
62 
63  // Not really being used...
64 
65  // Get sub-mesh if any
66  if
67  (
68  !subMeshPtr_
69  && (-1 != mesh().cellZones().findIndex(zoneNames_))
70  )
71  {
72  const label exposedPatchi =
73  mesh().boundaryMesh().findPatchID(exposedPatchName_);
74 
75  bitSet cellsToSelect(mesh().cellZones().selection(zoneNames_));
76 
77  DebugInfo
78  << "Allocating subset of size "
79  << cellsToSelect.count()
80  << " with exposed faces into patch "
81  << exposedPatchi << endl;
82 
83  subMeshPtr_.reset
84  (
85  new fvMeshSubset(fvm, cellsToSelect, exposedPatchi)
86  );
87  }
88 
89 
90  // Clear any stored topo
91  surfPtr_.clear();
92 
93  // Clear derived data
94  clearGeom();
95 
96  surfPtr_.reset
97  (
99  (
100  fvm.lookupObjectRef<reconstructionSchemes>
101  (
102  "reconstructionScheme"
103  ).surface()
104  )
105  );
106 
107  return true;
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
112 
114 (
115  const word& name,
116  const polyMesh& mesh,
117  const dictionary& dict
118 )
119 :
121  zoneNames_(),
122  exposedPatchName_(),
123  surfPtr_(nullptr),
124  prevTimeIndex_(-1),
125  subMeshPtr_(nullptr)
126 {
127  if (!dict.readIfPresent("zones", zoneNames_) && dict.found("zone"))
128  {
129  zoneNames_.resize(1);
130  dict.readEntry("zone", zoneNames_.first());
131  }
132 
133  if (-1 != mesh.cellZones().findIndex(zoneNames_))
134  {
135  dict.readIfPresent("exposedPatchName", exposedPatchName_);
136 
137  DebugInfo
138  << "Restricting to cellZone " << flatOutput(zoneNames_)
139  << " with exposed internal faces into patch "
140  << mesh.boundaryMesh().findPatchID(exposedPatchName_) << endl;
141  }
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
148 {
149  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
150 
151  return fvm.time().timeIndex() != prevTimeIndex_;
152 }
153 
154 
156 {
157  surfPtr_.clear();
158  subMeshPtr_.clear();
159 
160  // Clear derived data
161  clearGeom();
162 
163  // Already marked as expired
164  if (prevTimeIndex_ == -1)
165  {
166  return false;
167  }
168 
169  // Force update
170  prevTimeIndex_ = -1;
171  return true;
172 }
173 
174 
176 {
177  return updateGeometry();
178 }
179 
180 
182 (
183  const interpolation<scalar>& sampler
184 ) const
185 {
186  return sampleOnFaces(sampler);
187 }
188 
189 
191 (
192  const interpolation<vector>& sampler
193 ) const
194 {
195  return sampleOnFaces(sampler);
196 }
197 
198 
200 (
201  const interpolation<sphericalTensor>& sampler
202 ) const
203 {
204  return sampleOnFaces(sampler);
205 }
206 
207 
209 (
210  const interpolation<symmTensor>& sampler
211 ) const
212 {
213  return sampleOnFaces(sampler);
214 }
215 
216 
218 (
219  const interpolation<tensor>& sampler
220 ) const
221 {
222  return sampleOnFaces(sampler);
223 }
224 
225 
227 (
228  const interpolation<scalar>& interpolator
229 ) const
230 {
231  return sampleOnPoints(interpolator);
232 }
233 
234 
236 (
237  const interpolation<vector>& interpolator
238 ) const
239 {
240  return sampleOnPoints(interpolator);
241 }
242 
244 (
245  const interpolation<sphericalTensor>& interpolator
246 ) const
247 {
248  return sampleOnPoints(interpolator);
249 }
250 
251 
253 (
254  const interpolation<symmTensor>& interpolator
255 ) const
256 {
257  return sampleOnPoints(interpolator);
258 }
259 
260 
262 (
263  const interpolation<tensor>& interpolator
264 ) const
265 {
266  return sampleOnPoints(interpolator);
267 }
268 
269 
270 void Foam::sampledInterface::print(Ostream& os, int level) const
271 {
272  os << "sampledInterface: " << name();
273 }
274 
275 
276 // ************************************************************************* //
volFields.H
sampledInterface.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::ZoneMesh::findIndex
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:491
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Foam::sampledInterface::update
virtual bool update()
Update the surface as required.
Definition: sampledInterface.C:175
interface
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
Foam::sampledInterface::sampledInterface
sampledInterface(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: sampledInterface.C:114
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::TimeState::timeIndex
label timeIndex() const noexcept
Return current time index.
Definition: TimeStateI.H:37
Foam::sampledSurface::interpolate
bool interpolate() const noexcept
Same as isPointData()
Definition: sampledSurface.H:598
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:492
Foam::sampledInterface::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledInterface.C:147
Foam::findIndex
label findIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
Deprecated(2017-10) search for first occurrence of the given element.
Definition: ListOps.H:406
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:302
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:121
Foam::polyBoundaryMesh::findPatchID
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
Definition: polyBoundaryMesh.C:765
Foam::interpolation< scalar >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::sampledInterface::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledInterface.C:155
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::sampledInterface::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledInterface.C:182
volPointInterpolation.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::sampledSurface::mesh
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
Definition: sampledSurface.H:316
dictionary.H
Foam::sampledInterface::print
virtual void print(Ostream &os, int level=0) const
Print information.
Definition: sampledInterface.C:270
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
Definition: sampledSurface.C:53
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405