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

isoSurface.H

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 Class
00026     Foam::isoSurface
00027 
00028 Description
00029     A surface formed by the iso value.
00030     After "Regularised Marching Tetrahedra: improved iso-surface extraction",
00031     G.M. Treece, R.W. Prager and A.H. Gee.
00032 
00033     Note:
00034     - does tets without using cell centres/cell values. Not tested.
00035     - regularisation can create duplicate triangles/non-manifold surfaces.
00036     Current handling of those is bit ad-hoc for now and not perfect.
00037     - regularisation does not do boundary points so as to preserve the
00038       boundary perfectly.
00039     - uses geometric merge with fraction of bounding box as distance.
00040     - triangles can be between two cell centres so constant sampling
00041       does not make sense.
00042     - on empty patches behaves like zero gradient.
00043     - does not do 2D correctly, creates non-flat iso surface.
00044     - on processor boundaries might two overlapping (identical) triangles
00045       (one from either side)
00046 
00047     The handling on coupled patches is a bit complex. All fields
00048     (values and coordinates) get rewritten so
00049     - empty patches get zerogradient (value) and facecentre (coordinates)
00050     - separated processor patch faces get interpolate (value) and facecentre
00051       (coordinates). (this is already the default for cyclics)
00052     - non-separated processor patch faces keep opposite value and cell centre
00053 
00054     Now the triangle generation on non-separated processor patch faces
00055     can use the neighbouring value. Any separated processor face or cyclic
00056     face gets handled just like any boundary face.
00057 
00058 
00059 SourceFiles
00060     isoSurface.C
00061 
00062 \*---------------------------------------------------------------------------*/
00063 
00064 #ifndef isoSurface_H
00065 #define isoSurface_H
00066 
00067 #include "triSurface.H"
00068 #include "labelPair.H"
00069 #include "pointIndexHit.H"
00070 #include "PackedBoolList.H"
00071 #include "volFields.H"
00072 #include "slicedVolFields.H"
00073 
00074 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00075 
00076 namespace Foam
00077 {
00078 
00079 class fvMesh;
00080 
00081 /*---------------------------------------------------------------------------*\
00082                        Class isoSurface Declaration
00083 \*---------------------------------------------------------------------------*/
00084 
00085 class isoSurface
00086 :
00087     public triSurface
00088 {
00089     // Private data
00090 
00091         enum segmentCutType
00092         {
00093             NEARFIRST,      // intersection close to e.first()
00094             NEARSECOND,     //  ,,                   e.second()
00095             NOTNEAR         // no intersection
00096         };
00097 
00098         enum cellCutType
00099         {
00100             NOTCUT,     // not cut
00101             SPHERE,     // all edges to cell centre cut
00102             CUT         // normal cut
00103         };
00104 
00105 
00106         //- Reference to mesh
00107         const fvMesh& mesh_;
00108 
00109         const scalarField& pVals_;
00110 
00111         //- Input volScalarField with separated coupled patches rewritten
00112         autoPtr<slicedVolScalarField> cValsPtr_;
00113 
00114         //- Isosurface value
00115         const scalar iso_;
00116 
00117         //- Regularise?
00118         const Switch regularise_;
00119 
00120         //- When to merge points
00121         const scalar mergeDistance_;
00122 
00123 
00124         //- Whether face might be cut
00125         List<cellCutType> faceCutType_;
00126 
00127         //- Whether cell might be cut
00128         List<cellCutType> cellCutType_;
00129 
00130         //- Estimated number of cut cells
00131         label nCutCells_;
00132 
00133         //- For every triangle the original cell in mesh
00134         labelList meshCells_;
00135 
00136         //- For every unmerged triangle point the point in the triSurface
00137         labelList triPointMergeMap_;
00138 
00139 
00140     // Private Member Functions
00141 
00142         // Point synchronisation
00143 
00144             //- Does tensor differ (to within mergeTolerance) from identity
00145             bool noTransform(const tensor& tt) const;
00146 
00147             //- Is patch a collocated (i.e. non-separated) coupled patch?
00148             static bool collocatedPatch(const polyPatch&);
00149 
00150             //- Per face whether is collocated
00151             PackedBoolList collocatedFaces(const coupledPolyPatch&) const;
00152 
00153             //- Take value at local point patchPointI and assign it to its
00154             //  correct place in patchValues (for transferral) and sharedValues
00155             //  (for reduction)
00156             void insertPointData
00157             (
00158                 const processorPolyPatch& pp,
00159                 const Map<label>& meshToShared,
00160                 const pointField& pointValues,
00161                 const label patchPointI,
00162                 pointField& patchValues,
00163                 pointField& sharedValues
00164             ) const;
00165 
00166             //- Synchonise points on all non-separated coupled patches
00167             void syncUnseparatedPoints
00168             (
00169                 pointField& collapsedPoint,
00170                 const point& nullValue
00171             ) const;
00172 
00173 
00174         //- Get location of iso value as fraction inbetween s0,s1
00175         scalar isoFraction
00176         (
00177             const scalar s0,
00178             const scalar s1
00179         ) const;
00180 
00181         //- Check if any edge of a face is cut
00182         bool isEdgeOfFaceCut
00183         (
00184             const scalarField& pVals,
00185             const face& f,
00186             const bool ownLower,
00187             const bool neiLower
00188         ) const;
00189 
00190         void getNeighbour
00191         (
00192             const labelList& boundaryRegion,
00193             const volVectorField& meshC,
00194             const volScalarField& cVals,
00195             const label cellI,
00196             const label faceI,
00197             scalar& nbrValue,
00198             point& nbrPoint
00199         ) const;
00200 
00201         //- Set faceCutType,cellCutType.
00202         void calcCutTypes
00203         (
00204             const labelList& boundaryRegion,
00205             const volVectorField& meshC,
00206             const volScalarField& cVals,
00207             const scalarField& pVals
00208         );
00209 
00210         static labelPair findCommonPoints
00211         (
00212             const labelledTri&,
00213             const labelledTri&
00214         );
00215 
00216         static point calcCentre(const triSurface&);
00217 
00218         static pointIndexHit collapseSurface
00219         (
00220             pointField& localPoints,
00221             DynamicList<labelledTri, 64>& localTris
00222         );
00223 
00224         //- Determine per cc whether all near cuts can be snapped to single
00225         //  point.
00226         void calcSnappedCc
00227         (
00228             const labelList& boundaryRegion,
00229             const volVectorField& meshC,
00230             const volScalarField& cVals,
00231             const scalarField& pVals,
00232             DynamicList<point>& snappedPoints,
00233             labelList& snappedCc
00234         ) const;
00235 
00236         //- Determine per point whether all near cuts can be snapped to single
00237         //  point.
00238         void calcSnappedPoint
00239         (
00240             const PackedBoolList& isBoundaryPoint,
00241             const labelList& boundaryRegion,
00242             const volVectorField& meshC,
00243             const volScalarField& cVals,
00244             const scalarField& pVals,
00245             DynamicList<point>& snappedPoints,
00246             labelList& snappedPoint
00247         ) const;
00248 
00249 
00250         //- Return input field with coupled (and empty) patch values rewritten
00251         template<class Type>
00252         tmp<SlicedGeometricField
00253         <Type, fvPatchField, slicedFvPatchField, volMesh> >
00254         adaptPatchFields
00255         (
00256             const GeometricField<Type, fvPatchField, volMesh>& fld
00257         ) const;
00258 
00259         //- Generate single point by interpolation or snapping
00260         template<class Type>
00261         Type generatePoint
00262         (
00263             const scalar s0,
00264             const Type& p0,
00265             const bool hasSnap0,
00266             const Type& snapP0,
00267 
00268             const scalar s1,
00269             const Type& p1,
00270             const bool hasSnap1,
00271             const Type& snapP1
00272         ) const;
00273 
00274         template<class Type>
00275         void generateTriPoints
00276         (
00277             const scalar s0,
00278             const Type& p0,
00279             const bool hasSnap0,
00280             const Type& snapP0,
00281 
00282             const scalar s1,
00283             const Type& p1,
00284             const bool hasSnap1,
00285             const Type& snapP1,
00286 
00287             const scalar s2,
00288             const Type& p2,
00289             const bool hasSnap2,
00290             const Type& snapP2,
00291 
00292             const scalar s3,
00293             const Type& p3,
00294             const bool hasSnap3,
00295             const Type& snapP3,
00296 
00297             DynamicList<Type>& points
00298         ) const;
00299 
00300         template<class Type>
00301         label generateFaceTriPoints
00302         (
00303             const volScalarField& cVals,
00304             const scalarField& pVals,
00305 
00306             const GeometricField<Type, fvPatchField, volMesh>& cCoords,
00307             const Field<Type>& pCoords,
00308 
00309             const DynamicList<Type>& snappedPoints,
00310             const labelList& snappedCc,
00311             const labelList& snappedPoint,
00312             const label faceI,
00313 
00314             const scalar neiVal,
00315             const Type& neiPt,
00316             const bool hasNeiSnap,
00317             const Type& neiSnapPt,
00318 
00319             DynamicList<Type>& triPoints,
00320             DynamicList<label>& triMeshCells
00321         ) const;
00322 
00323         template<class Type>
00324         void generateTriPoints
00325         (
00326             const volScalarField& cVals,
00327             const scalarField& pVals,
00328 
00329             const GeometricField<Type, fvPatchField, volMesh>& cCoords,
00330             const Field<Type>& pCoords,
00331 
00332             const DynamicList<Type>& snappedPoints,
00333             const labelList& snappedCc,
00334             const labelList& snappedPoint,
00335 
00336             DynamicList<Type>& triPoints,
00337             DynamicList<label>& triMeshCells
00338         ) const;
00339 
00340         triSurface stitchTriPoints
00341         (
00342             const bool checkDuplicates,
00343             const List<point>& triPoints,
00344             labelList& triPointReverseMap,  // unmerged to merged point
00345             labelList& triMap               // merged to unmerged triangle
00346         ) const;
00347 
00348         //- Check single triangle for (topological) validity
00349         static bool validTri(const triSurface&, const label);
00350 
00351         //- Determine edge-face addressing
00352         void calcAddressing
00353         (
00354             const triSurface& surf,
00355             List<FixedList<label, 3> >& faceEdges,
00356             labelList& edgeFace0,
00357             labelList& edgeFace1,
00358             Map<labelList>& edgeFacesRest
00359         ) const;
00360 
00361         //- Determine orientation
00362         static void walkOrientation
00363         (
00364             const triSurface& surf,
00365             const List<FixedList<label, 3> >& faceEdges,
00366             const labelList& edgeFace0,
00367             const labelList& edgeFace1,
00368             const label seedTriI,
00369             labelList& flipState
00370         );
00371 
00372         //- Orient surface
00373         static void orientSurface
00374         (
00375             triSurface&,
00376             const List<FixedList<label, 3> >& faceEdges,
00377             const labelList& edgeFace0,
00378             const labelList& edgeFace1,
00379             const Map<labelList>& edgeFacesRest
00380         );
00381 
00382         //- Is triangle (given by 3 edges) not fully connected?
00383         static bool danglingTriangle
00384         (
00385             const FixedList<label, 3>& fEdges,
00386             const labelList& edgeFace1
00387         );
00388 
00389         //- Mark all non-fully connected triangles
00390         static label markDanglingTriangles
00391         (
00392             const List<FixedList<label, 3> >& faceEdges,
00393             const labelList& edgeFace0,
00394             const labelList& edgeFace1,
00395             const Map<labelList>& edgeFacesRest,
00396             boolList& keepTriangles
00397         );
00398 
00399         static triSurface subsetMesh
00400         (
00401             const triSurface& s,
00402             const labelList& newToOldFaces,
00403             labelList& oldToNewPoints,
00404             labelList& newToOldPoints
00405         );
00406 
00407 public:
00408 
00409     //- Runtime type information
00410     TypeName("isoSurface");
00411 
00412 
00413     // Constructors
00414 
00415         //- Construct from cell values and point values. Uses boundaryField
00416         //  for boundary values. Holds reference to cellIsoVals and
00417         //  pointIsoVals.
00418         isoSurface
00419         (
00420             const volScalarField& cellIsoVals,
00421             const scalarField& pointIsoVals,
00422             const scalar iso,
00423             const bool regularise,
00424             const scalar mergeTol = 1E-6    // fraction of bounding box
00425         );
00426 
00427 
00428     // Member Functions
00429 
00430         //- For every face original cell in mesh
00431         const labelList& meshCells() const
00432         {
00433             return meshCells_;
00434         }
00435 
00436         //- For every unmerged triangle point the point in the triSurface
00437         const labelList& triPointMergeMap() const
00438         {
00439             return triPointMergeMap_;
00440         }
00441 
00442         //- Interpolates cCoords,pCoords. Uses the references to the original
00443         //  fields used to create the iso surface.
00444         template <class Type>
00445         tmp<Field<Type> > interpolate
00446         (
00447             const GeometricField<Type, fvPatchField, volMesh>& cCoords,
00448             const Field<Type>& pCoords
00449         ) const;
00450 
00451 };
00452 
00453 
00454 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00455 
00456 } // End namespace Foam
00457 
00458 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00459 
00460 #ifdef NoRepository
00461 #   include "isoSurfaceTemplates.C"
00462 #endif
00463 
00464 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00465 
00466 #endif
00467 
00468 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd