OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

isoSurfaceCellTemplates.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "isoSurfaceCell.H"
00028 #include "polyMesh.H"
00029 #include "tetMatcher.H"
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 template<class Type>
00034 Type Foam::isoSurfaceCell::generatePoint
00035 (
00036     const DynamicList<Type>& snappedPoints,
00037 
00038     const scalar s0,
00039     const Type& p0,
00040     const label p0Index,
00041 
00042     const scalar s1,
00043     const Type& p1,
00044     const label p1Index
00045 ) const
00046 {
00047     scalar d = s1-s0;
00048 
00049     if (mag(d) > VSMALL)
00050     {
00051         scalar s = (iso_-s0)/d;
00052 
00053         if (s >= 0.5 && s <= 1 && p1Index != -1)
00054         {
00055             return snappedPoints[p1Index];
00056         }
00057         else if (s >= 0.0 && s <= 0.5 && p0Index != -1)
00058         {
00059             return snappedPoints[p0Index];
00060         }
00061         else
00062         {
00063             return s*p1 + (1.0-s)*p0;
00064         }
00065     }
00066     else
00067     {
00068         scalar s = 0.4999;
00069 
00070         return s*p1 + (1.0-s)*p0;
00071     }
00072 }
00073 
00074 
00075 template<class Type>
00076 void Foam::isoSurfaceCell::generateTriPoints
00077 (
00078     const DynamicList<Type>& snapped,
00079 
00080     const scalar s0,
00081     const Type& p0,
00082     const label p0Index,
00083 
00084     const scalar s1,
00085     const Type& p1,
00086     const label p1Index,
00087 
00088     const scalar s2,
00089     const Type& p2,
00090     const label p2Index,
00091 
00092     const scalar s3,
00093     const Type& p3,
00094     const label p3Index,
00095 
00096     DynamicList<Type>& points
00097 ) const
00098 {
00099     int triIndex = 0;
00100     if (s0 < iso_)
00101     {
00102         triIndex |= 1;
00103     }
00104     if (s1 < iso_)
00105     {
00106         triIndex |= 2;
00107     }
00108     if (s2 < iso_)
00109     {
00110         triIndex |= 4;
00111     }
00112     if (s3 < iso_)
00113     {
00114         triIndex |= 8;
00115     }
00116 
00117     /* Form the vertices of the triangles for each case */
00118     switch (triIndex)
00119     {
00120         case 0x00:
00121         case 0x0F:
00122         break;
00123 
00124         case 0x0E:
00125         case 0x01:
00126             points.append(generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index));
00127             points.append(generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index));
00128             points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
00129         break;
00130 
00131         case 0x0D:
00132         case 0x02:
00133             points.append(generatePoint(snapped,s1,p1,p1Index,s0,p0,p0Index));
00134             points.append(generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index));
00135             points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
00136         break;
00137 
00138         case 0x0C:
00139         case 0x03:
00140         {
00141             Type tp1 = generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index);
00142             Type tp2 = generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index);
00143 
00144             points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
00145             points.append(tp1);
00146             points.append(tp2);
00147             points.append(tp2);
00148             points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
00149             points.append(tp1);
00150         }
00151         break;
00152 
00153         case 0x0B:
00154         case 0x04:
00155         {
00156             points.append(generatePoint(snapped,s2,p2,p2Index,s0,p0,p0Index));
00157             points.append(generatePoint(snapped,s2,p2,p2Index,s1,p1,p1Index));
00158             points.append(generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index));
00159         }
00160         break;
00161 
00162         case 0x0A:
00163         case 0x05:
00164         {
00165             Type tp0 = generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index);
00166             Type tp1 = generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index);
00167 
00168             points.append(tp0);
00169             points.append(tp1);
00170             points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
00171             points.append(tp0);
00172             points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
00173             points.append(tp1);
00174         }
00175         break;
00176 
00177         case 0x09:
00178         case 0x06:
00179         {
00180             Type tp0 = generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index);
00181             Type tp1 = generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index);
00182 
00183             points.append(tp0);
00184             points.append(generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index));
00185             points.append(tp1);
00186             points.append(tp0);
00187             points.append(generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index));
00188             points.append(tp1);
00189         }
00190         break;
00191 
00192         case 0x07:
00193         case 0x08:
00194             points.append(generatePoint(snapped,s3,p3,p3Index,s0,p0,p0Index));
00195             points.append(generatePoint(snapped,s3,p3,p3Index,s2,p2,p2Index));
00196             points.append(generatePoint(snapped,s3,p3,p3Index,s1,p1,p1Index));
00197         break;
00198     }
00199 }
00200 
00201 
00202 template<class Type>
00203 void Foam::isoSurfaceCell::generateTriPoints
00204 (
00205     const scalarField& cVals,
00206     const scalarField& pVals,
00207 
00208     const Field<Type>& cCoords,
00209     const Field<Type>& pCoords,
00210 
00211     const DynamicList<Type>& snappedPoints,
00212     const labelList& snappedCc,
00213     const labelList& snappedPoint,
00214 
00215     DynamicList<Type>& triPoints,
00216     DynamicList<label>& triMeshCells
00217 ) const
00218 {
00219     tetMatcher tet;
00220 
00221     forAll(mesh_.cells(), cellI)
00222     {
00223         if (cellCutType_[cellI] != NOTCUT)
00224         {
00225             label oldNPoints = triPoints.size();
00226 
00227             const cell& cFaces = mesh_.cells()[cellI];
00228 
00229             if (tet.isA(mesh_, cellI))
00230             {
00231                 // For tets don't do cell-centre decomposition, just use the
00232                 // tet points and values
00233 
00234                 const face& f0 = mesh_.faces()[cFaces[0]];
00235 
00236                 // Get the other point
00237                 const face& f1 = mesh_.faces()[cFaces[1]];
00238                 label oppositeI = -1;
00239                 forAll(f1, fp)
00240                 {
00241                     oppositeI = f1[fp];
00242 
00243                     if (findIndex(f0, oppositeI) == -1)
00244                     {
00245                         break;
00246                     }
00247                 }
00248 
00249                 generateTriPoints
00250                 (
00251                     snappedPoints,
00252                     pVals[f0[0]],
00253                     pCoords[f0[0]],
00254                     snappedPoint[f0[0]],
00255 
00256                     pVals[f0[1]],
00257                     pCoords[f0[1]],
00258                     snappedPoint[f0[1]],
00259 
00260                     pVals[f0[2]],
00261                     pCoords[f0[2]],
00262                     snappedPoint[f0[2]],
00263 
00264                     pVals[oppositeI],
00265                     pCoords[oppositeI],
00266                     snappedPoint[oppositeI],
00267 
00268                     triPoints
00269                 );
00270             }
00271             else
00272             {
00273                 const cell& cFaces = mesh_.cells()[cellI];
00274 
00275                 forAll(cFaces, cFaceI)
00276                 {
00277                     label faceI = cFaces[cFaceI];
00278                     const face& f = mesh_.faces()[faceI];
00279 
00280                     for (label fp = 1; fp < f.size() - 1; fp++)
00281                     {
00282                         triFace tri(f[0], f[fp], f[f.fcIndex(fp)]);
00283                     //List<triFace> tris(triangulate(f));
00284                     //forAll(tris, i)
00285                     //{
00286                     //    const triFace& tri = tris[i];
00287 
00288 
00289                         generateTriPoints
00290                         (
00291                             snappedPoints,
00292 
00293                             pVals[tri[0]],
00294                             pCoords[tri[0]],
00295                             snappedPoint[tri[0]],
00296 
00297                             pVals[tri[1]],
00298                             pCoords[tri[1]],
00299                             snappedPoint[tri[1]],
00300 
00301                             pVals[tri[2]],
00302                             pCoords[tri[2]],
00303                             snappedPoint[tri[2]],
00304 
00305                             cVals[cellI],
00306                             cCoords[cellI],
00307                             snappedCc[cellI],
00308 
00309                             triPoints
00310                         );
00311                     }
00312                 }
00313             }
00314 
00315 
00316             // Every three triPoints is a cell
00317             label nCells = (triPoints.size()-oldNPoints)/3;
00318             for (label i = 0; i < nCells; i++)
00319             {
00320                 triMeshCells.append(cellI);
00321             }
00322         }
00323     }
00324 
00325     triPoints.shrink();
00326     triMeshCells.shrink();
00327 }
00328 
00329 
00330 template <class Type>
00331 Foam::tmp<Foam::Field<Type> >
00332 Foam::isoSurfaceCell::interpolate
00333 (
00334     const scalarField& cVals,
00335     const scalarField& pVals,
00336     const Field<Type>& cCoords,
00337     const Field<Type>& pCoords
00338 ) const
00339 {
00340     DynamicList<Type> triPoints(nCutCells_);
00341     DynamicList<label> triMeshCells(nCutCells_);
00342 
00343     // Dummy snap data
00344     DynamicList<Type> snappedPoints;
00345     labelList snappedCc(mesh_.nCells(), -1);
00346     labelList snappedPoint(mesh_.nPoints(), -1);
00347 
00348 
00349     generateTriPoints
00350     (
00351         cVals,
00352         pVals,
00353 
00354         cCoords,
00355         pCoords,
00356 
00357         snappedPoints,
00358         snappedCc,
00359         snappedPoint,
00360 
00361         triPoints,
00362         triMeshCells
00363     );
00364 
00365 
00366     // One value per point
00367     tmp<Field<Type> > tvalues(new Field<Type>(points().size()));
00368     Field<Type>& values = tvalues();
00369 
00370     forAll(triPoints, i)
00371     {
00372         label mergedPointI = triPointMergeMap_[i];
00373 
00374         if (mergedPointI >= 0)
00375         {
00376             values[mergedPointI] = triPoints[i];
00377         }
00378     }
00379 
00380     return tvalues;
00381 }
00382 
00383 
00384 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd