Loading...
Searching...
No Matches
subTriSurfaceMesh.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) 2015-2019 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
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
34{
37 (
40 dict
41 );
42}
43
44
45// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46
47Foam::wordList Foam::subTriSurfaceMesh::patchNames(const triSurface& s)
48{
49 const auto& patches = s.patches();
50
51 wordList names(patches.size());
52 forAll(patches, patchi)
53 {
54 names[patchi] = patches[patchi].name();
55 }
56 return names;
57}
58
59
60Foam::labelList Foam::subTriSurfaceMesh::selectedRegions
61(
62 const triSurface& s,
63 const wordRes& regionNameMatcher
64)
65{
66 const wordList names(patchNames(s));
67
68 labelList regionIds(names.size());
69
70 label count = 0;
71
72 forAll(names, regioni)
73 {
74 if (regionNameMatcher.match(names[regioni]))
75 {
76 regionIds[count++] = regioni;
77 }
78 }
79 regionIds.setSize(count);
80
81 return regionIds;
82}
83
84
85Foam::triSurface Foam::subTriSurfaceMesh::subset
86(
87 const IOobject& io,
88 const dictionary& dict
89)
90{
91 const word subGeomName(dict.get<word>("surface"));
92
93 const triSurfaceMesh& s =
94 io.db().lookupObject<triSurfaceMesh>(subGeomName);
95
96 if (s.type() == "distributedTriSurfaceMesh")
97 {
99 << "Found surface " << subGeomName << " of type " << s.type()
100 << ". subTriSurfaceMesh only works with non-distributed surfaces."
101 << endl;
102 }
103
104 const wordRes regionNames(dict.get<wordRes>("patches"));
105
106 labelList regionMap(selectedRegions(s, regionNames));
107
108 if (regionMap.empty())
109 {
111 << "Found no regions in triSurface matching " << regionNames
112 << ". Valid regions are " << patchNames(s)
113 << exit(FatalIOError);
114 }
115
116 labelList reverseRegionMap(s.patches().size(), -1);
117 forAll(regionMap, i)
118 {
119 reverseRegionMap[regionMap[i]] = i;
120 }
121
122 boolList isSelected(s.size(), false);
123 forAll(s, triI)
124 {
125 if (reverseRegionMap[s.triSurface::operator[](triI).region()] != -1)
126 {
127 isSelected[triI] = true;
128 }
129 }
131 return s.subsetMesh(isSelected);
132}
133
134
135// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
136
138(
139 const IOobject& io,
140 const dictionary& dict
141)
142:
144{}
145
146
147// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#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:191
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition IOobject.C:450
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
wordList names() const
The unsorted names of all objects.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
On-the-fly subset of triSurfaceMesh (based on selected patches).
subTriSurfaceMesh(const IOobject &io, const dictionary &dict)
Construct from IO and dictionary.
IOoject and searching on triSurface.
triSurfaceMesh(const triSurfaceMesh &)=delete
No copy construct.
Triangulated surface description with patch information.
Definition triSurface.H:74
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
const polyBoundaryMesh & patches
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
const auto & io
auto & names
wordList regionNames
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 IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition BitOps.H:73
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
List< bool > boolList
A List of bools.
Definition List.H:60
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
wordList patchNames(nPatches)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299