createFundamentalSheetsJFS.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 
29 #include "demandDrivenData.H"
30 #include "meshSurfaceEngine.H"
31 #include "extrudeLayer.H"
32 
34 
35 # ifdef USE_OMP
36 #include <omp.h>
37 # endif
38 
39 //#define DEBUGSheets
40 
41 # ifdef DEBUGSheets
42 #include "helperFunctions.H"
43 # endif
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
54 (
58 );
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
63 {
64  const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
65 
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  );
72 
73  const labelList& owner = mesh_.owner();
74 
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);
79 
80  bool isOkTopo(true);
81  for(label faceI=start;faceI<end;++faceI)
82  {
83  ++nBndFacesInCell[owner[faceI]];
84 
85  if( nBndFacesInCell[owner[faceI]] > 1 )
86  {
87  isOkTopo = false;
88  break;
89  }
90  }
91 
92  reduce(isOkTopo, minOp<bool>());
93 
94  return isOkTopo;
95 }
96 
98 {
99  if( !createWrapperSheet_ )
100  {
101  if( isTopologyOk() )
102  return;
103 
104  Warning << "Found invalid topology!"
105  << "\nStarting creating initial wrapper sheet" << endl;
106  }
107 
108  Info << "Creating initial wrapper sheet" << endl;
109 
110  const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
111 
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  );
118 
119  const labelList& owner = mesh_.owner();
120 
121  LongList<labelPair> extrudeFaces(end-start);
122 
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]);
128 
129  extrudeLayer(mesh_, extrudeFaces);
130 
131  Info << "Finished creating initial wrapper sheet" << endl;
132 }
133 
135 {
136  Info << "Starting creating sheets at feature edges" << endl;
137 
138  const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
139 
140  if( returnReduce(boundaries.size(), maxOp<label>()) < 2 )
141  {
142  Info << "Skipping creating sheets at feature edges" << endl;
143  return;
144  }
145 
146  const cellListPMG& cells = mesh_.cells();
147  const labelList& owner = mesh_.owner();
148  const labelList& neighbour = mesh_.neighbour();
149 
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  );
156 
157  faceListPMG::subList bFaces(mesh_.faces(), end-start, start);
158  labelList facePatch(bFaces.size());
159 
160  forAll(boundaries, patchI)
161  {
162  const label patchStart = boundaries[patchI].patchStart();
163  const label patchEnd = patchStart + boundaries[patchI].patchSize();
164 
165  for(label faceI=patchStart;faceI<patchEnd;++faceI)
166  facePatch[faceI-start] = patchI;
167  }
168 
169  labelList patchCell(mesh_.cells().size(), -1);
170  forAll(facePatch, bfI)
171  patchCell[owner[start+bfI]] = facePatch[bfI];
172 
173  # ifdef DEBUGSheets
174  labelList patchSheetId(boundaries.size());
175  forAll(patchSheetId, patchI)
176  patchSheetId[patchI] =
177  mesh_.addCellSubset("sheetPatch_"+help::labelToText(patchI));
178 
179  forAll(patchCell, cellI)
180  {
181  if( patchCell[cellI] < 0 )
182  continue;
183 
184  mesh_.addCellToSubset(patchSheetId[patchCell[cellI]], cellI);
185  }
186  # endif
187 
188  LongList<labelPair> front;
189 
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;
197 
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];
205 
206  const cell& c = cells[cellI];
207  const label patchI = facePatch[bfI];
208 
209  forAll(c, fI)
210  {
211  if( neighbour[c[fI]] < 0 )
212  continue;
213 
214  label nei = owner[c[fI]];
215  if( nei == cellI )
216  nei = neighbour[c[fI]];
217 
218  if( patchCell[nei] != patchI )
219  localFront.append(labelPair(c[fI], cellI));
220  }
221  }
222 
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  }
231 
232  # ifdef USE_OMP
233  # pragma omp barrier
234  # endif
235 
236  //- copy the local front into the global front
237  forAll(localFront, lfI)
238  front[frontStart+lfI] = localFront[lfI];
239  }
240 
241  # ifdef DEBUGSheets
242  const label fId = mesh_.addFaceSubset("facesForFundamentalSheets");
243  const label cId = mesh_.addCellSubset("cellsForFundamentalSheets");
244 
245  forAll(front, fI)
246  {
247  mesh_.addFaceToSubset(fId, front[fI].first());
248  mesh_.addCellToSubset(cId, front[fI].second());
249  }
250 
251  mesh_.write();
252  # endif
253 
254  //- extrude the layer
255  extrudeLayer(mesh_, front);
256 
257  Info << "Finished creating sheets at feature edges" << endl;
258 }
259 
260 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
261 
262 // Construct from mesh, octree, regions for boundary vertices
264 (
265  polyMeshGen& mesh,
266  const bool createWrapperSheet
267 )
268 :
269  createFundamentalSheets(mesh, createWrapperSheet)
270 {
271  createInitialSheet();
272 
273  createSheetsAtFeatureEdges();
274 }
275 
276 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
277 
279 {}
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 } // End namespace Foam
284 
285 // ************************************************************************* //
Foam::polyMeshGenFaces::neighbour
const labelList & neighbour() const
Definition: polyMeshGenFacesI.H:86
Foam::polyMeshGenFaces::owner
const labelList & owner() const
owner and neighbour cells for faces
Definition: polyMeshGenFacesI.H:67
Foam::createFundamentalSheets::mesh_
polyMeshGen & mesh_
reference to mesh
Definition: createFundamentalSheets.H:64
Foam::maxOp
Definition: ops.H:172
createFundamentalSheetsJFS
Inserts sheets at the boundary of the mesh to capture all feature edges.
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::createFundamentalSheetsJFS::createFundamentalSheetsJFS
createFundamentalSheetsJFS()
Disallow default construct.
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:86
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::createFundamentalSheetsJFS::createInitialSheet
void createInitialSheet()
create inital sheet from all boundary faces of the surface mesh
Definition: createFundamentalSheetsJFS.C:97
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::Warning
messageStream Warning
Foam::minOp
Definition: ops.H:173
createFundamentalSheetsJFS.H
Foam::polyMeshGenFaces::addFaceSubset
label addFaceSubset(const word &)
Definition: polyMeshGenFaces.C:262
Foam::createFundamentalSheetsJFS::createSheetsAtFeatureEdges
void createSheetsAtFeatureEdges()
create fundamental sheets for all feature edges
Definition: createFundamentalSheetsJFS.C:134
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::cellListPMG
Definition: cellListPMG.H:49
polyMeshGen
Mesh with selections.
Foam::polyMeshGenFaces::faces
const faceListPMG & faces() const
access to faces
Definition: polyMeshGenFacesI.H:43
Foam::createFundamentalSheetsJFS::isTopologyOk
bool isTopologyOk() const
check if all cells have only one face at the boundary
Definition: createFundamentalSheetsJFS.C:62
Foam::LongList::setSize
void setSize(const label)
Reset size of List.
Definition: LongListI.H:223
Foam::LongList
Definition: LongList.H:55
Foam::polyMeshGenCells::addCellToSubset
void addCellToSubset(const label, const label)
Definition: polyMeshGenCellsI.H:45
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::help::labelToText
word labelToText(const label l)
convert the integer value into text
Definition: helperFunctionsStringConversion.C:69
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::Info
messageStream Info
Foam::polyMeshGenCells::cells
const cellListPMG & cells() const
access to cells
Definition: polyMeshGenCellsI.H:39
Foam::polyMeshGenCells::addCellSubset
label addCellSubset(const word &)
Definition: polyMeshGenCells.C:351
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
helperFunctions.H
extrudeLayer.H
Foam::polyMeshGenFaces::boundaries
const PtrList< boundaryPatch > & boundaries() const
ordinary boundaries
Definition: polyMeshGenFacesI.H:111
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::polyMeshGen::write
void write() const
Definition: polyMeshGen.C:126
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::polyMeshGenFaces::addFaceToSubset
void addFaceToSubset(const label, const label)
Definition: polyMeshGenFacesI.H:117
Foam::createFundamentalSheets
Definition: createFundamentalSheets.H:55
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::createFundamentalSheets::createWrapperSheet_
const bool createWrapperSheet_
shall the procedure create the intial wrapper sheet
Definition: createFundamentalSheets.H:67
Foam::UList::size
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::labelPair
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
Foam::extrudeLayer
Definition: extrudeLayer.H:51
createFundamentalSheets
A base class for various method to generate fundamental sheets necessary to capture feature edges.
Foam::cellListPMG::size
label size() const
return the number of used elements
Definition: cellListPMGI.H:56
Foam::createFundamentalSheetsJFS::~createFundamentalSheetsJFS
~createFundamentalSheetsJFS()
Definition: createFundamentalSheetsJFS.C:278