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 "createFundamentalSheetsJFS.H"
29 #include "demandDrivenData.H"
30 #include "meshSurfaceEngine.H"
31 #include "extrudeLayer.H"
33 #include "addToRunTimeSelectionTable.H"
42 #include "helperFunctions.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 defineTypeNameAndDebug(createFundamentalSheetsJFS, 0);
53 addToRunTimeSelectionTable
55 createFundamentalSheets,
56 createFundamentalSheetsJFS,
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 bool createFundamentalSheetsJFS::isTopologyOk() const
64 const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
66 const label start = boundaries[0].patchStart();
69 boundaries[boundaries.size()-1].patchStart() +
70 boundaries[boundaries.size()-1].patchSize()
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);
81 for(label faceI=start;faceI<end;++faceI)
83 ++nBndFacesInCell[owner[faceI]];
85 if( nBndFacesInCell[owner[faceI]] > 1 )
92 reduce(isOkTopo, minOp<bool>());
97 void createFundamentalSheetsJFS::createInitialSheet()
99 if( !createWrapperSheet_ )
104 Warning << "Found invalid topology!"
105 << "\nStarting creating initial wrapper sheet" << endl;
108 Info << "Creating initial wrapper sheet" << endl;
110 const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
112 const label start = boundaries[0].patchStart();
115 boundaries[boundaries.size()-1].patchStart() +
116 boundaries[boundaries.size()-1].patchSize()
119 const labelList& owner = mesh_.owner();
121 LongList<labelPair> extrudeFaces(end-start);
124 # pragma omp parallel for schedule(guided, 100)
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 )
142 Info << "Skipping creating sheets at feature edges" << endl;
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();
153 boundaries[boundaries.size()-1].patchStart() +
154 boundaries[boundaries.size()-1].patchSize()
157 faceListPMG::subList bFaces(mesh_.faces(), end-start, start);
158 labelList facePatch(bFaces.size());
160 forAll(boundaries, patchI)
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;
169 labelList patchCell(mesh_.cells().size(), -1);
170 forAll(facePatch, bfI)
171 patchCell[owner[start+bfI]] = facePatch[bfI];
174 labelList patchSheetId(boundaries.size());
175 forAll(patchSheetId, patchI)
176 patchSheetId[patchI] =
177 mesh_.addCellSubset("sheetPatch_"+help::labelToText(patchI));
179 forAll(patchCell, cellI)
181 if( patchCell[cellI] < 0 )
184 mesh_.addCellToSubset(patchSheetId[patchCell[cellI]], cellI);
188 LongList<labelPair> front;
191 const label nThreads = 3 * omp_get_num_procs();
192 # pragma omp parallel num_threads(nThreads)
195 //- create the front faces
196 LongList<labelPair> localFront;
201 forAll(facePatch, bfI)
203 const label faceI = start + bfI;
204 const label cellI = owner[faceI];
206 const cell& c = cells[cellI];
207 const label patchI = facePatch[bfI];
211 if( neighbour[c[fI]] < 0 )
214 label nei = owner[c[fI]];
216 nei = neighbour[c[fI]];
218 if( patchCell[nei] != patchI )
219 localFront.append(labelPair(c[fI], cellI));
223 label frontStart(-1);
225 # pragma omp critical
228 frontStart = front.size();
229 front.setSize(front.size()+localFront.size());
236 //- copy the local front into the global front
237 forAll(localFront, lfI)
238 front[frontStart+lfI] = localFront[lfI];
242 const label fId = mesh_.addFaceSubset("facesForFundamentalSheets");
243 const label cId = mesh_.addCellSubset("cellsForFundamentalSheets");
247 mesh_.addFaceToSubset(fId, front[fI].first());
248 mesh_.addCellToSubset(cId, front[fI].second());
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
266 const bool createWrapperSheet
269 createFundamentalSheets(mesh, createWrapperSheet)
271 createInitialSheet();
273 createSheetsAtFeatureEdges();
276 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
278 createFundamentalSheetsJFS::~createFundamentalSheetsJFS()
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 } // End namespace Foam
285 // ************************************************************************* //