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 "isoSurfaceCell.H"
28 #include "tetMatcher.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 Type Foam::isoSurfaceCell::generatePoint
35 const DynamicList<Type>& snappedPoints,
50 scalar s = (iso_-s0)/d;
52 if (s >= 0.5 && s <= 1 && p1Index != -1)
54 return snappedPoints[p1Index];
56 else if (s >= 0.0 && s <= 0.5 && p0Index != -1)
58 return snappedPoints[p0Index];
62 return s*p1 + (1.0-s)*p0;
69 return s*p1 + (1.0-s)*p0;
75 void Foam::isoSurfaceCell::generateTriPoints
77 const DynamicList<Type>& snapped,
95 DynamicList<Type>& points
116 /* Form the vertices of the triangles for each case */
125 points.append(generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index));
126 points.append(generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index));
127 points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
132 points.append(generatePoint(snapped,s1,p1,p1Index,s0,p0,p0Index));
133 points.append(generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index));
134 points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
140 Type tp1 = generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index);
141 Type tp2 = generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index);
143 points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
147 points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
155 points.append(generatePoint(snapped,s2,p2,p2Index,s0,p0,p0Index));
156 points.append(generatePoint(snapped,s2,p2,p2Index,s1,p1,p1Index));
157 points.append(generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index));
164 Type tp0 = generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index);
165 Type tp1 = generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index);
169 points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
171 points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
179 Type tp0 = generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index);
180 Type tp1 = generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index);
183 points.append(generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index));
186 points.append(generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index));
193 points.append(generatePoint(snapped,s3,p3,p3Index,s0,p0,p0Index));
194 points.append(generatePoint(snapped,s3,p3,p3Index,s2,p2,p2Index));
195 points.append(generatePoint(snapped,s3,p3,p3Index,s1,p1,p1Index));
202 void Foam::isoSurfaceCell::generateTriPoints
204 const scalarField& cVals,
205 const scalarField& pVals,
207 const Field<Type>& cCoords,
208 const Field<Type>& pCoords,
210 const DynamicList<Type>& snappedPoints,
211 const labelList& snappedCc,
212 const labelList& snappedPoint,
214 DynamicList<Type>& triPoints,
215 DynamicList<label>& triMeshCells
220 forAll(mesh_.cells(), cellI)
222 if (cellCutType_[cellI] != NOTCUT)
224 label oldNPoints = triPoints.size();
226 const cell& cFaces = mesh_.cells()[cellI];
228 if (tet.isA(mesh_, cellI))
230 // For tets don't do cell-centre decomposition, just use the
231 // tet points and values
233 const face& f0 = mesh_.faces()[cFaces[0]];
235 // Get the other point
236 const face& f1 = mesh_.faces()[cFaces[1]];
237 label oppositeI = -1;
242 if (findIndex(f0, oppositeI) == -1)
265 snappedPoint[oppositeI],
272 const cell& cFaces = mesh_.cells()[cellI];
274 forAll(cFaces, cFaceI)
276 label faceI = cFaces[cFaceI];
277 const face& f = mesh_.faces()[faceI];
279 for (label fp = 1; fp < f.size() - 1; fp++)
281 triFace tri(f[0], f[fp], f[f.fcIndex(fp)]);
282 //List<triFace> tris(triangulate(f));
285 // const triFace& tri = tris[i];
294 snappedPoint[tri[0]],
298 snappedPoint[tri[1]],
302 snappedPoint[tri[2]],
315 // Every three triPoints is a cell
316 label nCells = (triPoints.size()-oldNPoints)/3;
317 for (label i = 0; i < nCells; i++)
319 triMeshCells.append(cellI);
325 triMeshCells.shrink();
329 template <class Type>
330 Foam::tmp<Foam::Field<Type> >
331 Foam::isoSurfaceCell::interpolate
333 const scalarField& cVals,
334 const scalarField& pVals,
335 const Field<Type>& cCoords,
336 const Field<Type>& pCoords
339 DynamicList<Type> triPoints(nCutCells_);
340 DynamicList<label> triMeshCells(nCutCells_);
343 DynamicList<Type> snappedPoints;
344 labelList snappedCc(mesh_.nCells(), -1);
345 labelList snappedPoint(mesh_.nPoints(), -1);
365 // One value per point
366 tmp<Field<Type> > tvalues(new Field<Type>(points().size()));
367 Field<Type>& values = tvalues();
371 label mergedPointI = triPointMergeMap_[i];
373 if (mergedPointI >= 0)
375 values[mergedPointI] = triPoints[i];
383 template <class Type>
384 Foam::tmp<Foam::Field<Type> >
385 Foam::isoSurfaceCell::interpolate
387 const Field<Type>& cCoords,
388 const Field<Type>& pCoords
391 DynamicList<Type> triPoints(nCutCells_);
392 DynamicList<label> triMeshCells(nCutCells_);
395 DynamicList<Type> snappedPoints;
396 labelList snappedCc(mesh_.nCells(), -1);
397 labelList snappedPoint(mesh_.nPoints(), -1);
417 // One value per point
418 tmp<Field<Type> > tvalues(new Field<Type>(points().size()));
419 Field<Type>& values = tvalues();
423 label mergedPointI = triPointMergeMap_[i];
425 if (mergedPointI >= 0)
427 values[mergedPointI] = triPoints[i];
435 // ************************************************************************* //