All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups
selectBadCells.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  selectbadCells
26 
27 Description
28  Picks up cells which can produce oscillations in QGD solution and puts
29  them into the badCells cell set. Works only in serial mode.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "argList.H"
34 #include "Time.H"
35 #include "primitiveMeshTools.H"
36 #include "polyMesh.H"
37 #include "cellSet.H"
38 #include "faceSet.H"
39 #include "IOdictionary.H"
40 
41 using namespace Foam;
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 
46 int main(int argc, char *argv[])
47 {
48 // argList::addNote
49 // (
50 // "Create a cellSet for cells with their centres inside the defined "
51 // "surface.\n"
52 // "Surface must be closed and singly connected."
53 // );
54  argList::noParallel();
55  //argList::validArgs.append("surfaceFile");
56  //argList::validArgs.append("cellSet");
57 
58  #include "setRootCase.H"
59  #include "createTime.H"
60  #include "createPolyMesh.H"
61 
62  IOdictionary QGDCellQuality
63  (
64  IOobject
65  (
66  "QGDCellQuality",
67  runTime.system(),
68  mesh,
69  IOobject::MUST_READ,
70  IOobject::NO_WRITE
71  )
72  );
73 
74  scalar faceCosine (readScalar(QGDCellQuality.lookup("faceCosine")));
75  scalar maxAspectRatio(readScalar(QGDCellQuality.lookup("maxAspectRatio")));
76 
77  // Destination cellSet.
78  cellSet badFaceAngle (mesh, "badFaceAngle", IOobject::NO_READ);
79 
80  const labelListList& pointFaces =
81  mesh.pointFaces();
82 
83  const label nInternalFaces = mesh.nInternalFaces();
84 
85  forAll(pointFaces, ipoint)
86  {
87  forAll(pointFaces[ipoint], iface)
88  {
89  label ifaceId = pointFaces[ipoint][iface];
90  label inei = -1;
91  label iown = mesh.faceOwner()[ifaceId];
92  if (ifaceId < nInternalFaces)
93  {
94  inei = mesh.faceNeighbour()[ifaceId];
95  }
96 
97  forAll(pointFaces[ipoint], kface)
98  {
99  label kfaceId = pointFaces[ipoint][kface];
100  if (ifaceId == kfaceId)
101  {
102  continue;
103  }
104 
105  label knei = -1;
106  label kown = mesh.faceOwner()[kfaceId];
107  if (kfaceId < nInternalFaces)
108  {
109  knei = mesh.faceNeighbour()[kfaceId];
110  }
111 
112  vector ni = mesh.faceAreas()[ifaceId] / mag(mesh.faceAreas()[ifaceId]);
113  vector nk = mesh.faceAreas()[kfaceId] / mag(mesh.faceAreas()[kfaceId]);
114 
115  scalar dotnf = mag( ni & nk );
116 
117  if ((inei == knei) && (inei >= 0))
118  {
119 
120  if (dotnf >= faceCosine) // 5 degrees
121  {
122  badFaceAngle.insert(inei);
123  }
124  }
125 
126  if ((iown == kown) || (iown == knei))
127  {
128 
129  if (dotnf >= faceCosine) // 5 degrees
130  {
131  badFaceAngle.insert(iown);
132  }
133  }
134 
135  if (inei == kown)
136  {
137  if (dotnf >= faceCosine) // 5 degrees
138  {
139  badFaceAngle.insert(inei);
140  }
141  }
142 
143  }
144  }
145  }
146 
147  badFaceAngle.write();
148 
149  //
150  // Select cells with high aspect ratio
151  //
152 
153  scalarField openness(mesh.cellVolumes().size(), 0);
154  scalarField aspectRatio(mesh.cellVolumes().size(), 1);
155 
156  primitiveMeshTools::cellClosedness
157  (
158  mesh,
159  mesh.geometricD(),
160  mesh.faceAreas(),
161  mesh.cellVolumes(),
162  openness,
163  aspectRatio
164  );
165 
166  cellSet highAspectRatio (mesh, "highAspectRatio", IOobject::NO_READ);
167 
168  forAll(aspectRatio, iCell)
169  {
170  if (aspectRatio[iCell] > maxAspectRatio)
171  {
172  highAspectRatio.insert(iCell);
173  }
174  }
175 
176 // faceSet badFacesSet (mesh, "badFaces", IOobject::NO_READ);
177 //
178 // mesh.checkFaceFlatness(true, 0.95, &badFacesSet);
179 //
180 // badFacesSet.write();
181 
182  Info<< "End\n" << endl;
183 
184  return 0;
185 }
186 
187 
188 // ************************************************************************* //
int main(int argc, char *argv[])
forAll(Y, i)
Definition: QGDYEqn.H:36