Fixed URL for libccmio-2.6.1 (bug report #5 by Thomas Oliveira)
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / surfaceTools / createFundamentalSheets / createFundamentalSheetsJFS / createFundamentalSheetsJFS.C
blob3786d5f827f518d712b1d1b7f05c5ef1f8359204
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 "createFundamentalSheetsJFS.H"
29 #include "demandDrivenData.H"
30 #include "meshSurfaceEngine.H"
31 #include "extrudeLayer.H"
33 #include "addToRunTimeSelectionTable.H"
35 # ifdef USE_OMP
36 #include <omp.h>
37 # endif
39 //#define DEBUGSheets
41 # ifdef DEBUGSheets
42 #include "helperFunctions.H"
43 # endif
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 namespace Foam
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 defineTypeNameAndDebug(createFundamentalSheetsJFS, 0);
53 addToRunTimeSelectionTable
55     createFundamentalSheets,
56     createFundamentalSheetsJFS,
57     polyMeshGen
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 bool createFundamentalSheetsJFS::isTopologyOk() const
64     const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
66     const label start = boundaries[0].patchStart();
67     const label end
68     (
69         boundaries[boundaries.size()-1].patchStart() +
70         boundaries[boundaries.size()-1].patchSize()
71     );
73     const labelList& owner = mesh_.owner();
75     //- count the number of boundary faces in every cell
76     //- cells with more than one boundary face cause problem to the
77     //- sheet insertion procedure
78     labelList nBndFacesInCell(mesh_.cells().size(), 0);
80     bool isOkTopo(true);
81     for(label faceI=start;faceI<end;++faceI)
82     {
83         ++nBndFacesInCell[owner[faceI]];
85         if( nBndFacesInCell[owner[faceI]] > 1 )
86         {
87             isOkTopo = false;
88             break;
89         }
90     }
92     reduce(isOkTopo, minOp<bool>());
94     return isOkTopo;
97 void createFundamentalSheetsJFS::createInitialSheet()
99     if( !createWrapperSheet_ )
100     {
101         if( isTopologyOk() )
102             return;
104         Warning << "Found invalid topology!"
105                 << "\nStarting creating initial wrapper sheet" << endl;
106     }
108     Info << "Creating initial wrapper sheet" << endl;
110     const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
112     const label start = boundaries[0].patchStart();
113     const label end
114     (
115         boundaries[boundaries.size()-1].patchStart() +
116         boundaries[boundaries.size()-1].patchSize()
117     );
119     const labelList& owner = mesh_.owner();
121     LongList<labelPair> extrudeFaces(end-start);
123     # ifdef USE_OMP
124     # pragma omp parallel for schedule(guided, 100)
125     # endif
126     for(label faceI=start;faceI<end;++faceI)
127         extrudeFaces[faceI-start] = labelPair(faceI, owner[faceI]);
129     extrudeLayer(mesh_, extrudeFaces);
131     Info << "Finished creating initial wrapper sheet" << endl;
134 void createFundamentalSheetsJFS::createSheetsAtFeatureEdges()
136     Info << "Starting creating sheets at feature edges" << endl;
138     const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
140     if( returnReduce(boundaries.size(), maxOp<label>()) < 2 )
141     {
142         Info << "Skipping creating sheets at feature edges" << endl;
143         return;
144     }
146     const cellListPMG& cells = mesh_.cells();
147     const labelList& owner = mesh_.owner();
148     const labelList& neighbour = mesh_.neighbour();
150     const label start = boundaries[0].patchStart();
151     const label end
152     (
153         boundaries[boundaries.size()-1].patchStart() +
154         boundaries[boundaries.size()-1].patchSize()
155     );
157     faceListPMG::subList bFaces(mesh_.faces(), end-start, start);
158     labelList facePatch(bFaces.size());
160     forAll(boundaries, patchI)
161     {
162         const label patchStart = boundaries[patchI].patchStart();
163         const label patchEnd = patchStart + boundaries[patchI].patchSize();
165         for(label faceI=patchStart;faceI<patchEnd;++faceI)
166             facePatch[faceI-start] = patchI;
167     }
169     labelList patchCell(mesh_.cells().size(), -1);
170     forAll(facePatch, bfI)
171         patchCell[owner[start+bfI]] = facePatch[bfI];
173     # ifdef DEBUGSheets
174     labelList patchSheetId(boundaries.size());
175     forAll(patchSheetId, patchI)
176         patchSheetId[patchI] =
177             mesh_.addCellSubset("sheetPatch_"+help::labelToText(patchI));
179     forAll(patchCell, cellI)
180     {
181         if( patchCell[cellI] < 0 )
182             continue;
184         mesh_.addCellToSubset(patchSheetId[patchCell[cellI]], cellI);
185     }
186     # endif
188     LongList<labelPair> front;
190     # ifdef USE_OMP
191     const label nThreads = 3 * omp_get_num_procs();
192     # pragma omp parallel num_threads(nThreads)
193     # endif
194     {
195         //- create the front faces
196         LongList<labelPair> localFront;
198         # ifdef USE_OMP
199         # pragma omp for
200         # endif
201         forAll(facePatch, bfI)
202         {
203             const label faceI = start + bfI;
204             const label cellI = owner[faceI];
206             const cell& c = cells[cellI];
207             const label patchI = facePatch[bfI];
209             forAll(c, fI)
210             {
211                 if( neighbour[c[fI]] < 0 )
212                     continue;
214                 label nei = owner[c[fI]];
215                 if( nei == cellI )
216                     nei = neighbour[c[fI]];
218                 if( patchCell[nei] != patchI )
219                     localFront.append(labelPair(c[fI], cellI));
220             }
221         }
223         label frontStart(-1);
224         # ifdef USE_OMP
225         # pragma omp critical
226         # endif
227         {
228             frontStart = front.size();
229             front.setSize(front.size()+localFront.size());
230         }
232         # ifdef USE_OMP
233         # pragma omp barrier
234         # endif
236         //- copy the local front into the global front
237         forAll(localFront, lfI)
238             front[frontStart+lfI] = localFront[lfI];
239     }
241     # ifdef DEBUGSheets
242     const label fId = mesh_.addFaceSubset("facesForFundamentalSheets");
243     const label cId = mesh_.addCellSubset("cellsForFundamentalSheets");
245     forAll(front, fI)
246     {
247         mesh_.addFaceToSubset(fId, front[fI].first());
248         mesh_.addCellToSubset(cId, front[fI].second());
249     }
251     mesh_.write();
252     # endif
254     //- extrude the layer
255     extrudeLayer(mesh_, front);
257     Info << "Finished creating sheets at feature edges" << endl;
260 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
262 // Construct from mesh, octree, regions for boundary vertices
263 createFundamentalSheetsJFS::createFundamentalSheetsJFS
265     polyMeshGen& mesh,
266     const bool createWrapperSheet
269     createFundamentalSheets(mesh, createWrapperSheet)
271     createInitialSheet();
273     createSheetsAtFeatureEdges();
276 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
278 createFundamentalSheetsJFS::~createFundamentalSheetsJFS()
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 } // End namespace Foam
285 // ************************************************************************* //