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 | Copyright (C) 2015 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "subTriSurfaceMesh.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 defineTypeNameAndDebug(subTriSurfaceMesh, 0);
35 addToRunTimeSelectionTable(searchableSurface, subTriSurfaceMesh, dict);
36 
37 }
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
42 {
43  const geometricSurfacePatchList& patches = s.patches();
44 
46  forAll(patches, patchI)
47  {
48  names[patchI] = patches[patchI].name();
49  }
50  return names;
51 }
52 
53 
55 (
56  const triSurface& s,
57  const wordReList& regionNames
58 )
59 {
60  const wordList names(patchNames(s));
61 
62  labelList regions(names.size());
63 
64  label compactI = 0;
65 
66  forAll(names, regionI)
67  {
68  const word& name = names[regionI];
69 
70  forAll(regionNames, i)
71  {
72  if (regionNames[i].match(name))
73  {
74  regions[compactI++] = regionI;
75  }
76  }
77  }
78  regions.setSize(compactI);
79 
80  return regions;
81 }
82 
83 
85 (
86  const IOobject& io,
87  const dictionary& dict
88 )
89 {
90  const word subGeomName(dict.lookup("surface"));
91 
92  const triSurfaceMesh& s =
93  io.db().lookupObject<triSurfaceMesh>(subGeomName);
94 
95  const wordReList regionNames(dict.lookup("patches"));
96 
97  labelList regionMap(selectedRegions(s, regionNames));
98 
99  if (regionMap.size() == 0)
100  {
102  << "Found no regions in triSurface matching " << regionNames
103  << ". Valid regions are " << patchNames(s)
104  << exit(FatalIOError);
105  }
106 
107  labelList reverseRegionMap(s.patches().size(), -1);
108  forAll(regionMap, i)
109  {
110  reverseRegionMap[regionMap[i]] = i;
111  }
112 
113  boolList isSelected(s.size(), false);
114  forAll(s, triI)
115  {
116  if (reverseRegionMap[s.triSurface::operator[](triI).region()] != -1)
117  {
118  isSelected[triI] = true;
119  }
120  }
121 
122  labelList pointMap;
124  return s.subsetMesh(isSelected, pointMap, faceMap);
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
129 
131 (
132  const IOobject& io,
133  const dictionary& dict
134 )
135 :
136  triSurfaceMesh(io, subset(io, dict))
137 {}
138 
139 
140 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
141 
143 {}
144 
145 
146 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::subTriSurfaceMesh::patchNames
static wordList patchNames(const triSurface &s)
Extract patch names of triSurface.
Definition: subTriSurfaceMesh.C:41
Foam::FatalIOError
IOerror FatalIOError
Foam::triSurfaceMesh
IOoject and searching on triSurface.
Definition: triSurfaceMesh.H:63
subTriSurfaceMesh.H
Foam::triSurface::patches
const geometricSurfacePatchList & patches() const
Definition: triSurface.H:301
Foam::IOobject::db
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:239
Foam::subTriSurfaceMesh::selectedRegions
static labelList selectedRegions(const triSurface &s, const wordReList &regionNames)
Select regions by name.
Definition: subTriSurfaceMesh.C:55
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::subTriSurfaceMesh::subTriSurfaceMesh
subTriSurfaceMesh(const IOobject &io, const dictionary &dict)
Construct from IO and dictionary.
Definition: subTriSurfaceMesh.C:131
patchNames
wordList patchNames(nPatches)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::subTriSurfaceMesh::~subTriSurfaceMesh
virtual ~subTriSurfaceMesh()
Destructor.
Definition: subTriSurfaceMesh.C:142
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().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))
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::subset
ListType subset(const UList< T > &select, const T &value, const ListType &)
Extract elements of List when select is a certain value.
Definition: ListOpsTemplates.C:290
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::subTriSurfaceMesh::subset
static triSurface subset(const IOobject &, const dictionary &)
Subset triSurface based on regions.
Definition: subTriSurfaceMesh.C:85
Foam::objectRegistry::names
wordList names() const
Return the list of names of the IOobjects.
Definition: objectRegistry.C:115
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47