polyMeshFilter.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) 2012-2016 OpenFOAM Foundation
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::polyMeshFilter
26 
27 Description
28  Remove the edges and faces of a polyMesh whilst satisfying the given mesh
29  quality criteria.
30 
31  Works on a copy of the mesh.
32 
33 SourceFiles
34  polyMeshFilter.C
35  polyMeshFilterTemplates.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef polyMeshFilter_H
40 #define polyMeshFilter_H
41 
42 #include "IOdictionary.H"
43 #include "Time.H"
44 #include "List.H"
45 #include "autoPtr.H"
46 #include "scalarField.H"
47 #include "polyMeshFilterSettings.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 class polyMesh;
55 class fvMesh;
56 class PackedBoolList;
57 class faceSet;
58 
59 /*---------------------------------------------------------------------------*\
60  Class polyMeshFilter Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class polyMeshFilter
64 :
66 {
67  // Private data
68 
69  //- Reference to the original mesh
70  const fvMesh& mesh_;
71 
72  //- Copy of the original mesh to perform the filtering on
73  autoPtr<fvMesh> newMeshPtr_;
74 
75  //- Original point priorities. If a point has a higher priority than
76  // another point then the edge between them collapses towards the
77  // point with the higher priority. (e.g. 2 is a higher priority than 1)
78  labelList originalPointPriority_;
79 
80  //- Point priority associated with the new mesh
81  autoPtr<labelList> pointPriority_;
82 
83  //- The minimum edge length for each edge
84  scalarField minEdgeLen_;
85 
86  //- The face filter factor for each face
87  scalarField faceFilterFactor_;
88 
89 
90  // Private Member Functions
91 
92  template<class T>
93  static void updateSets(const mapPolyMesh& map);
94 
95  template<class T>
96  static void copySets(const polyMesh& oldMesh, const polyMesh& newMesh);
97 
98  label filterFacesLoop(const label nOriginalBadFaces);
99 
100  label filterFaces
101  (
102  polyMesh& newMesh,
103  scalarField& newMeshFaceFilterFactor,
104  labelList& origToCurrentPointMap
105  );
106 
107  label filterEdges
108  (
109  polyMesh& newMesh,
110  scalarField& newMeshMinEdgeLen,
111  labelList& origToCurrentPointMap
112  );
113 
114  //- Increment pointErrorCount for points attached to a bad face
115  void updatePointErrorCount
116  (
117  const PackedBoolList& isErrorPoint,
118  const labelList& oldToNewMesh,
119  labelList& pointErrorCount
120  ) const;
121 
122 
123  //- Given the new points that are part of bad faces, and a map from the
124  // old mesh points to the new mesh points, relax minEdgeLen_
125  void checkMeshEdgesAndRelaxEdges
126  (
127  const polyMesh& newMesh,
128  const labelList& oldToNewMesh,
129  const PackedBoolList& isErrorPoint,
130  const labelList& pointErrorCount
131  );
132 
133  //- Given the new points that are part of bad faces, and a map from the
134  // old mesh points to the new mesh points, relax faceFilterFactor_
135  void checkMeshFacesAndRelaxEdges
136  (
137  const polyMesh& newMesh,
138  const labelList& oldToNewMesh,
139  const PackedBoolList& isErrorPoint,
140  const labelList& pointErrorCount
141  );
142 
143  // Mark boundary points
144  // boundaryPoint:
145  // + -1 : point not on boundary
146  // + 0 : point on a real boundary
147  // + >0 : point on a processor patch with that ID
148  // TODO: Need to mark boundaryEdges as well, as an edge may have two
149  // boundary points but not itself lie on a boundary
150  void updatePointPriorities
151  (
152  const polyMesh& newMesh,
153  const labelList& pointMap
154  );
155 
156  //- Print min/mean/max data for a field
157  void printScalarFieldStats
158  (
159  const string desc,
160  const scalarField& fld
161  ) const;
162 
163  //- Update minEdgeLen_ for the new mesh based upon the movement of the
164  // old points to the new points
165  void mapOldMeshEdgeFieldToNewMesh
166  (
167  const polyMesh& newMesh,
168  const labelList& pointMap,
169  scalarField& newMeshMinEdgeLen
170  ) const;
171 
172  //- Update faceFilterFactor_ for the new mesh based upon the movement
173  // of the old faces to the new faces
174  void mapOldMeshFaceFieldToNewMesh
175  (
176  const polyMesh& newMesh,
177  const labelList& faceMap,
178  scalarField& newMeshFaceFilterFactor
179  ) const;
180 
181  //- Maintain a map of the original mesh points to the latest version of
182  // the filtered mesh.
183  void updateOldToNewPointMap
184  (
185  const labelList& currToNew,
186  labelList& origToCurrentPointMap
187  ) const;
188 
189  //- Disallow default bitwise copy construct
191 
192  //- Disallow default bitwise assignment
193  void operator=(const polyMeshFilter&);
194 
195 
196 public:
197 
198  //- Runtime type information
199  ClassName("polyMeshFilter");
200 
201 
202  // Constructors
203 
204  //- Construct from fvMesh
205  explicit polyMeshFilter(const fvMesh& mesh);
206 
207  //- Construct from fvMesh and a label list of point priorities
208  polyMeshFilter(const fvMesh& mesh, const labelList& pointPriority);
209 
210  //- Construct from fvMesh and a label list of point priorities
212  (
213  const fvMesh& mesh,
214  const labelList& pointPriority,
215  const dictionary& dict
216  );
217 
218 
219  //- Destructor
220  ~polyMeshFilter();
221 
222 
223  // Member Functions
224 
225  // Access
226 
227  //- Return reference to the filtered mesh. Does not check if the
228  // mesh has actually been filtered.
229  const autoPtr<fvMesh>& filteredMesh() const;
230 
231  //- Return the new pointPriority list.
232  const autoPtr<labelList>& pointPriority() const;
233 
234 
235  // Edit
236 
237  //- Return a copy of an fvMesh
238  static autoPtr<fvMesh> copyMesh(const fvMesh& mesh);
239 
240  //- Copy loaded topoSets from the old mesh to the new mesh
241  static void copySets
242  (
243  const polyMesh& oldMesh,
244  const polyMesh& newMesh
245  );
246 
247  //- Update the loaded topoSets
248  static void updateSets(const mapPolyMesh& map);
249 
250  //- Filter edges and faces
251  label filter(const label nOriginalBadFaces);
252 
253  //- Filter all faces that are in the face set
254  label filter(const faceSet& fSet);
255 
256  //- Filter edges only.
257  label filterEdges(const label nOriginalBadFaces);
258 };
259 
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 } // End namespace Foam
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 #ifdef NoRepository
268  #include "polyMeshFilterTemplates.C"
269 #endif
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #endif
274 
275 // ************************************************************************* //
dictionary dict
label filter(const label nOriginalBadFaces)
Filter edges and faces.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of face labels.
Definition: faceSet.H:48
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const autoPtr< labelList > & pointPriority() const
Return the new pointPriority list.
const autoPtr< fvMesh > & filteredMesh() const
Return reference to the filtered mesh. Does not check if the.
static autoPtr< fvMesh > copyMesh(const fvMesh &mesh)
Return a copy of an fvMesh.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
dynamicFvMesh & mesh
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Remove the edges and faces of a polyMesh whilst satisfying the given mesh quality criteria...
~polyMeshFilter()
Destructor.
A bit-packed bool list.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
ClassName("polyMeshFilter")
Runtime type information.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Class to store the settings for the polyMeshFilter class.
Namespace for OpenFOAM.