1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "thresholdCellFaces.H"
29 #include "DynamicList.H"
31 #include "emptyPolyPatch.H"
32 #include "processorPolyPatch.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(Foam::thresholdCellFaces, 0);
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 void Foam::thresholdCellFaces::calculate
43 const scalarField& field,
44 const scalar lowerThreshold,
45 const scalar upperThreshold,
46 const bool triangulate
49 const labelList& own = mesh_.faceOwner();
50 const labelList& nei = mesh_.faceNeighbour();
52 const faceList& origFaces = mesh_.faces();
53 const pointField& origPoints = mesh_.points();
55 const polyBoundaryMesh& bMesh = mesh_.boundaryMesh();
58 surfZoneList surfZones(bMesh.size()+1);
60 surfZones[0] = surfZone
70 surfZones[patchI+1] = surfZone
86 DynamicList<face> surfFaces(0.5 * mesh_.nFaces());
87 DynamicList<label> surfCells(surfFaces.size());
89 labelList oldToNewPoints(origPoints.size(), -1);
92 // internal faces only
93 for (label faceI = 0; faceI < mesh_.nInternalFaces(); ++faceI)
97 // check lowerThreshold
98 if (field[own[faceI]] > lowerThreshold)
100 if (field[nei[faceI]] < lowerThreshold)
105 else if (field[nei[faceI]] > lowerThreshold)
110 // check upperThreshold
111 if (field[own[faceI]] < upperThreshold)
113 if (field[nei[faceI]] > upperThreshold)
118 else if (field[nei[faceI]] < upperThreshold)
126 const face& f = origFaces[faceI];
130 if (oldToNewPoints[f[fp]] == -1)
132 oldToNewPoints[f[fp]] = nPoints++;
147 surfFace = f.reverseFace();
154 label count = surfFace.triangles(origPoints, surfFaces);
157 surfCells.append(cellId);
162 surfFaces.append(surfFace);
163 surfCells.append(cellId);
168 surfZones[0].size() = surfFaces.size();
171 // nothing special for processor patches?
172 forAll(bMesh, patchI)
174 const polyPatch& p = bMesh[patchI];
175 surfZone& zone = surfZones[patchI+1];
177 zone.start() = nFaces;
181 isA<emptyPolyPatch>(p)
182 || (Pstream::parRun() && isA<processorPolyPatch>(p))
188 label faceI = p.start();
191 forAll(p, localFaceI)
195 field[own[faceI]] > lowerThreshold
196 && field[own[faceI]] < upperThreshold
199 const face& f = origFaces[faceI];
202 if (oldToNewPoints[f[fp]] == -1)
204 oldToNewPoints[f[fp]] = nPoints++;
208 label cellId = own[faceI];
212 label count = f.triangles(origPoints, surfFaces);
215 surfCells.append(cellId);
221 surfCells.append(cellId);
228 zone.size() = surfFaces.size() - zone.start();
236 forAll(surfFaces, faceI)
238 inplaceRenumber(oldToNewPoints, surfFaces[faceI]);
242 pointField surfPoints(nPoints);
244 forAll(oldToNewPoints, pointI)
246 if (oldToNewPoints[pointI] >= 0)
248 surfPoints[oldToNewPoints[pointI]] = origPoints[pointI];
252 surfPoints.setSize(nPoints);
254 this->storedPoints().transfer(surfPoints);
255 this->storedFaces().transfer(surfFaces);
256 this->storedZones().transfer(surfZones);
258 meshCells_.transfer(surfCells);
262 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
264 Foam::thresholdCellFaces::thresholdCellFaces
266 const polyMesh& mesh,
267 const scalarField& field,
268 const scalar lowerThreshold,
269 const scalar upperThreshold,
270 const bool triangulate
276 if (lowerThreshold > upperThreshold)
278 WarningIn("thresholdCellFaces::thresholdCellFaces(...)")
279 << "lower > upper limit! "
280 << lowerThreshold << " > " << upperThreshold << endl;
283 calculate(field, lowerThreshold, upperThreshold, triangulate);
287 // ************************************************************************* //