searchableSurfaceToFace.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) 2018-2022 OpenCFD Ltd.
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 
29 #include "polyMesh.H"
30 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(searchableSurfaceToFace, 0);
39  (
40  topoSetSource,
41  searchableSurfaceToFace,
42  word
43  );
45  (
46  topoSetFaceSource,
47  searchableSurfaceToFace,
48  word
49  );
51  (
52  topoSetFaceSource,
53  searchableSurfaceToFace,
54  word,
55  surface
56  );
57 }
58 
59 
60 Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToFace::usage_
61 (
62  searchableSurfaceToFace::typeName,
63  "\n Usage: searchableSurfaceToFace surface\n\n"
64  " Select faces with centres enclosed by the surface"
65  "\n"
66 );
67 
68 
69 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 // Difficult to get a good default name from the dictionary name.
75 // It could be
76 // sourceInfo { .. }
77 // But even with something like
78 // mySurf.stl { .. }
79 // The dictName() method will only return the "stl" ending.
80 
81 static inline word getSurfaceName
82 (
83  const dictionary& dict,
84  word surfaceName
85 )
86 {
87  dict.readIfPresent("surfaceName", surfaceName);
88 
89  if (surfaceName.empty()) surfaceName = "surface"; // failsafe
90 
91  return surfaceName;
92 }
93 
94 } // End namespace Foam
95 
96 
97 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
98 
99 void Foam::searchableSurfaceToFace::combine(topoSet& set, const bool add) const
100 {
101  if (!surf_)
102  {
103  return;
104  }
105  const tmp<pointField> tctrs(this->transform(mesh_.faceCentres()));
106  const pointField& ctrs = tctrs();
107 
108  const searchableSurface& s = *surf_;
109 
110  // Face centres within the enclosing volumes
111 
112  List<volumeType> volTypes;
113  s.getVolumeType(ctrs, volTypes);
114 
115  const label len = volTypes.size();
116  for (label elemi = 0; elemi < len; ++elemi)
117  {
118  if (volTypes[elemi] == volumeType::INSIDE)
119  {
120  addOrDelete(set, elemi, add);
121  }
122  }
123 }
124 
125 
126 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
127 
129 (
130  const word& surfaceType,
131  const polyMesh& mesh,
132  const dictionary& dict
133 )
134 :
135  topoSetFaceSource(mesh, dict),
136  surf_
137  (
138  searchableSurface::New
139  (
140  surfaceType,
141  IOobject
142  (
143  getSurfaceName(dict, mesh.objectRegistry::db().name()),
144  mesh.time().constant(), // Instance
145  "triSurface", // Local
146  mesh.objectRegistry::db(), // Registry
147  IOobject::MUST_READ,
148  IOobject::NO_WRITE
149  ),
150  dict
151  )
152  )
153 {
154  // Check/warn for non-enclosed
155  if (surf_ && !surf_->hasVolumeType())
156  {
158  << nl << "The surface " << surf_->name() << " (type: "
159  << surf_->type() << ") appears to be unclosed ... ignoring"
160  << nl << endl;
162  surf_.clear();
163  }
164 }
165 
166 
168 (
169  const polyMesh& mesh,
170  const dictionary& dict
171 )
172 :
173  searchableSurfaceToFace
174  (
175  dict.getCompat<word>("surfaceType", {{"surface", 0}}),
176  mesh,
177  dict
178  )
179 {}
180 
181 
182 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
183 
185 (
186  const topoSetSource::setAction action,
187  topoSet& set
188 ) const
189 {
190  if (!surf_ || !surf_->hasVolumeType())
191  {
192  return;
193  }
194 
195  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
196  {
197  if (verbose_)
198  {
199  Info<< " Adding faces enclosed by surface '"
200  << surf_->name() << "' (type: " << surf_->type() << ") ..."
201  << endl;
202  }
203 
204  combine(set, true);
205  }
206  else if (action == topoSetSource::SUBTRACT)
207  {
208  if (verbose_)
209  {
210  Info<< " Removing faces enclosed by surface '"
211  << surf_->name() << "' (type: " << surf_->type() << ") ..."
212  << endl;
213  }
214 
215  combine(set, false);
216  }
217 }
218 
219 
220 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Create a new set and ADD elements to it.
Add elements to current set.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when &#39;add&#39; is true.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
setAction
Enumeration defining various actions.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
A location inside the volume.
Definition: volumeType.H:65
static word getSurfaceName(const dictionary &dict, word surfaceName)
const polyMesh & mesh_
Reference to the mesh.
const wordList surface
Standard surface field types (scalar, vector, tensor, etc)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
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...
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
const vectorField & faceCentres() const
Subtract elements from current set.
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
searchableSurfaceToFace(const word &surfaceType, const polyMesh &mesh, const dictionary &dict)
Construct surface-type from dictionary.
tmp< pointField > transform(const pointField &points) const
Coordinate transform (optionally) coordinates. Returns reference to input data if no transform is act...
messageStream Info
Information stream (stdout output on master, null elsewhere)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)