FreeFOAM The Cross-Platform CFD Toolkit
undoableMeshCutter.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  Foam::undoableMeshCutter
26 
27 Description
28  The main refinement handler. Gets cellCuts which is structure that
29  describes which cells are to be cut and in what way. Maintains an undo
30  list (if told so during construction). Apart from undo list is just
31  wrapper around meshCutter.
32 
33  Undo list: contains a refinement tree (of type splitCell; cell labels are
34  of no consequence) and a list of visible splitCells, i.e. the top of the
35  tree (where the cell labels are valid). Now every cell added gets put on
36  the tree and every updateMesh action updates the labels of visible
37  splitcells.
38 
39  We can now ask this structure for a list of visible split cells or the list
40  of faces between these. These can be passed to removeFaces for actual
41  deletion and we delete the top splitCell and update the now newly visible
42  underlying cells for the new cell number (passed back from removeFaces).
43 
44  NOTE: Undoing note properly tested. Expect it to fail if the faces to
45  be removed cause other faces to be additionally removed (i.e. removeFaces
46  adds additional faces to remove).
47 
48  splitCell:
49  - original cell number.
50  - pointer to parent (null for first level splitCell)
51  - two pointers to splitCell children. Both null (unrefined=visible cell) or
52  both non-null.
53 
54  - live are:
55  (-all unrefined cells (original cell without any splitCells))
56  -all splitCells with null children
57 
58  - liveSplitCells contains pointers to splitCells with null children.
59 
60 
61 
62 SourceFiles
63  undoableMeshCutter.C
64 
65 \*---------------------------------------------------------------------------*/
66 
67 #ifndef undoableMeshCutter_H
68 #define undoableMeshCutter_H
69 
70 #include <dynamicMesh/edgeVertex.H>
71 #include <dynamicMesh/refineCell.H>
72 #include <OpenFOAM/boolList.H>
73 #include <dynamicMesh/cellLooper.H>
74 #include <dynamicMesh/meshCutter.H>
75 #include <OpenFOAM/Map.H>
76 #include <OpenFOAM/typeInfo.H>
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
81 namespace Foam
82 {
83 
84 // Forward declaration of classes
85 class polyMesh;
86 class polyTopoChange;
87 class refineCell;
88 class splitCell;
89 
90 /*---------------------------------------------------------------------------*\
91  Class undoableMeshCutter Declaration
92 \*---------------------------------------------------------------------------*/
93 
95 :
96  public meshCutter
97 {
98  // Private data
99 
100  //- Whether or not to store actions for unplaying.
101  const bool undoable_;
102 
103  //- Current split cells which are 'visible'. Only set if undoable.
104  Map<splitCell*> liveSplitCells_;
105 
106  //- Face remover engine
107  removeFaces faceRemover_;
108 
109 
110  // Private Member Functions
111 
112  //- Debug print
113  void printCellRefTree(Ostream& os, const word&, const splitCell*)
114  const;
115 
116  //- Debug print
117  void printRefTree(Ostream& os) const;
118 
119  //- Find shared face between two cells
120  label sharedFace
121  (
122  const label cell0I,
123  const label cell1I
124  ) const;
125 
126 
127  //- Update labels on splitCell structure after morphing.
128  static void updateLabels(const labelList& map, Map<splitCell*>&);
129 
130 
131  //- Disallow default bitwise copy construct
133 
134  //- Disallow default bitwise assignment
135  void operator=(const undoableMeshCutter&);
136 
137 
138 public:
139 
140  //- Runtime type information
141  ClassName("undoableMeshCutter");
142 
143 
144 
145  // Constructors
146 
147  //- Construct from mesh and flag whether refinement pattern needs
148  // to be stored.
149  undoableMeshCutter(const polyMesh& mesh, const bool undoable = true);
150 
151 
152  // Destructor
153 
155 
156 
157  // Member Functions
158 
159  // Access
160 
161  //- All current live split cells. Warning: cell labels will change
162  // during morphing. Only this map is guaranteed to hold uptodate
163  // info.
165  {
166  return liveSplitCells_;
167  }
168 
169  const removeFaces& faceRemover() const
170  {
171  return faceRemover_;
172  }
173 
174 
175  // Edit
176 
177  //- Refine cells acc. to cellCuts. Plays topology changes
178  // into polyTopoChange.
179  void setRefinement(const cellCuts& cuts, polyTopoChange&);
180 
181  //- Update stored refinement pattern for changes to mesh. Only
182  // call if undoable set.
183  void updateMesh(const mapPolyMesh& morphMap);
184 
185  //- Calculate split faces from current liveCells. Only
186  // call if undoable set.
187  labelList getSplitFaces() const;
188 
189  //- Like getSplitFaces but returns map from original to added cell.
190  // Only call if undoable set.
191  Map<label> getAddedCells() const;
192 
193  //- Remove some refinement. Needs to be supplied subset of
194  // getSplitFaces() output. Returns list of faces removed
195  // (can be more or equal but never less than splitFaces - since
196  // removeFaces might decide to take down unnessecary faces)
197  // Only call if undoable set.
199  (
200  const labelList& splitFaces,
202  );
203 };
204 
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 } // End namespace Foam
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************ vim: set sw=4 sts=4 et: ************************ //