triSurfacePatchManipulator.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "helperFunctions.H"
30 #include "demandDrivenData.H"
31 #include "checkMeshDict.H"
32 
33 #include <map>
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
43 :
44  surf_(surface),
45  featureEdges_(surf_.edges().size(), direction(0)),
46  facetInPatch_(),
47  nPatches_(),
48  newPatchNames_(),
49  newPatchTypes_()
50 {
52 
53  createPatches();
54 }
55 
57 {}
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
62 (
64 ) const
65 {
66  graph.setSize(nPatches_);
67 
68  labelLongList nFacetsInPatch(nPatches_, 0);
69 
70  forAll(facetInPatch_, triI)
71  ++nFacetsInPatch[facetInPatch_[triI]];
72 
73  graph.setSizeAndRowSize(nFacetsInPatch);
74 
75  nFacetsInPatch = 0;
76  forAll(facetInPatch_, triI)
77  {
78  const label patchI = facetInPatch_[triI];
79 
80  graph(patchI, nFacetsInPatch[patchI]) = triI;
81  ++nFacetsInPatch[patchI];
82  }
83 }
84 
86 (
87  IOdictionary* meshDictPtr,
88  const word prefix,
89  const bool forceOverwrite
90 ) const
91 {
92  //- collect patch information
93  VRWGraph facetsInPatch;
94  detectedSurfaceRegions(facetsInPatch);
95 
96  //- create new list of boundary patches
97  LongList<labelledTri> newTriangles(facetInPatch_.size());
98  label counter(0);
99  geometricSurfacePatchList newPatches(nPatches_);
100 
101  if( forceOverwrite )
102  {
103  forAll(newPatches, patchI)
104  {
105  newPatches[patchI].name() = prefix+help::scalarToText(patchI);
106  newPatches[patchI].geometricType() = "patch";
107  newPatches[patchI].index() = patchI;
108  }
109  }
110  else
111  {
112  forAll(facetsInPatch, patchI)
113  {
114  forAllRow(facetsInPatch, patchI, fpI)
115  {
116  const label origPatchI =
117  surf_[facetsInPatch(patchI, fpI)].region();
118  newPatches[patchI].name() =
119  surf_.patches()[origPatchI].name() + '_' +
120  help::scalarToText(patchI);
121  newPatches[patchI].geometricType() =
122  surf_.patches()[origPatchI].geometricType();
123  newPatches[patchI].index() = patchI;
124  }
125  }
126  }
127 
128  //- create triangles for the new surface
129  labelLongList newFacetLabel(newTriangles.size(), -1);
130 
131  forAll(facetsInPatch, patchI)
132  forAllRow(facetsInPatch, patchI, tI)
133  {
134  newFacetLabel[facetsInPatch(patchI, tI)] = counter;
135  labelledTri tria = surf_[facetsInPatch(patchI, tI)];
136  tria.region() = patchI;
137  newTriangles[counter++] = tria;
138  }
139 
140  //- create and return a new surface mesh
141  triSurf* newSurfPtr =
142  new triSurf
143  (
144  newTriangles,
145  newPatches,
146  edgeLongList(),
147  surf_.points()
148  );
149 
150  //- transfer facet subsets
151  DynList<label> subsetIDs;
152  surf_.facetSubsetIndices(subsetIDs);
153  forAll(subsetIDs, subsetI)
154  {
155  const word sName = surf_.facetSubsetName(subsetIDs[subsetI]);
156 
157  const label newID = newSurfPtr->addFacetSubset(sName);
158 
159  labelLongList facetsInSubset;
160  surf_.facetsInSubset(subsetIDs[subsetI], facetsInSubset);
161 
162  forAll(facetsInSubset, i)
163  {
164  const label fI = newFacetLabel[facetsInSubset[i]];
165 
166  newSurfPtr->addFacetToSubset(newID, fI);
167  }
168  }
169 
170  //- transfer point subsets
171  surf_.pointSubsetIndices(subsetIDs);
172  forAll(subsetIDs, subsetI)
173  {
174  const word sName = surf_.pointSubsetName(subsetIDs[subsetI]);
175 
176  const label newID = newSurfPtr->addPointSubset(sName);
177 
178  labelLongList pointsInSubset;
179  surf_.pointsInSubset(subsetIDs[subsetI], pointsInSubset);
180 
181  forAll(pointsInSubset, i)
182  newSurfPtr->addPointToSubset(newID, pointsInSubset[i]);
183  }
184 
185  if( meshDictPtr )
186  {
187  //- create mapping between the patches on the original surface
188  //- and the renamed patches
189  std::map<word, wordList> patchesForPatch;
190  std::map<word, word> patchTypes;
191 
192  const geometricSurfacePatchList& origPatches = surf_.patches();
193  forAll(origPatches, patchI)
194  patchTypes[origPatches[patchI].name()] =
195  origPatches[patchI].geometricType();
196 
197  //- find the mapping of patch ids
198  List<labelHashSet> patchToNewPatches(origPatches.size());
199  forAll(facetsInPatch, patchI)
200  {
201  forAllRow(facetsInPatch, patchI, fI)
202  {
203  const label opatchI = surf_[facetsInPatch(patchI, fI)].region();
204 
205  patchToNewPatches[opatchI].insert(patchI);
206  }
207  }
208 
209  forAll(patchToNewPatches, patchI)
210  {
211  const word& pName = origPatches[patchI].name();
212  patchesForPatch[pName].setSize
213  (
214  patchToNewPatches[patchI].size()
215  );
216 
217  label counter(0);
218 
219  forAllConstIter(labelHashSet, patchToNewPatches[patchI], it)
220  patchesForPatch[pName][counter++] = newPatches[it.key()].name();
221  }
222 
223  //- update the values in meshDict based on the created patches
224  checkMeshDict(*meshDictPtr).updateDictionaries
225  (
226  patchesForPatch,
227  patchTypes
228  );
229  }
230 
231  return newSurfPtr;
232 }
233 
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 
236 } // End namespace Foam
237 
238 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::triSurfacePatchManipulator::detectedSurfaceRegions
void detectedSurfaceRegions(VRWGraph &) const
Definition: triSurfacePatchManipulator.C:62
Foam::triSurfacePatchManipulator::~triSurfacePatchManipulator
~triSurfacePatchManipulator()
Definition: triSurfacePatchManipulator.C:56
Foam::graph
Class to create, store and output qgraph files.
Definition: graph.H:58
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::triSurfacePatchManipulator::triSurfacePatchManipulator
triSurfacePatchManipulator(const triSurfacePatchManipulator &)
Disallow default bitwise copy construct.
triSurfacePatchManipulator.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::help::scalarToText
word scalarToText(const scalar s)
convert the scalar value into text
Definition: helperFunctionsStringConversion.C:61
Foam::checkMeshDict
Definition: checkMeshDict.H:50
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::HashSet< label, Hash< label > >
Foam::triSurfPoints::addPointSubset
label addPointSubset(const word &)
point subsets
Definition: triSurfPoints.C:54
patchTypes
wordList patchTypes(nPatches)
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::LongList< label >
Foam::triSurfFacets::addFacetToSubset
void addFacetToSubset(const label, const label)
Definition: triSurfFacetsI.H:60
checkMeshDict.H
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::triSurfPoints::addPointToSubset
void addPointToSubset(const label, const label)
Definition: triSurfPointsI.H:57
Foam::triSurfacePatchManipulator::surfaceWithPatches
const triSurf * surfaceWithPatches(IOdictionary *meshDictPtr=NULL, const word prefix="patch_", const bool forceOverwrite=false) const
store regions into subsets with a given prefix
Definition: triSurfacePatchManipulator.C:86
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::triSurfFacets::addFacetSubset
label addFacetSubset(const word &)
point subsets
Definition: triSurfFacets.C:105
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::triSurfacePatchManipulator::allocateFeatureEdges
void allocateFeatureEdges()
allocate and fill the feature edges list
Definition: triSurfacePatchManipulatorFunctions.C:43
Foam::DynList< label >
Foam::checkMeshDict::updateDictionaries
void updateDictionaries(const std::map< word, wordList > &patchesForPatch, const std::map< word, word > &patchTypes, const bool renamePatches=true)
update meshDict based on modification of patches in the surface
Definition: checkMeshDict.C:1282
Foam::labelledTri::region
label region() const
Return region label.
Definition: labelledTriI.H:68
helperFunctions.H
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
Foam::surface
Definition: surface.H:55
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::edgeLongList
LongList< edge > edgeLongList
Definition: edgeLongList.H:46
Foam::triSurfacePatchManipulator::createPatches
void createPatches()
create patches bounded by a set of feature edges
Definition: triSurfacePatchManipulatorFunctions.C:68
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::triSurf
Definition: triSurf.H:59