1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
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.
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
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/>.
26 \*---------------------------------------------------------------------------*/
28 #include "triSurfaceCopyParts.H"
29 #include "triSurfModifier.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 void triSurfaceCopyParts::markFacetsForCopying
40 const wordList& parts,
44 copyFacets.setSize(surf_.size());
47 const geometricSurfacePatchList& patches = surf_.patches();
49 //- mark patches which will be removed
50 boolList removePatch(patches.size(), false);
52 forAll(patches, patchI)
54 const word name = patches[patchI].name();
58 if( parts[partI] == name )
60 removePatch[patchI] = true;
66 //- select facets affected by the deletion of a patch
69 if( removePatch[surf_[triI].region()] )
70 copyFacets[triI] = true;
73 //- mark facets contained in selected subsets
74 DynList<label> facetSubsetsIDs;
75 surf_.facetSubsetIndices(facetSubsetsIDs);
77 forAll(facetSubsetsIDs, i)
79 const word fsName = surf_.facetSubsetName(facetSubsetsIDs[i]);
83 if( parts[partI] == fsName )
85 labelLongList containedFacets;
86 surf_.facetsInSubset(facetSubsetsIDs[i], containedFacets);
88 forAll(containedFacets, cfI)
89 copyFacets[containedFacets[cfI]] = true;
97 void triSurfaceCopyParts::copySurfaceMesh
99 const boolList& copyFacets,
103 Info << "Starting copying surface parts" << endl;
105 const pointField& pts = surf_.points();
107 labelLongList newPointLabel(pts.size(), -1);
111 //- create the modifier and delete data if there is any
112 triSurfModifier sm(s);
113 LongList<labelledTri>& newTriangles = sm.facetsAccess();
114 newTriangles.clear();
115 sm.featureEdgesAccess().clear();
116 sm.patchesAccess().setSize(1);
117 sm.patchesAccess()[0] = geometricSurfacePatch("patch0", "patch", 0);
119 //- copy selected patches
120 forAll(copyFacets, triI)
122 if( !copyFacets[triI] )
125 const labelledTri& tri = surf_[triI];
132 if( newPointLabel[tri[pI]] == -1 )
134 newPointLabel[tri[pI]] = nPoints;
138 newTri[pI] = newPointLabel[tri[pI]];
141 newTriangles.append(newTri);
144 Info << "Copied triangles " << newTriangles.size() << endl;
145 Info << "Number of vertices " << nPoints << endl;
148 pointField& newPts = sm.pointsAccess();
149 newPts.setSize(nPoints);
151 forAll(newPointLabel, i)
153 if( newPointLabel[i] < 0 )
156 newPts[newPointLabel[i]] = pts[i];
159 Info << "Finished copying surface parts" << endl;
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 triSurfaceCopyParts::triSurfaceCopyParts(const triSurf& surface)
169 triSurfaceCopyParts::~triSurfaceCopyParts()
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 void triSurfaceCopyParts::copySurface(const wordList& patches, triSurf& s) const
176 boolList copyFacets(surf_.size(), false);
178 markFacetsForCopying(patches, copyFacets);
180 copySurfaceMesh(copyFacets, s);
183 triSurf* triSurfaceCopyParts::copySurface(const wordList& patches) const
185 boolList copyFacets(surf_.size(), false);
187 markFacetsForCopying(patches, copyFacets);
189 triSurf* sPtr = new triSurf();
191 copySurfaceMesh(copyFacets, *sPtr);
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 } // End namespace Foam
200 // ************************************************************************* //