searchableSurfaceToPoint.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(searchableSurfaceToPoint, 0);
39  (
40  topoSetSource,
41  searchableSurfaceToPoint,
42  word
43  );
45  (
46  topoSetPointSource,
47  searchableSurfaceToPoint,
48  word
49  );
51  (
52  topoSetPointSource,
53  searchableSurfaceToPoint,
54  word,
55  surface
56  );
57 }
58 
59 
60 Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToPoint::usage_
61 (
62  searchableSurfaceToPoint::typeName,
63  "\n Usage: searchableSurfaceToPoint surface\n\n"
64  " Select points 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::searchableSurfaceToPoint::combine(topoSet& set, const bool add) const
91 {
92  if (!surf_)
93  {
94  return;
95  }
96  const searchableSurface& s = *surf_;
97 
98  // Mesh points within the enclosing volumes
99 
100  List<volumeType> volTypes;
101  s.getVolumeType(mesh_.points(), volTypes);
102 
103  const label len = volTypes.size();
104  for (label id=0; id < len; ++id)
105  {
106  if (volTypes[id] == volumeType::INSIDE)
107  {
108  addOrDelete(set, id, add);
109  }
110  }
111 }
112 
113 
114 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
115 
117 (
118  const word& surfaceType,
119  const polyMesh& mesh,
120  const dictionary& dict
121 )
122 :
124  surf_
125  (
127  (
128  surfaceType,
129  IOobject
130  (
131  getSurfaceName(dict, mesh.objectRegistry::db().name()),
132  mesh.time().constant(), // Instance
133  "triSurface", // Local
134  mesh.objectRegistry::db(), // Registry
137  ),
138  dict
139  )
140  )
141 {
142  // Check/warn for non-enclosed
143  if (surf_ && !surf_->hasVolumeType())
144  {
146  << nl << "The surface " << surf_->name() << " (type: "
147  << surf_->type() << ") appears to be unclosed ... ignoring"
148  << nl << endl;
149 
150  surf_.clear();
151  }
152 }
153 
154 
156 (
157  const polyMesh& mesh,
158  const dictionary& dict
159 )
160 :
162  (
163  dict.getCompat<word>("surfaceType", {{"surface", 0}}),
164  mesh,
165  dict
166  )
167 {}
168 
169 
170 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
171 
173 (
174  const topoSetSource::setAction action,
175  topoSet& set
176 ) const
177 {
178  if (!surf_ || !surf_->hasVolumeType())
179  {
180  return;
181  }
182 
183  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
184  {
185  if (verbose_)
186  {
187  Info<< " Adding points enclosed by surface '"
188  << surf_->name() << "' (type: " << surf_->type() << ") ..."
189  << endl;
190  }
191 
192  combine(set, true);
193  }
194  else if (action == topoSetSource::SUBTRACT)
195  {
196  if (verbose_)
197  {
198  Info<< " Removing points enclosed by surface '"
199  << surf_->name() << "' (type: " << surf_->type() << ") ..."
200  << endl;
201  }
202 
203  combine(set, false);
204  }
205 }
206 
207 
208 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
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::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::searchableSurfaceToPoint
A topoSetPointSource to select points which are centre enclosed by a given searchableSurface.
Definition: searchableSurfaceToPoint.H:153
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
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)
searchableSurfaceToPoint.H
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::topoSetPointSource
The topoSetPointSource is a intermediate class for handling topoSet sources for selecting points.
Definition: topoSetPointSource.H:54
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::searchableSurfaceToPoint::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: searchableSurfaceToPoint.C:173
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::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
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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)
Foam::searchableSurfaceToPoint::getSurfaceName
static word getSurfaceName(const dictionary &dict, const word &defaultName)
Retrieve surface name from dictionary entry.
Definition: searchableSurfaceToPoint.C:72
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::searchableSurfaceToPoint::searchableSurfaceToPoint
searchableSurfaceToPoint(const word &surfaceType, const polyMesh &mesh, const dictionary &dict)
Construct surface-type from dictionary.
Definition: searchableSurfaceToPoint.C:117
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:300
Foam::IOobject::MUST_READ
Definition: IOobject.H:185