decomposeCellsPyramids.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 \*----------------------p-----------------------------------------------------*/
27 
28 #include "decomposeCells.H"
29 #include "helperFunctions.H"
30 #include "triFace.H"
31 
32 //#define DEBUGDecompose
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
40 (
41  const label cellI,
42  DynList<label, 32>& vrt,
43  DynList<edge, 64>& edges,
44  DynList<DynList<label, 8> >& faceEdges,
45  DynList<DynList<label, 2>, 64>& edgeFaces
46 ) const
47 {
48  const cell& c = mesh_.cells()[cellI];
49 
50  vrt.clear();
51  edges.clear();
52  edgeFaces.clear();
53  faceEdges.setSize(c.size());
54 
55  const faceListPMG& faces = mesh_.faces();
56  forAll(faceEdges, feI)
57  {
58  faceEdges[feI].setSize(faces[c[feI]].size());
59  faceEdges[feI] = -1;
60  }
61 
62  forAll(c, fI)
63  {
64  const face& f = faces[c[fI]];
65 
66  forAll(f, eI)
67  {
68  const edge e = f.faceEdge(eI);
69 
70  bool store(true);
71  forAll(vrt, vI)
72  if( vrt[vI] == f[eI] )
73  {
74  store = false;
75  break;
76  }
77  if( store )
78  {
79  vrt.append(f[eI]);
80  }
81 
82  //- check if the edge alreready exists
83  store = true;
84 
85  forAll(edges, eJ)
86  if( e == edges[eJ] )
87  {
88  store = false;
89  faceEdges[fI][eI] = eJ;
90  edgeFaces[eJ].append(fI);
91  break;
92  }
93 
94  if( store )
95  {
96  faceEdges[fI][eI] = edges.size();
98  ef.append(fI);
99  edgeFaces.append(ef);
100  edges.append(e);
101  }
102  }
103  }
104 
105  //- check if the cell is topologically closed
106  forAll(edgeFaces, efI)
107  if( edgeFaces[efI].size() != 2 )
108  {
109  forAll(c, fI)
110  Info << "Face " << c[fI] << " is " << faces[c[fI]] << endl;
111 
112  Info << "Edges " << edges << endl;
113  Info << "faceEdges " << faceEdges << endl;
114  Info << "edgeFaces " << edgeFaces << endl;
115  mesh_.write();
117  (
118  "void decomposeCells::findAddressingForCell"
119  "(const label, DynList<label, 32>&, DynList<edge, 64>&"
120  ", DynList<DynList<label, 8> >&"
121  ", DynList<DynList<label, 2>, 64>&) const"
122  ) << "Cell " << cellI << " is not topologically closed!"
123  << abort(FatalError);
124  }
125 }
126 
128 (
129  const label cellI,
130  const DynList<label, 32>& /*vrt*/,
131  const DynList<edge, 64>& /*edges*/,
132  const DynList<DynList<label, 2>, 64>& /*edgeFaces*/
133 )
134 {
135  const cell& c = mesh_.cells()[cellI];
136  const faceListPMG& faces = mesh_.faces();
137 
138  pointFieldPMG& pointsAccess = mesh_.points();
139 
140  //- there is no vertex in 3 or more patches
141  //- find boundary faces
142  label topVertex(-1);
143 
144  const labelList cp = c.labels(faces);
146  forAll(cp, cpI)
147  p += pointsAccess[cp[cpI]];
148  p /= cp.size();
149 
150  topVertex = pointsAccess.size();
151  pointsAccess.append(p);
152 
153  # ifdef DEBUGDecompose
154  Info << "Top vertex is " << topVertex << endl;
155  # endif
156 
157  return topVertex;
158 }
159 
161 {
162  const cellListPMG& cells = mesh_.cells();
163  const faceListPMG& faces = mesh_.faces();
164  const labelList& owner = mesh_.owner();
165 
166  const cell& c = cells[cellI];
167 
168  # ifdef DEBUGDecompose
169  Info << "Starting decomposing cell " << cellI << endl;
170  Info << "Cell consists of faces " << c << endl;
171  forAll(c, fI)
172  Info << "Face " << c[fI] << " is " << faces[c[fI]] << endl;
173  # endif
174 
175  //- calculate edges, faceEdges and edgeFaces addressing
176  DynList<label, 32> vrt;
177  DynList<edge, 64> edges;
178  DynList<DynList<label, 8> > faceEdges;
179  faceEdges.setSize(c.size());
180  DynList<DynList<label, 2>, 64> edgeFaces;
181  findAddressingForCell(cellI, vrt, edges, faceEdges, edgeFaces);
182 
183  // find a vertex which will be the top of the pyramids
184  //- if there exist a corner vertex which is in 3 or more patches then
185  //- it is selected as the top vertex
186  label topVertex = findTopVertex(cellI, vrt, edges, edgeFaces);
187 
188  //- start generating pyramids
189  forAll(c, fI)
190  {
191  # ifdef DEBUGDecompose
192  Info << "Face " << faces[c[fI]] << " is a base face" << endl;
193  #endif
194  const face& f = faces[c[fI]];
195  DynList<DynList<label, 8> > cellFaces;
196  cellFaces.setSize(f.size() + 1);
197 
198  DynList<triFace> triFaces;
199  triFaces.setSize(f.size());
200  forAll(triFaces, pI)
201  {
202  triFaces[pI][0] = f.nextLabel(pI);
203  triFaces[pI][1] = f[pI];
204  triFaces[pI][2] = topVertex;
205  }
206 
207  label cfI(0);
208  if( owner[c[fI]] == cellI )
209  {
210  cellFaces[cfI++] = faces[c[fI]];
211 
212  forAll(triFaces, tfI)
213  {
214  cellFaces[cfI++] = triFaces[tfI];
215  }
216  }
217  else
218  {
219  cellFaces[cfI++] = faces[c[fI]].reverseFace();
220 
221  forAll(triFaces, tfI)
222  {
223  triFace rf;
224  rf[0] = triFaces[tfI][0];
225  rf[1] = triFaces[tfI][2];
226  rf[2] = triFaces[tfI][1];
227  cellFaces[cfI++] = rf;
228  }
229  }
230 
231  # ifdef DEBUGDecompose
232  Info << "Cell for face is " << cellFaces << endl;
233 
234  DynList<edge, 64> cEdges;
235  DynList<DynList<label, 2>, 64> eFaces;
236  forAll(cellFaces, fI)
237  {
238  const DynList<label, 8>& f = cellFaces[fI];
239  forAll(f, eI)
240  {
241  const edge e(f[eI], f[(eI+1)%f.size()]);
242 
243  const label pos = cEdges.contains(e);
244 
245  if( pos < 0 )
246  {
247  cEdges.append(e);
249  ef.append(fI);
250  eFaces.append(ef);
251  }
252  else
253  {
254  eFaces[pos].append(fI);
255  }
256  }
257  }
258 
259  forAll(eFaces, eI)
260  if( eFaces[eI].size() != 2 )
261  Pout << "This pyrmid is not topologically closed" << endl;
262  # endif
263 
264  facesOfNewCells_.appendGraph(cellFaces);
265  }
266 }
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
269 
270 } // End namespace Foam
271 
272 // ************************************************************************* //
Foam::polyMeshGenFaces::owner
const labelList & owner() const
owner and neighbour cells for faces
Definition: polyMeshGenFacesI.H:67
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
p
p
Definition: pEqn.H:62
Foam::decomposeCells::facesOfNewCells_
VRWGraphList facesOfNewCells_
Definition: decomposeCells.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::decomposeCells::findTopVertex
label findTopVertex(const label cellI, const DynList< label, 32 > &vrt, const DynList< edge, 64 > &edges, const DynList< DynList< label, 2 >, 64 > &edgeFaces)
find the apex of the pyramids
Definition: decomposeCellsPyramids.C:128
decomposeCells.H
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
triFace.H
Foam::cp
bool cp(const fileName &src, const fileName &dst)
Copy, recursively if necessary, the source to the destination.
Definition: POSIX.C:755
Foam::cellListPMG
Definition: cellListPMG.H:49
Foam::DynList::contains
bool contains(const T &e) const
check if the element is in the list (takes linear time)
Definition: DynListI.H:339
Foam::VRWGraphList::appendGraph
void appendGraph(const GraphType &l)
Append a graph at the end of the graphList.
Definition: VRWGraphListI.H:123
Foam::polyMeshGenFaces::faces
const faceListPMG & faces() const
access to faces
Definition: polyMeshGenFacesI.H:43
Foam::decomposeCells::mesh_
polyMeshGen & mesh_
reference to the mesh
Definition: decomposeCells.H:52
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::Ostream::write
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::Info
messageStream Info
Foam::polyMeshGenCells::cells
const cellListPMG & cells() const
access to cells
Definition: polyMeshGenCellsI.H:39
Foam::pointFieldPMG::size
label size() const
return the number of used elements
Definition: pointFieldPMGI.H:71
Foam::FatalError
error FatalError
Foam::decomposeCells::decomposeCellIntoPyramids
void decomposeCellIntoPyramids(const label cellI)
Definition: decomposeCellsPyramids.C:160
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::pointFieldPMG::append
void append(const point &)
add a point at the end of the list
Definition: pointFieldPMGI.H:98
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::DynList
Definition: DynList.H:53
Foam::decomposeCells::findAddressingForCell
void findAddressingForCell(const label cellI, DynList< label, 32 > &vrt, DynList< edge, 64 > &edges, DynList< DynList< label, 8 > > &faceEdges, DynList< DynList< label, 2 >, 64 > &edgeFaces) const
create addressing needed to decompose the cell
Definition: decomposeCellsPyramids.C:40
Foam::triFace
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:68
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
helperFunctions.H
f
labelList f(nPoints)
Foam::Vector< scalar >
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::DynList::setSize
void setSize(const label)
Reset size of List.
Definition: DynListI.H:263
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::DynList::size
label size() const
Definition: DynListI.H:235
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::faceListPMG
Definition: faceListPMG.H:50
Foam::pointFieldPMG
Definition: pointFieldPMG.H:50
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::DynList::clear
void clear()
Clear the list, i.e. set next free to zero.
Definition: DynListI.H:279
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:190