OpenFOAM logo
Open Source CFD Toolkit

meshCutter.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-2005 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     meshCutter
00027 
00028 Description
00029     Cuts (splits) cells.
00030 
00031     Description of cut is given as a loop of 'cuts' per cell (see cellCuts).
00032     setRefinement() takes this cut description and inserts the nessecary
00033     topoActions (add points/faces/cells) into the polyTopoChange.
00034 
00035     Stores added cells/faces/points.
00036 
00037     Cut description gives orientation to cut by calculating 'anchorPoints'.
00038     The side of the cell that contains the anchorPoints is the master cell.
00039     Likewise the cells' edges will have the split added as a duplicate of the
00040     master (anchor) point.
00041     Think of it as the cell with the anchor points at the bottom. Add a face
00042     at the bottom to split the cell and then sweep this face up to be through
00043     the middle of the cell (inflation).
00044 
00045 
00046     1. Start: cell with anchor points at bottom
00047     +-------+
00048     |       +
00049     |       +
00050     |       +
00051     |       +
00052     |       +
00053     |       +
00054     |       +
00055     +-------+
00056     anchor  anchor
00057 
00058 
00059     2. Topo change: splitface introduced at bottom of cell, introducing a new
00060       cell and splitting the side faces into two.
00061     +-------+
00062     |       +
00063     |       +
00064     |       + <- addedCell
00065     |       +
00066     |       +
00067     |       +
00068     +-------+ <- splitFace
00069     +-------+ <- original cell
00070     anchor  anchor
00071 
00072 
00073     3. Inflation: splitface shifted up to middle of cell (or wherever cut was)
00074     +-------+
00075     |       +
00076     |       + <- addedCell
00077     |       +
00078     +-------+ <- splitFace
00079     |       +
00080     |       + <- original cell
00081     |       +
00082     +-------+
00083     anchor  anchor
00084 
00085     Anyway this was the original idea. Inflation was meant to handle
00086     conservative properties distribution without interpolation.
00087     (just face sweeping through space). But problem was that
00088     only if the introduced splitface was exactly the same shape as bottom face
00089     (so same 2D topo or perfectly flat) the volume between them was 0.
00090 
00091     This meshCutting still uses anchorPoints though:
00092     - the master cell is the one without the anchor points. The added cell
00093       (on top of the splitFace) is the with.
00094     - the splitFace is owned by the master cell (since it has the lower number)
00095     - the side faces get split and get either the original cell as neighbour
00096       or the added cell (if the faces contain the cell anchor points)
00097     
00098 SourceFiles
00099     meshCutter.C
00100 
00101 \*---------------------------------------------------------------------------*/
00102 
00103 #ifndef meshCutter_H
00104 #define meshCutter_H
00105 
00106 #include "edgeVertex.H"
00107 #include "boolList.H"
00108 #include "labelList.H"
00109 #include "typeInfo.H"
00110 #include "DynamicList.H"
00111 #include "Map.H"
00112 
00113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00114 
00115 namespace Foam
00116 {
00117 
00118 // Class forward declarations
00119 class Time;
00120 class polyTopoChange;
00121 class cellCuts;
00122 class polyMesh;
00123 class face;
00124 
00125 /*---------------------------------------------------------------------------*\
00126                            Class meshCutter Declaration
00127 \*---------------------------------------------------------------------------*/
00128 
00129 class meshCutter
00130 :
00131     public edgeVertex
00132 {
00133     // Private data
00134 
00135         //- Cells added in last setRefinement. Per splitcell label of added 
00136         //  cell
00137         Map<label> addedCells_;
00138 
00139         //- Faces added in last setRefinement. Per split cell label of added
00140         //  face
00141         Map<label> addedFaces_;
00142 
00143         //- Points added in last setRefinement. Per split edge label of added
00144         //  point
00145         HashTable<label, edge, Hash<edge> > addedPoints_;
00146 
00147 
00148     // Private Static Functions
00149 
00150         //- Do list 1 and 2 share elements?
00151         static bool uses(const labelList& elems1, const labelList& elems2);
00152 
00153         //- Do the elements of edge appear in consecutive order in the list
00154         static bool isIn(const edge&, const labelList&);
00155 
00156 
00157     // Private Member Functions
00158 
00159         //- Returns -1 or the cell in cellLabels that is cut.
00160         label findCutCell(const cellCuts&, const labelList&) const;
00161 
00162         //- Returns first pointI in pointLabels that uses an internal
00163         //  face. Used to find point to inflate cell/face from (has to be
00164         //  connected to internal face)
00165         label findInternalFacePoint(const labelList& pointLabels) const;
00166 
00167         //- Get new owner and neighbour of face. Checks anchor points to see if
00168         // need to get original or added cell.
00169         void faceCells
00170         (
00171             const cellCuts& cuts,
00172             const label faceI,
00173             label& own,
00174             label& nei
00175         ) const;
00176 
00177         //- Get patch information for face.
00178         void getFaceInfo
00179         (
00180             const label faceI,
00181             label& patchID,
00182             label& zoneID,
00183             label& zoneFlip
00184         ) const;
00185 
00186         //- Adds a face on top of existing faceI. Flips face
00187         //  if owner>neighbour
00188         void addFace
00189         (
00190             polyTopoChange& meshMod,
00191             const label faceI,
00192             const face& newFace,
00193             const label owner,
00194             const label neighbour
00195         );
00196 
00197         //- Modifies existing faceI for either new owner/neighbour or 
00198         //  new face points. Checks if anything changed and flips face
00199         //  if owner>neighbour
00200         void modFace
00201         (
00202             polyTopoChange& meshMod,
00203             const label faceI,
00204             const face& newFace,
00205             const label owner,
00206             const label neighbour
00207         );
00208 
00209 
00210         // Copies face starting from startFp. Jumps cuts. Marks visited
00211         // vertices in visited.
00212         void copyFace
00213         (
00214             const face& f,
00215             const label startFp,
00216             const label endFp,
00217             face& newFace
00218         ) const;
00219 
00220         //- Split face along cut into two faces. Faces are in same point
00221         //  order as original face (i.e. maintain normal direction)
00222         void splitFace
00223         (
00224             const face& f,
00225             const label v0,
00226             const label v1,
00227 
00228             face& f0,
00229             face& f1
00230         ) const;
00231 
00232         //- Add cuts of edges to face
00233         face addEdgeCutsToFace(const label faceI) const;
00234 
00235         //- Convert loop of cuts into face.
00236         face loopToFace
00237         (
00238             const label cellI,
00239             const labelList& loop
00240         ) const;
00241 
00242 
00243         //- Get elements of cell.
00244         void getFacesEdgesPoints
00245         (
00246             const label cellI,
00247             labelHashSet& faces,
00248             labelHashSet& edges,
00249             labelHashSet& points
00250         ) const;
00251 
00252 
00253 
00254         //- Disallow default bitwise copy construct
00255         meshCutter(const meshCutter&);
00256 
00257         //- Disallow default bitwise assignment
00258         void operator=(const meshCutter&);
00259 
00260 public:
00261 
00262     //- Runtime type information
00263     ClassName("meshCutter");
00264 
00265     // Constructors
00266 
00267         //- Construct from mesh
00268         meshCutter(const polyMesh& mesh);
00269 
00270 
00271     // Destructor
00272 
00273         ~meshCutter();
00274 
00275 
00276     // Member Functions
00277 
00278         // Edit
00279 
00280             //- Do actual cutting with cut description. Inserts mesh changes
00281             //  into meshMod.
00282             void setRefinement(const cellCuts& cuts, polyTopoChange& meshMod);
00283 
00284             //- Force recalculation of locally stored data on topological change
00285             void updateMesh(const mapPolyMesh&);
00286 
00287         // Access
00288 
00289             //- Cells added. Per split cell label of added cell
00290             const Map<label>& addedCells() const
00291             {
00292                 return addedCells_;
00293             }
00294 
00295             //- Faces added. Per split cell label of added face
00296             const Map<label>& addedFaces() const
00297             {
00298                 return addedFaces_;
00299             }
00300 
00301             //- Points added. Per split edge label of added point
00302             const HashTable<label, edge, Hash<edge> >& addedPoints() const
00303             {
00304                 return addedPoints_;
00305             }
00306 };
00307 
00308 
00309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00310 
00311 } // End namespace Foam
00312 
00313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00314 
00315 #endif
00316 
00317 // ************************************************************************* //
For further information go to www.openfoam.org