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
28#include "subTriSurfaceMesh.H"
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
34{
37 (
40 dict
41 );
42}
43
44
45// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46
48{
49 const auto& patches = s.patches();
50
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 const wordRes regionNames(dict.get<wordRes>("patches"));
97
98 labelList regionMap(selectedRegions(s, regionNames));
99
100 if (regionMap.empty())
101 {
103 << "Found no regions in triSurface matching " << regionNames
104 << ". Valid regions are " << patchNames(s)
105 << exit(FatalIOError);
106 }
107
108 labelList reverseRegionMap(s.patches().size(), -1);
109 forAll(regionMap, i)
110 {
111 reverseRegionMap[regionMap[i]] = i;
112 }
113
114 boolList isSelected(s.size(), false);
115 forAll(s, triI)
116 {
117 if (reverseRegionMap[s.triSurface::operator[](triI).region()] != -1)
118 {
119 isSelected[triI] = true;
120 }
121 }
122
123 return s.subsetMesh(isSelected);
124}
125
126
127// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128
130(
131 const IOobject& io,
132 const dictionary& dict
133)
134:
136{}
137
138
139// ************************************************************************* //
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:170
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:500
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
wordList patchNames() const
Get names of patches.
Definition: boundaryMesh.C:275
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
wordList names() const
The unsorted names of all objects.
const Type & lookupObject(const word &name, const bool recursive=false) const
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
On-the-fly subset of triSurfaceMesh (based on selected patches)
IOoject and searching on triSurface.
Triangulated surface description with patch information.
Definition: triSurface.H:79
const geometricSurfacePatchList & patches() const noexcept
Definition: triSurface.H:399
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
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))
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:78
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:63
List< label > labelList
A List of labels.
Definition: List.H:66
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
IOerror FatalIOError
List< bool > boolList
A List of bools.
Definition: List.H:64
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
wordList patchNames(nPatches)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333