checkTools.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6  This file is modified from OpenFOAM's source code
7  applications/utilities/mesh/manipulation/checkMesh/checkTools.C
8 
9  OpenFOAM: The Open Source CFD Toolbox
10 
11  Copyright (C): 2011-2016 OpenFOAM Foundation
12 
13  OpenFOAM License:
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "checkTools.H"
31 #include "polyMesh.H"
32 #include "globalMeshData.H"
33 #include "hexMatcher.H"
34 #include "wedgeMatcher.H"
35 #include "prismMatcher.H"
36 #include "pyrMatcher.H"
37 #include "tetWedgeMatcher.H"
38 #include "tetMatcher.H"
39 #include "IOmanip.H"
40 #include "pointSet.H"
41 #include "faceSet.H"
42 #include "cellSet.H"
43 #include "Time.H"
44 #include "surfaceWriter.H"
45 #include "syncTools.H"
46 #include "globalIndex.H"
47 #include "PatchTools.H"
48 #include "functionObject.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
53  const polyMesh& mesh,
54  const surfaceWriter& writer,
55  const word& name,
56  const indirectPrimitivePatch& setPatch,
57  const fileName& outputDir)
58 {
59  if (Pstream::parRun())
60  {
61  labelList pointToGlobal;
62  labelList uniqueMeshPointLabels;
63  autoPtr<globalIndex> globalPoints;
64  autoPtr<globalIndex> globalFaces;
65  faceList mergedFaces;
66  pointField mergedPoints;
67  Foam::PatchTools::gatherAndMerge(
68  mesh,
69  setPatch.localFaces(),
70  setPatch.meshPoints(),
71  setPatch.meshPointMap(),
72 
73  pointToGlobal,
74  uniqueMeshPointLabels,
75  globalPoints,
76  globalFaces,
77 
78  mergedFaces,
79  mergedPoints);
80 
81  // Write
82  if (Pstream::master())
83  {
84  writer.write(
85  outputDir,
86  name,
87  meshedSurfRef(
88  mergedPoints,
89  mergedFaces));
90  }
91  }
92  else
93  {
94  writer.write(
95  outputDir,
96  name,
97  meshedSurfRef(
98  setPatch.localPoints(),
99  setPatch.localFaces()));
100  }
101 }
102 
104  const surfaceWriter& writer,
105  const faceSet& set)
106 {
107  const polyMesh& mesh = refCast<const polyMesh>(set.db());
108 
109  const indirectPrimitivePatch setPatch(
110  IndirectList<face>(mesh.faces(), set.sortedToc()),
111  mesh.points());
112 
113  fileName outputDir(
114  set.time().globalPath()
115  / functionObject::outputPrefix
116  / mesh.pointsInstance()
117  / set.name());
118  outputDir.clean();
119 
120  mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
121 }
122 
124  const surfaceWriter& writer,
125  const cellSet& set)
126 {
127  const polyMesh& mesh = refCast<const polyMesh>(set.db());
128  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
129 
130  // Determine faces on outside of cellSet
131  bitSet isInSet(mesh.nCells());
132  forAllConstIter(cellSet, set, iter)
133  {
134  isInSet.set(iter.key());
135  }
136 
137  boolList bndInSet(mesh.nBoundaryFaces());
138  forAll(pbm, patchi)
139  {
140  const polyPatch& pp = pbm[patchi];
141  const labelList& fc = pp.faceCells();
142  forAll(fc, i)
143  {
144  bndInSet[pp.start() + i - mesh.nInternalFaces()] = isInSet[fc[i]];
145  }
146  }
147  syncTools::swapBoundaryFaceList(mesh, bndInSet);
148 
149  DynamicList<label> outsideFaces(3 * set.size());
150  for (label facei = 0; facei < mesh.nInternalFaces(); facei++)
151  {
152  const bool ownVal = isInSet[mesh.faceOwner()[facei]];
153  const bool neiVal = isInSet[mesh.faceNeighbour()[facei]];
154 
155  if (ownVal != neiVal)
156  {
157  outsideFaces.append(facei);
158  }
159  }
160 
161  forAll(pbm, patchi)
162  {
163  const polyPatch& pp = pbm[patchi];
164  const labelList& fc = pp.faceCells();
165  if (pp.coupled())
166  {
167  forAll(fc, i)
168  {
169  label facei = pp.start() + i;
170 
171  const bool neiVal = bndInSet[facei - mesh.nInternalFaces()];
172  if (isInSet[fc[i]] && !neiVal)
173  {
174  outsideFaces.append(facei);
175  }
176  }
177  }
178  else
179  {
180  forAll(fc, i)
181  {
182  if (isInSet[fc[i]])
183  {
184  outsideFaces.append(pp.start() + i);
185  }
186  }
187  }
188  }
189 
190  const indirectPrimitivePatch setPatch(
191  IndirectList<face>(mesh.faces(), outsideFaces),
192  mesh.points());
193 
194  fileName outputDir(
195  set.time().globalPath()
196  / functionObject::outputPrefix
197  / mesh.pointsInstance()
198  / set.name());
199  outputDir.clean();
200 
201  mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
202 }
203 
204 // ************************************************************************* //
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
Foam::mergeAndWrite
void mergeAndWrite(const polyMesh &mesh, const surfaceWriter &writer, const word &name, const indirectPrimitivePatch &setPatch, const fileName &outputDir)
Definition: checkTools.C:52
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
checkTools.H