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-2020 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 centre enclosed by the surface"
65  "\n"
66 );
67 
68 
69 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
70 
72 (
73  const dictionary& dict,
74  const word& defaultName
75 )
76 {
77  // Unfortunately cannot get a good default name from the dictionary name.
78  // It could be
79  // sourceInfo { .. }
80  // But even with something like
81  // mySurf.stl { .. }
82  // The dictName() method will only return the "stl" ending.
83 
84  return dict.getOrDefault<word>("surfaceName", defaultName);
85 }
86 
87 
88 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
89 
90 void Foam::searchableSurfaceToFace::combine(topoSet& set, const bool add) const
91 {
92  if (!surf_)
93  {
94  return;
95  }
96  const pointField& ctrs = mesh_.faceCentres();
97  const searchableSurface& s = *surf_;
98 
99  // Face centres within the enclosing volumes
100 
101  List<volumeType> volTypes;
102  s.getVolumeType(ctrs, volTypes);
103 
104  const label len = volTypes.size();
105  for (label elemi = 0; elemi < len; ++elemi)
106  {
107  if (volTypes[elemi] == volumeType::INSIDE)
108  {
109  addOrDelete(set, elemi, add);
110  }
111  }
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
118 (
119  const word& surfaceType,
120  const polyMesh& mesh,
121  const dictionary& dict
122 )
123 :
125  surf_
126  (
128  (
129  surfaceType,
130  IOobject
131  (
132  getSurfaceName(dict, mesh.objectRegistry::db().name()),
133  mesh.time().constant(), // Instance
134  "triSurface", // Local
135  mesh.objectRegistry::db(), // Registry
138  ),
139  dict
140  )
141  )
142 {
143  // Check/warn for non-enclosed
144  if (surf_ && !surf_->hasVolumeType())
145  {
147  << nl << "The surface " << surf_->name() << " (type: "
148  << surf_->type() << ") appears to be unclosed ... ignoring"
149  << nl << endl;
150 
151  surf_.clear();
152  }
153 }
154 
155 
157 (
158  const polyMesh& mesh,
159  const dictionary& dict
160 )
161 :
163  (
164  dict.getCompat<word>("surfaceType", {{"surface", 0}}),
165  mesh,
166  dict
167  )
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
174 (
175  const topoSetSource::setAction action,
176  topoSet& set
177 ) const
178 {
179  if (!surf_ || !surf_->hasVolumeType())
180  {
181  return;
182  }
183 
184  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
185  {
186  if (verbose_)
187  {
188  Info<< " Adding faces enclosed by surface '"
189  << surf_->name() << "' (type: " << surf_->type() << ") ..."
190  << endl;
191  }
192 
193  combine(set, true);
194  }
195  else if (action == topoSetSource::SUBTRACT)
196  {
197  if (verbose_)
198  {
199  Info<< " Removing faces enclosed by surface '"
200  << surf_->name() << "' (type: " << surf_->type() << ") ..."
201  << endl;
202  }
203 
204  combine(set, false);
205  }
206 }
207 
208 
209 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
s
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))
Definition: gmvOutputSpray.H:25
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::topoSetFaceSource
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
Definition: topoSetFaceSource.H:54
Foam::searchableSurfaceToFace::getSurfaceName
static word getSurfaceName(const dictionary &dict, const word &defaultName)
Retrieve surface name from dictionary entry.
Definition: searchableSurfaceToFace.C:72
Foam::dictionary::getCompat
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Definition: dictionaryTemplates.C:134
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::searchableSurfaceToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: searchableSurfaceToFace.C:174
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::searchableSurfaceToFace
A topoSetFaceSource to select faces whose face centre enclosed by a given searchableSurface.
Definition: searchableSurfaceToFace.H:153
Foam::topoSetSource::SUBTRACT
Subtract elements from current set.
Definition: topoSetSource.H:105
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::searchableSurface::New
static autoPtr< searchableSurface > New(const word &surfaceType, const IOobject &io, const dictionary &dict)
Return a reference to the selected searchableSurface.
Definition: searchableSurface.C:43
searchableSurfaceToFace.H
Time.H
Foam::searchableSurfaceToFace::searchableSurfaceToFace
searchableSurfaceToFace(const word &surfaceType, const polyMesh &mesh, const dictionary &dict)
Construct surface-type from dictionary.
Definition: searchableSurfaceToFace.C:118
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::primitiveMesh::faceCentres
const vectorField & faceCentres() const
Definition: primitiveMeshFaceCentresAndAreas.C:77
Foam::volumeType::INSIDE
A location inside the volume.
Definition: volumeType.H:68
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:171
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:300
Foam::IOobject::MUST_READ
Definition: IOobject.H:185