1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
29 #include "faceDecompIsoSurfaceCuts.H"
30 #include "volPointInterpolation.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 void Foam::faceDecompIsoSurfaceCuts::constructEdgeCuts
36 const volScalarField& volField,
37 const pointScalarField& ptField,
42 const primitiveMesh& mesh = volField.mesh();
44 // Intermediate storage for labels of cut edges and cut points
45 label nBFaces = mesh.nFaces() - mesh.nInternalFaces();
47 labelHashSet cutCells(nBFaces);
48 labelHashSet cutVerts(nBFaces);
49 labelHashSet cutFaceCentres(nBFaces);
50 labelHashSet cutCellCentres(nBFaces);
52 DynamicList<label> meshCutEdges(nBFaces);
53 DynamicList<scalar> meshEdgeWeights(nBFaces);
55 DynamicList<pyramidEdge> cutPyrEdges(nBFaces);
56 DynamicList<scalar> pyrEdgeWeights(nBFaces);
58 DynamicList<faceEdge> cutFaceEdges(nBFaces);
59 DynamicList<scalar> faceEdgeWeights(nBFaces);
61 DynamicList<centreEdge> cutCentreEdges(nBFaces);
62 DynamicList<scalar> centreEdgeWeights(nBFaces);
66 forAll(mesh.faces(), faceI)
68 const face& f = mesh.faces()[faceI];
75 fcVal += ptField[f[fp]];
80 label ownerI = mesh.faceOwner()[faceI];
81 label neighbourI = -1;
82 if (mesh.isInternalFace(faceI))
84 neighbourI = mesh.faceNeighbour()[faceI];
90 // Check faceCentre-cellCentre crossing for owner and neigbour
93 if (crosses(isoVal, fcVal, volField[ownerI], weight))
95 mark(ownerI, cutCells);
99 mark(faceI, cutFaceCentres);
101 else if (weight > 1-tol)
103 mark(ownerI, cutCellCentres);
107 cutCentreEdges.append(centreEdge(faceI, true));
108 centreEdgeWeights.append(weight);
112 if (neighbourI != -1)
114 if (crosses(isoVal, fcVal, volField[neighbourI], weight))
116 mark(neighbourI, cutCells);
120 mark(faceI, cutFaceCentres);
122 else if (weight > 1-tol)
124 mark(neighbourI, cutCellCentres);
128 cutCentreEdges.append(centreEdge(faceI, false));
129 centreEdgeWeights.append(weight);
138 // Check face internal (faceEdge) edge crossing
141 if (crosses(isoVal, ptField[f[fp]], fcVal, weight))
143 mark(ownerI, cutCells);
144 if (neighbourI != -1)
146 mark(neighbourI, cutCells);
151 mark(f[fp], cutVerts);
153 else if (weight > 1-tol)
155 mark(faceI, cutFaceCentres);
159 cutFaceEdges.append(faceEdge(faceI, fp));
160 faceEdgeWeights.append(weight);
167 // Walk over all mesh points
168 forAll(mesh.points(), pointI)
170 const labelList& myCells = mesh.pointCells()[pointI];
172 forAll(myCells, myCellI)
174 label cellI = myCells[myCellI];
177 // Check pyramid edge crossing
182 if (crosses(isoVal, ptField[pointI], volField[cellI], weight))
184 mark(cellI, cutCells);
188 mark(pointI, cutVerts);
190 else if (weight > 1-tol)
192 mark(cellI, cutCellCentres);
196 cutPyrEdges.append(pyramidEdge(pointI, cellI));
197 pyrEdgeWeights.append(weight);
204 // Walk over all mesh edges
205 forAll(mesh.edges(), edgeI)
207 const edge& e = mesh.edges()[edgeI];
211 if (crosses(isoVal, ptField[e.start()], ptField[e.end()], weight))
213 mark(mesh.edgeCells()[edgeI], cutCells);
217 mark(e.start(), cutVerts);
219 else if (weight > 1-tol)
221 mark(e.end(), cutVerts);
225 meshCutEdges.append(edgeI);
226 meshEdgeWeights.append(weight);
231 meshCutEdges.shrink();
232 meshEdgeWeights.shrink();
234 cutPyrEdges.shrink();
235 pyrEdgeWeights.shrink();
237 cutFaceEdges.shrink();
238 faceEdgeWeights.shrink();
240 cutCentreEdges.shrink();
241 centreEdgeWeights.shrink();
245 // Tranfer lists to faceDecompCuts
247 cells_ = cutCells.toc();
248 meshVerts_ = cutVerts.toc();
249 meshFaceCentres_ = cutFaceCentres.toc();
250 meshCellCentres_ = cutCellCentres.toc();
252 meshEdges_.transfer(meshCutEdges);
253 meshEdgeWeights_.transfer(meshEdgeWeights);
255 pyrEdges_.transfer(cutPyrEdges);
256 pyrEdgeWeights_.transfer(pyrEdgeWeights);
258 faceEdges_.transfer(cutFaceEdges);
259 faceEdgeWeights_.transfer(faceEdgeWeights);
261 centreEdges_.transfer(cutCentreEdges);
262 centreEdgeWeights_.transfer(centreEdgeWeights);
266 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
268 Foam::faceDecompIsoSurfaceCuts::faceDecompIsoSurfaceCuts
270 const volScalarField& volField,
271 const pointScalarField& ptField,
285 labelList(), // mesh edges
288 List<pyramidEdge>(), // pyramid edges
291 List<faceEdge>(), // face edges
294 List<centreEdge>(), // cell centre edges
298 constructEdgeCuts(volField, ptField, isoVal, tol);
302 // Construct from interpolator and field (does interpolation)
303 Foam::faceDecompIsoSurfaceCuts::faceDecompIsoSurfaceCuts
305 const volScalarField& volField,
306 const volPointInterpolation& pInterp,
320 labelList(), // mesh edges
323 List<pyramidEdge>(), // pyramid edges
326 List<faceEdge>(), // face edges
329 List<centreEdge>(), // cell centre edges
333 // Get field on vertices
334 tmp<pointScalarField> tptField = pInterp.interpolate(volField);
335 const pointScalarField& ptField = tptField();
338 constructEdgeCuts(volField, ptField, isoVal, tol);
342 // ************************************************************************* //