triSurfaceCopyParts.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 "triSurfaceCopyParts.H"
29 #include "triSurfModifier.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
39 (
40  const wordList& parts,
41  boolList& copyFacets
42 ) const
43 {
44  copyFacets.setSize(surf_.size());
45  copyFacets = false;
46 
47  const geometricSurfacePatchList& patches = surf_.patches();
48 
49  //- mark patches which will be copied
50  boolList copyPatch(patches.size(), false);
51 
52  forAll(patches, patchI)
53  {
54  const word name = patches[patchI].name();
55 
56  forAll(parts, partI)
57  {
58  if( parts[partI] == name )
59  {
60  copyPatch[patchI] = true;
61  break;
62  }
63  }
64  }
65 
66  //- select facets affected by the deletion of a patch
67  forAll(surf_, triI)
68  {
69  if( copyPatch[surf_[triI].region()] )
70  copyFacets[triI] = true;
71  }
72 
73  //- mark facets contained in selected subsets
74  DynList<label> facetSubsetsIDs;
75  surf_.facetSubsetIndices(facetSubsetsIDs);
76 
77  forAll(facetSubsetsIDs, i)
78  {
79  const word fsName = surf_.facetSubsetName(facetSubsetsIDs[i]);
80 
81  forAll(parts, partI)
82  {
83  if( parts[partI] == fsName )
84  {
85  labelLongList containedFacets;
86  surf_.facetsInSubset(facetSubsetsIDs[i], containedFacets);
87 
88  forAll(containedFacets, cfI)
89  copyFacets[containedFacets[cfI]] = true;
90 
91  break;
92  }
93  }
94  }
95 }
96 
98 (
99  const boolList& copyFacets,
100  triSurf& s
101 ) const
102 {
103  Info << "Starting copying surface parts" << endl;
104 
105  const pointField& pts = surf_.points();
106 
107  labelLongList newPointLabel(pts.size(), -1);
108 
109  label nPoints(0);
110 
111  //- create the modifier and delete data if there is any
112  triSurfModifier sm(s);
113  sm.facetsAccess().clear();
114  sm.featureEdgesAccess().clear();
115  sm.patchesAccess().setSize(surf_.patches().size());
116  forAll(surf_.patches(), patchI)
117  sm.patchesAccess()[patchI] = surf_.patches()[patchI];
118 
119  //- copy selected patches
120  labelLongList newTriangleLabel(surf_.size(), -1);
121  forAll(copyFacets, triI)
122  {
123  if( !copyFacets[triI] )
124  continue;
125 
126  const labelledTri& tri = surf_[triI];
127 
128  labelledTri newTri;
129  newTri.region() = tri.region();
130 
131  forAll(tri, pI)
132  {
133  if( newPointLabel[tri[pI]] == -1 )
134  {
135  newPointLabel[tri[pI]] = nPoints;
136  ++nPoints;
137  }
138 
139  newTri[pI] = newPointLabel[tri[pI]];
140  }
141 
142  newTriangleLabel[triI] = s.size();
143  s.appendTriangle(newTri);
144  }
145 
146  Info << "Copied triangles " << s.size() << endl;
147  Info << "Number of vertices " << nPoints << endl;
148 
149  //- copy vertices
150  pointField& newPts = sm.pointsAccess();
151  newPts.setSize(nPoints);
152 
153  forAll(newPointLabel, i)
154  {
155  if( newPointLabel[i] < 0 )
156  continue;
157 
158  newPts[newPointLabel[i]] = pts[i];
159  }
160 
161  //- copy point subsets
162  DynList<label> subsetIds;
163  surf_.pointSubsetIndices(subsetIds);
164  forAll(subsetIds, subsetI)
165  {
166  const label origId = subsetIds[subsetI];
167  const word sName = surf_.pointSubsetName(origId);
168 
169  labelLongList pointsInSubset;
170  surf_.pointsInSubset(origId, pointsInSubset);
171 
172  const label newId = s.addPointSubset(sName);
173  forAll(pointsInSubset, i)
174  {
175  const label newPointI = newPointLabel[pointsInSubset[i]];
176 
177  if( newPointI < 0 )
178  continue;
179 
180  s.addPointToSubset(newId, newPointI);
181  }
182  }
183 
184  //- copy facet subsets
185  surf_.facetSubsetIndices(subsetIds);
186  forAll(subsetIds, subsetI)
187  {
188  const label origId = subsetIds[subsetI];
189  const word sName = surf_.facetSubsetName(origId);
190 
191  labelLongList trianglesInSubset;
192  surf_.facetsInSubset(origId, trianglesInSubset);
193 
194  const label newId = s.addFacetSubset(sName);
195  forAll(trianglesInSubset, i)
196  {
197  const label newTriI = newTriangleLabel[trianglesInSubset[i]];
198 
199  if( newTriI < 0 )
200  continue;
201 
202  s.addFacetToSubset(newId, newTriI);
203  }
204  }
205 
206  //- copy feature edges
207  labelLongList newEdgeLabel(surf_.nFeatureEdges(), -1);
208  const VRWGraph& pointEdges = surf_.pointEdges();
209  const edgeLongList& edges = surf_.edges();
210  const VRWGraph& edgeFacets = surf_.edgeFacets();
211  forAll(newEdgeLabel, edgeI)
212  {
213  const edge& e = surf_.featureEdges()[edgeI];
214  label eI(-1);
215  forAllRow(pointEdges, e.start(), peI)
216  {
217  const label eJ = pointEdges(e.start(), peI);
218  if( edges[eJ] == e )
219  {
220  eI = eJ;
221  break;
222  }
223  }
224 
225  if( newPointLabel[e.start()] < 0 )
226  continue;
227  if( newPointLabel[e.end()] < 0 )
228  continue;
229  bool foundTriangle(false);
230  forAllRow(edgeFacets, eI, efI)
231  {
232  if( newTriangleLabel[edgeFacets(eI, efI)] >= 0 )
233  {
234  foundTriangle = true;
235  break;
236  }
237  }
238  if( !foundTriangle )
239  continue;
240 
241  newEdgeLabel[edgeI] = sm.featureEdgesAccess().size();
243  (
244  edge(newPointLabel[e.start()], newPointLabel[e.end()])
245  );
246  }
247 
248  //- copy subsets of feature edges
249  surf_.edgeSubsetIndices(subsetIds);
250  forAll(subsetIds, subsetI)
251  {
252  const label origId = subsetIds[subsetI];
253  const word sName = surf_.edgeSubsetName(origId);
254 
255  labelLongList edgesInSubset;
256  surf_.edgesInSubset(origId, edgesInSubset);
257 
258  const label newId = s.addEdgeSubset(sName);
259  forAll(edgesInSubset, i)
260  {
261  const label newEdgeI = newEdgeLabel[edgesInSubset[i]];
262 
263  if( newEdgeI < 0 )
264  continue;
265 
266  s.addEdgeToSubset(newId, newEdgeI);
267  }
268  }
269 
270  Info << "Finished copying surface parts" << endl;
271 }
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
276 :
277  surf_(surface)
278 {}
279 
281 {}
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
286 {
287  boolList copyFacets(surf_.size(), false);
288 
289  markFacetsForCopying(patches, copyFacets);
290 
291  copySurfaceMesh(copyFacets, s);
292 }
293 
295 {
296  boolList copyFacets(surf_.size(), false);
297 
298  markFacetsForCopying(patches, copyFacets);
299 
300  triSurf* sPtr = new triSurf();
301 
302  copySurfaceMesh(copyFacets, *sPtr);
303 
304  return sPtr;
305 }
306 
307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308 
309 } // End namespace Foam
310 
311 // ************************************************************************* //
Foam::triSurfaceCopyParts::triSurfaceCopyParts
triSurfaceCopyParts(const triSurfaceCopyParts &)
Disallow default bitwise copy construct.
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
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::triSurfaceCopyParts::surf_
const triSurf & surf_
reference to triSurf
Definition: triSurfaceCopyParts.H:53
Foam::LongList::clear
void clear()
Clear the list, i.e. set next free to zero.
Definition: LongListI.H:230
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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::triSurfModifier::patchesAccess
geometricSurfacePatchList & patchesAccess()
access to patches
Definition: triSurfModifierI.H:52
Foam::triSurfaceCopyParts::markFacetsForCopying
void markFacetsForCopying(const wordList &, boolList &) const
mark facets which shall be copied
Definition: triSurfaceCopyParts.C:39
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
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::Info
messageStream Info
Foam::triSurfModifier::pointsAccess
pointField & pointsAccess()
non-const access to points
Definition: triSurfModifierI.H:37
Foam::triSurfModifier::facetsAccess
LongList< labelledTri > & facetsAccess()
access to facets
Definition: triSurfModifierI.H:42
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
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::DynList< label >
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::labelledTri::region
label region() const
Return region label.
Definition: labelledTriI.H:68
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
Foam::triSurfaceCopyParts::~triSurfaceCopyParts
~triSurfaceCopyParts()
Definition: triSurfaceCopyParts.C:280
Foam::surface
Definition: surface.H:55
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::triSurfaceCopyParts::copySurfaceMesh
void copySurfaceMesh(const boolList &, triSurf &) const
copies data to a new surface mesh
Definition: triSurfaceCopyParts.C:98
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::triSurfaceCopyParts::copySurface
void copySurface(const wordList &, triSurf &) const
copies selected patches/subsets to an already created mesh
Definition: triSurfaceCopyParts.C:285
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::triSurf
Definition: triSurf.H:59
triSurfaceCopyParts.H
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47