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  // Get any subMesh
62  if (!subMeshPtr_ && zoneID_.index() != -1)
63  {
64  const cellZone& cz = mesh().cellZones()[zoneID_.index()];
65 
66  const polyBoundaryMesh& patches = mesh().boundaryMesh();
67 
68  // Patch to put exposed internal faces into
69  const label exposedPatchi = patches.findPatchID(exposedPatchName_);
70 
71  DebugInfo
72  << "Allocating subset of size " << cz.size()
73  << " with exposed faces into patch "
74  << patches[exposedPatchi].name() << endl;
75 
76  subMeshPtr_.reset(new fvMeshSubset(fvm, cz, exposedPatchi));
77  }
78 
79 
80  prevTimeIndex_ = fvm.time().timeIndex();
81 
82  // Clear any stored topo
83  surfPtr_.clear();
84 
85  // Clear derived data
86  clearGeom();
87 
88  surfPtr_.reset
89  (
91  (
92  fvm.lookupObjectRef<reconstructionSchemes>
93  (
94  "reconstructionScheme"
95  ).surface()
96  )
97  );
98 
99  return true;
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 
106 (
107  const word& name,
108  const polyMesh& mesh,
109  const dictionary& dict
110 )
111 :
113  zoneID_(dict.getOrDefault<word>("zone", word::null), mesh.cellZones()),
114  exposedPatchName_(word::null),
115  surfPtr_(nullptr),
116  prevTimeIndex_(-1),
117  subMeshPtr_(nullptr)
118 {
119  if (zoneID_.index() != -1)
120  {
121  dict.readEntry("exposedPatchName", exposedPatchName_);
122 
123  if (mesh.boundaryMesh().findPatchID(exposedPatchName_) == -1)
124  {
126  << "Cannot find patch " << exposedPatchName_
127  << " in which to put exposed faces." << endl
128  << "Valid patches are " << mesh.boundaryMesh().names()
129  << exit(FatalIOError);
130  }
131 
132  DebugInfo
133  << "Restricting to cellZone " << zoneID_.name()
134  << " with exposed internal faces into patch "
135  << exposedPatchName_ << endl;
136  }
137 }
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
143 {
144  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
145 
146  return fvm.time().timeIndex() != prevTimeIndex_;
147 }
148 
149 
151 {
152  surfPtr_.clear();
153  subMeshPtr_.clear();
154 
155  // Clear derived data
156  clearGeom();
157 
158  // Already marked as expired
159  if (prevTimeIndex_ == -1)
160  {
161  return false;
162  }
163 
164  // Force update
165  prevTimeIndex_ = -1;
166  return true;
167 }
168 
169 
171 {
172  return updateGeometry();
173 }
174 
175 
177 (
178  const interpolation<scalar>& sampler
179 ) const
180 {
181  return sampleOnFaces(sampler);
182 }
183 
184 
186 (
187  const interpolation<vector>& sampler
188 ) const
189 {
190  return sampleOnFaces(sampler);
191 }
192 
193 
195 (
196  const interpolation<sphericalTensor>& sampler
197 ) const
198 {
199  return sampleOnFaces(sampler);
200 }
201 
202 
204 (
205  const interpolation<symmTensor>& sampler
206 ) const
207 {
208  return sampleOnFaces(sampler);
209 }
210 
211 
213 (
214  const interpolation<tensor>& sampler
215 ) const
216 {
217  return sampleOnFaces(sampler);
218 }
219 
220 
222 (
223  const interpolation<scalar>& interpolator
224 ) const
225 {
226  return sampleOnPoints(interpolator);
227 }
228 
229 
231 (
232  const interpolation<vector>& interpolator
233 ) const
234 {
235  return sampleOnPoints(interpolator);
236 }
237 
239 (
240  const interpolation<sphericalTensor>& interpolator
241 ) const
242 {
243  return sampleOnPoints(interpolator);
244 }
245 
246 
248 (
249  const interpolation<symmTensor>& interpolator
250 ) const
251 {
252  return sampleOnPoints(interpolator);
253 }
254 
255 
257 (
258  const interpolation<tensor>& interpolator
259 ) const
260 {
261  return sampleOnPoints(interpolator);
262 }
263 
264 
266 {
267  os << "sampledInterface: " << name();
268 }
269 
270 
271 // ************************************************************************* //
volFields.H
sampledInterface.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::sampledInterface::update
virtual bool update()
Update the surface as required.
Definition: sampledInterface.C:170
interface
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:483
Foam::FatalIOError
IOerror FatalIOError
Foam::sampledInterface::sampledInterface
sampledInterface(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: sampledInterface.C:106
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::polyBoundaryMesh::names
wordList names() const
Return a list of patch names.
Definition: polyBoundaryMesh.C:593
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::sampledInterface::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledInterface.C:142
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:314
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:120
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:766
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:150
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
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:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::sampledInterface::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledInterface.C:177
Foam::sampledInterface::print
virtual void print(Ostream &) const
Write.
Definition: sampledInterface.C:265
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
volPointInterpolation.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:354
dictionary.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
Definition: sampledSurface.C:55
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:248
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:392
Foam::sampledSurface::mesh
const polyMesh & mesh() const
Access to the underlying mesh.
Definition: sampledSurface.H:302
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::TimeState::timeIndex
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:36
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:122
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation to nodes requested for surface.
Definition: sampledSurface.H:326
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::DynamicID::index
label index() const
Return index of first matching zone.
Definition: DynamicID.H:110