searchableSurfaceToCell.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-------------------------------------------------------------------------------
10License
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
35namespace Foam
36{
39 (
42 word
43 );
45 (
48 word
49 );
51 (
54 word,
55 surface
56 );
57}
58
59
60Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToCell::usage_
61(
62 searchableSurfaceToCell::typeName,
63 "\n Usage: searchableSurfaceToCell surface\n\n"
64 " Select cells with centre enclosed by the surface"
65 "\n"
66);
67
68
69// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
70
71namespace 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
81static 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
99void Foam::searchableSurfaceToCell::combine(topoSet& set, const bool add) const
100{
101 if (!surf_)
102 {
103 return;
104 }
105 const pointField& ctrs = mesh_.cellCentres();
106 const searchableSurface& s = *surf_;
107
108 // Cell centres within the enclosing volumes
109
110 List<volumeType> volTypes;
111 s.getVolumeType(ctrs, volTypes);
112
113 const label len = volTypes.size();
114 for (label elemi=0; elemi < len; ++elemi)
115 {
116 if (volTypes[elemi] == volumeType::INSIDE)
117 {
118 addOrDelete(set, elemi, add);
119 }
120 }
121}
122
123
124// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
125
127(
128 const word& surfaceType,
129 const polyMesh& mesh,
130 const dictionary& dict
131)
132:
134 surf_
135 (
137 (
138 surfaceType,
140 (
142 mesh.time().constant(), // Instance
143 "triSurface", // Local
144 mesh.objectRegistry::db(), // Registry
145 IOobject::MUST_READ,
146 IOobject::NO_WRITE
147 ),
148 dict
149 )
150 )
151{
152 // Check/warn for non-enclosed
153 if (surf_ && !surf_->hasVolumeType())
154 {
156 << nl << "The surface " << surf_->name() << " (type: "
157 << surf_->type() << ") appears to be unclosed ... ignoring"
158 << nl << endl;
159
160 surf_.clear();
161 }
162}
163
164
166(
167 const polyMesh& mesh,
168 const dictionary& dict
169)
170:
172 (
173 dict.getCompat<word>("surfaceType", {{"surface", 0}}),
174 mesh,
175 dict
176 )
177{}
178
179
180// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181
183(
184 const topoSetSource::setAction action,
185 topoSet& set
186) const
187{
188 if (!surf_ || !surf_->hasVolumeType())
189 {
190 return;
191 }
192
193 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
194 {
195 if (verbose_)
196 {
197 Info<< " Adding cells enclosed by surface '"
198 << surf_->name() << "' (type: " << surf_->type() << ") ..."
199 << endl;
200 }
201
202 combine(set, true);
203 }
204 else if (action == topoSetSource::SUBTRACT)
205 {
206 if (verbose_)
207 {
208 Info<< " Removing cells enclosed by surface '"
209 << surf_->name() << "' (type: " << surf_->type() << ") ..."
210 << endl;
211 }
212
213 combine(set, false);
214 }
215}
216
217
218// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Registry of regIOobjects.
constant condensation/saturation model.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const vectorField & cellCentres() const
A topoSetCellSource to select cells whose cell centre enclosed by a given searchableSurface.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
Definition: topoSetSource.H:68
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
const polyMesh & mesh_
Reference to the mesh.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:67
@ INSIDE
A location inside the volume.
Definition: volumeType.H:68
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
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))
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
static word getSurfaceName(const dictionary &dict, word surfaceName)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dict add("bounds", meshBb)
dictionary dict