Moving cfMesh into place. Updated contibutors list
[foam-extend-3.2.git] / src / mesh / cfMesh / meshLibrary / utilities / triSurfaceTools / triSurfaceCopyParts / triSurfaceCopyParts.C
blobbb9b8d67619294c5ef67f59b899659b50d7f17b5
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.
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
19     for more details.
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/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "triSurfaceCopyParts.H"
29 #include "triSurfModifier.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 void triSurfaceCopyParts::markFacetsForCopying
40     const wordList& parts,
41     boolList& copyFacets
42 ) const
44     copyFacets.setSize(surf_.size());
45     copyFacets = false;
47     const geometricSurfacePatchList& patches = surf_.patches();
49     //- mark patches which will be removed
50     boolList removePatch(patches.size(), false);
52     forAll(patches, patchI)
53     {
54         const word name = patches[patchI].name();
56         forAll(parts, partI)
57         {
58             if( parts[partI] == name )
59             {
60                 removePatch[patchI] = true;
61                 break;
62             }
63         }
64     }
66     //- select facets affected by the deletion of a patch
67     forAll(surf_, triI)
68     {
69         if( removePatch[surf_[triI].region()] )
70             copyFacets[triI] = true;
71     }
73     //- mark facets contained in selected subsets
74     DynList<label> facetSubsetsIDs;
75     surf_.facetSubsetIndices(facetSubsetsIDs);
77     forAll(facetSubsetsIDs, i)
78     {
79         const word fsName = surf_.facetSubsetName(facetSubsetsIDs[i]);
81         forAll(parts, partI)
82         {
83             if( parts[partI] == fsName )
84             {
85                 labelLongList containedFacets;
86                 surf_.facetsInSubset(facetSubsetsIDs[i], containedFacets);
88                 forAll(containedFacets, cfI)
89                     copyFacets[containedFacets[cfI]] = true;
91                 break;
92             }
93         }
94     }
97 void triSurfaceCopyParts::copySurfaceMesh
99     const boolList& copyFacets,
100     triSurf& s
101 ) const
103     Info << "Starting copying surface parts" << endl;
105     const pointField& pts = surf_.points();
107     labelLongList newPointLabel(pts.size(), -1);
109     label nPoints(0);
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)
121     {
122         if( !copyFacets[triI] )
123             continue;
125         const labelledTri& tri = surf_[triI];
127         labelledTri newTri;
128         newTri.region() = 0;
130         forAll(tri, pI)
131         {
132             if( newPointLabel[tri[pI]] == -1 )
133             {
134                 newPointLabel[tri[pI]] = nPoints;
135                 ++nPoints;
136             }
138             newTri[pI] = newPointLabel[tri[pI]];
139         }
141         newTriangles.append(newTri);
142     }
144     Info << "Copied triangles " << newTriangles.size() << endl;
145     Info << "Number of vertices " << nPoints << endl;
147     //- copy vertices
148     pointField& newPts = sm.pointsAccess();
149     newPts.setSize(nPoints);
151     forAll(newPointLabel, i)
152     {
153         if( newPointLabel[i] < 0 )
154             continue;
156         newPts[newPointLabel[i]] = pts[i];
157     }
159     Info << "Finished copying surface parts" << endl;
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 triSurfaceCopyParts::triSurfaceCopyParts(const triSurf& surface)
166     surf_(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);
193     return sPtr;
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 } // End namespace Foam
200 // ************************************************************************* //