triSurfaceRemoveFacetsFunctions.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 
28 #include "triSurfaceRemoveFacets.H"
29 #include "triSurfModifier.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
39 {
40  removeFacet.setSize(surf_.size());
41  removeFacet = false;
42 
44 
45  //- mark patches which will be removed
46  boolList removePatch(patches.size(), false);
47 
48  forAll(patches, patchI)
49  {
50  if( selectedEntities_.contains(patches[patchI].name()) )
51  removePatch[patchI] = true;
52  }
53 
54  //- select facets affected by the deletion of a patch
55  forAll(surf_, triI)
56  {
57  if( removePatch[surf_[triI].region()] )
58  removeFacet[triI] = true;
59  }
60 
61  //- mark facets contained in selected subsets
62  DynList<label> facetSubsetsIDs;
63  surf_.facetSubsetIndices(facetSubsetsIDs);
64 
65  forAll(facetSubsetsIDs, i)
66  {
67  const word fsName = surf_.facetSubsetName(facetSubsetsIDs[i]);
68 
69  if( selectedEntities_.contains(fsName) )
70  {
71  labelLongList containedFacets;
72  surf_.facetsInSubset(facetSubsetsIDs[i], containedFacets);
73 
74  forAll(containedFacets, cfI)
75  removeFacet[containedFacets[cfI]] = true;
76  }
77  }
78 }
79 
81 {
82  boolList removeFacet;
83  markFacetsForRemoval(removeFacet);
84 
85  //- calculate new indices of vertices and facets
86  const pointField& points = surf_.points();
87  labelLongList newPointLabel(surf_.points().size(), -1);
88  labelLongList newFacetLabel(surf_.size(), -1);
89 
90  label pointCounter(0), facetCounter(0);
91 
92  forAll(removeFacet, triI)
93  {
94  if( removeFacet[triI] )
95  continue;
96 
97  const labelledTri& tri = surf_[triI];
98 
99  forAll(tri, pI)
100  {
101  if( newPointLabel[tri[pI]] == -1 )
102  newPointLabel[tri[pI]] = pointCounter++;
103  }
104 
105  newFacetLabel[triI] = facetCounter++;
106  }
107 
108  //- remove vertices
109  pointField newPts(pointCounter);
110  forAll(newPointLabel, pI)
111  {
112  if( newPointLabel[pI] < 0 )
113  continue;
114 
115  newPts[newPointLabel[pI]] = points[pI];
116  }
117 
118  triSurfModifier(surf_).pointsAccess().transfer(newPts);
119  surf_.updatePointSubsets(newPointLabel);
120 
121  //- remove facets
122  LongList<labelledTri> newFacets(facetCounter);
123 
124  forAll(newFacetLabel, triI)
125  {
126  if( newFacetLabel[triI] < 0 )
127  continue;
128 
129  const labelledTri& tri = surf_[triI];
130 
131  newFacets[newFacetLabel[triI]] =
133  (
134  newPointLabel[tri[0]],
135  newPointLabel[tri[1]],
136  newPointLabel[tri[2]],
137  tri.region()
138  );
139  }
140 
141  triSurfModifier(surf_).facetsAccess().transfer(newFacets);
142  surf_.updateFacetsSubsets(newFacetLabel);
143 
144  //- update feature edges
145  const edgeLongList& featureEdges = surf_.featureEdges();
146  const VRWGraph& pointEdges = surf_.pointEdges();
147  const edgeLongList& edges = surf_.edges();
148  const VRWGraph& edgeFacets = surf_.edgeFacets();
149 
150  label edgeCounter(0);
151  labelLongList newFeatureEdgeLabel(featureEdges.size(), -1);
152 
153  forAll(featureEdges, feI)
154  {
155  const edge& e = featureEdges[feI];
156 
157  if( (newPointLabel[e.start()] < 0) || (newPointLabel[e.end()] < 0) )
158  continue;
159 
160  //- find global edge label
161  label eI(-1);
162  forAllRow(pointEdges, e.start(), peI)
163  {
164  const label eJ = pointEdges(e.start(), peI);
165  if( edges[eJ] == e )
166  {
167  eI = eJ;
168  break;
169  }
170  }
171 
172  if( eI < 0 )
173  continue;
174 
175  //- check if the edge is attached to at least one triangle
176  bool foundTriangle(false);
177  forAllRow(edgeFacets, eI, efI)
178  {
179  if( newFacetLabel[edgeFacets(eI, efI)] >= 0 )
180  {
181  foundTriangle = true;
182  break;
183  }
184  }
185  if( !foundTriangle )
186  continue;
187 
188  newFeatureEdgeLabel[feI] = edgeCounter++;
189  }
190 
191  edgeLongList newFeatureEdges(edgeCounter);
192  forAll(newFeatureEdgeLabel, eI)
193  {
194  if( newFeatureEdgeLabel[eI] < 0 )
195  continue;
196 
197  const edge& e = featureEdges[eI];
198 
199  newFeatureEdges[newFeatureEdgeLabel[eI]] =
200  edge
201  (
202  newPointLabel[e.start()],
203  newPointLabel[e.end()]
204  );
205  }
206 
207  triSurfModifier(surf_).featureEdgesAccess().transfer(newFeatureEdges);
208  surf_.updateEdgeSubsets(newFeatureEdgeLabel);
209 
210  selectedEntities_.clear();
211 }
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 } // End namespace Foam
216 
217 // ************************************************************************* //
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::triSurfPoints::points
const pointField & points() const
access to points
Definition: triSurfPointsI.H:44
Foam::triSurfaceRemoveFacets::markFacetsForRemoval
void markFacetsForRemoval(boolList &) const
remove facets in selected patches/subsets
Definition: triSurfaceRemoveFacetsFunctions.C:38
Foam::triSurfPoints::updatePointSubsets
void updatePointSubsets(const ListType &)
Definition: triSurfPointsI.H:133
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
triSurfModifier.H
Foam::triSurfModifier
Definition: triSurfModifier.H:48
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::triSurfFeatureEdges::featureEdges
const edgeLongList & featureEdges() const
access to feature edges
Definition: triSurfFeatureEdgesI.H:44
Foam::LongList< label >
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::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::triSurfModifier::pointsAccess
pointField & pointsAccess()
non-const access to points
Definition: triSurfModifierI.H:37
Foam::triSurfFacets::patches
const geometricSurfacePatchList & patches() const
access to patches
Definition: triSurfFacetsI.H:49
Foam::LongList::transfer
void transfer(LongList< T, Offset > &)
transfer the list from another one without allocating it
Definition: LongListI.H:245
Foam::triSurfModifier::facetsAccess
LongList< labelledTri > & facetsAccess()
access to facets
Definition: triSurfModifierI.H:42
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::triSurfaceRemoveFacets::removeFacets
void removeFacets()
perform removal of selected facets
Definition: triSurfaceRemoveFacetsFunctions.C:80
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::DynList< label >
Foam::triSurfFeatureEdges::updateEdgeSubsets
void updateEdgeSubsets(const ListType &)
Definition: triSurfFeatureEdgesI.H:134
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::triSurfModifier::featureEdgesAccess
edgeLongList & featureEdgesAccess()
non-const access to feature edges
Definition: triSurfModifierI.H:47
Foam::triSurfFacets::facetSubsetIndices
void facetSubsetIndices(DynList< label > &) const
Definition: triSurfFacetsI.H:105
Foam::triSurfFacets::size
label size() const
return the number of triangles
Definition: triSurfFacetsI.H:39
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
points
const pointField & points
Definition: gmvOutputHeader.H:1
triSurfaceRemoveFacets.H
Foam::triSurfAddressing::edges
const LongList< edge > & edges() const
return edges
Definition: triSurfAddressingI.H:61
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::triSurfFacets::updateFacetsSubsets
void updateFacetsSubsets(const ListType &)
Definition: triSurfFacetsI.H:135
Foam::triSurfFacets::facetSubsetName
word facetSubsetName(const label) const
Definition: triSurfFacets.C:135
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::triSurfFacets::facetsInSubset
void facetsInSubset(const label, ListType &) const
Definition: triSurfFacetsI.H:120
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::triSurfAddressing::edgeFacets
const VRWGraph & edgeFacets() const
return edge-facets addressing
Definition: triSurfAddressingI.H:97
Foam::triSurfAddressing::pointEdges
const VRWGraph & pointEdges() const
return point-edges addressing
Definition: triSurfAddressingI.H:115
Foam::triSurfaceRemoveFacets::selectedEntities_
DynList< word > selectedEntities_
patches/subsets for removal
Definition: triSurfaceRemoveFacets.H:57
Foam::triSurfaceRemoveFacets::surf_
triSurf & surf_
reference to triSurf
Definition: triSurfaceRemoveFacets.H:54