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 -------------------------------------------------------------------------------
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 
28 #include "subTriSurfaceMesh.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(subTriSurfaceMesh, 0);
37  (
38  searchableSurface,
39  subTriSurfaceMesh,
40  dict
41  );
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 Foam::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 
60 Foam::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 
85 Foam::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 :
135  triSurfaceMesh(io, subset(io, dict))
136 {}
137 
138 
139 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
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::subset
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:65
Foam::FatalIOError
IOerror FatalIOError
Foam::triSurfaceMesh
IOoject and searching on triSurface.
Definition: triSurfaceMesh.H:106
subTriSurfaceMesh.H
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::triSurface::patches
const geometricSurfacePatchList & patches() const noexcept
Definition: triSurface.H:399
regionNames
wordList regionNames
Definition: getAllRegionOptions.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
Foam::subTriSurfaceMesh::subTriSurfaceMesh
subTriSurfaceMesh(const IOobject &io, const dictionary &dict)
Construct from IO and dictionary.
Definition: subTriSurfaceMesh.C:130
patchNames
wordList patchNames(nPatches)
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
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::objectRegistry::names
wordList names() const
The names of all objects.
Definition: objectRegistry.C:147
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::List< word >
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)