ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / mesh / autoMesh / autoHexMesh / autoHexMeshDriver / autoSnapDriver.H
blob2e908b73180fbb85017ae176e7492f11eb311c12
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 Class
25     Foam::autoSnapDriver
27 Description
28     All to do with snapping to surface
30 SourceFiles
31     autoSnapDriver.C
32     autoSnapDriverFeature.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef autoSnapDriver_H
37 #define autoSnapDriver_H
39 #include "meshRefinement.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 // Forward declaration of classes
47 class motionSmoother;
48 class snapParameters;
49 class pointConstraint;
51 /*---------------------------------------------------------------------------*\
52                            Class autoSnapDriver Declaration
53 \*---------------------------------------------------------------------------*/
55 class autoSnapDriver
57     // Private data
59         //- Mesh+surface
60         meshRefinement& meshRefiner_;
62         //- From surface region to patch
63         const labelList globalToPatch_;
66     // Private Member Functions
69         // Snapping
71             //- Calculates (geometric) shared points
72             static label getCollocatedPoints
73             (
74                 const scalar tol,
75                 const pointField&,
76                 PackedBoolList&
77             );
79             //- Calculate displacement per patch point to smooth out patch.
80             //  Quite complicated in determining which points to move where.
81             pointField smoothPatchDisplacement
82             (
83                 const motionSmoother&,
84                 const List<labelPair>&
85             ) const;
87             //- Check that face zones are synced
88             void checkCoupledFaceZones() const;
90             //- Per edge distance to patch
91             static tmp<scalarField> edgePatchDist
92             (
93                 const pointMesh&,
94                 const indirectPrimitivePatch&
95             );
97             //- Write displacement as .obj file.
98             static void dumpMove
99             (
100                 const fileName&,
101                 const pointField&,
102                 const pointField&
103             );
105             //- Check displacement is outwards pointing
106             static bool outwardsDisplacement
107             (
108                 const indirectPrimitivePatch&,
109                 const vectorField&
110             );
112             // Feature line snapping
114                 void smoothAndConstrain
115                 (
116                     const indirectPrimitivePatch& pp,
117                     const List<pointConstraint>& constraints,
118                     vectorField& disp
119                 ) const;
120                 //void calcNearest
121                 //(
122                 //    const pointField& points,
123                 //    vectorField& disp,
124                 //    vectorField& surfaceNormal
125                 //) const;
126                 void calcNearestFace
127                 (
128                     const label iter,
129                     const indirectPrimitivePatch& pp,
130                     vectorField& faceDisp,
131                     vectorField& faceSurfaceNormal,
132                     vectorField& faceRotation
133                 ) const;
134                 void interpolateFaceToPoint
135                 (
136                     const label iter,
137                     const indirectPrimitivePatch& pp,
138                     const vectorField& faceSurfaceNormal,
140                     const vectorField& faceDisp,
141                     const vectorField& faceRotation,
143                     vectorField& patchDisp,
144                     vectorField& patchRotationDisp
145                 ) const;
146                 void correctAttraction
147                 (
148                     const DynamicList<point>& surfacePoints,
149                     const DynamicList<label>& surfaceCount,
150                     const point& edgePt,
151                     const vector& edgeNormal,   // normalised normal
152                     const point& pt,
153                     vector& edgeOffset  // offset from pt to point on edge
154                 ) const;
155                 void binFeatureFace
156                 (
157                     const label iter,
158                     const scalar featureCos,
160                     const indirectPrimitivePatch& pp,
161                     const scalar snapDist,
163                     const point& fc,
164                     const vector& faceSurfaceNormal,
165                     const vector& faceDisp,
167                     DynamicList<point>& surfacePoints,
168                     DynamicList<vector>& surfaceNormals,
169                     DynamicList<label>& surfaceCount
170                 ) const;
171                 void binFeatureFaces
172                 (
173                     const label iter,
174                     const scalar featureCos,
176                     const indirectPrimitivePatch& pp,
177                     const scalarField& snapDist,
178                     const label pointI,
180                     const List<List<point> >& pointFaceNormals,
181                     const List<List<point> >& pointFaceDisp,
182                     const List<List<point> >& pointFaceCentres,
184                     DynamicList<point>& surfacePoints,
185                     DynamicList<vector>& surfaceNormals,
186                     DynamicList<label>& surfaceCount
187                 ) const;
189                 void featureAttractionUsingReconstruction
190                 (
191                     const label iter,
192                     const scalar featureCos,
193                     const indirectPrimitivePatch& pp,
194                     const scalarField& snapDist,
196                     const List<List<point> >& pointFaceNormals,
197                     const List<List<point> >& pointFaceDisp,
198                     const List<List<point> >& pointFaceCentres,
200                     vectorField& patchAttraction,
201                     List<pointConstraint>& patchConstraints
202                 ) const;
204                 void determineAllFeatures
205                 (
206                     const label iter,
207                     const scalar featureCos,
209                     const indirectPrimitivePatch&,
210                     const scalarField&,
212                     const List<List<point> >& pointFaceNormals,
213                     const List<List<point> >& pointFaceDisp,
214                     const List<List<point> >& pointFaceCentres,
216                     List<labelList>& pointAttractor,
217                     List<List<pointConstraint> >& pointConstraints,
218                     // Feature-edge to pp point
219                     List<List<DynamicList<point> > >& edgeAttractors,
220                     List<List<DynamicList<pointConstraint> > >& edgeConstraints,
221                     vectorField& patchAttraction,
222                     List<pointConstraint>& patchConstraints
223                 ) const;
224                 void determineFeatures
225                 (
226                     const label iter,
227                     const scalar featureCos,
229                     const indirectPrimitivePatch&,
230                     const scalarField&,
232                     const List<List<point> >& pointFaceNormals,
233                     const List<List<point> >& pointFaceDisp,
234                     const List<List<point> >& pointFaceCentres,
236                     List<labelList>& pointAttractor,
237                     List<List<pointConstraint> >& pointConstraints,
238                     // Feature-edge to pp point
239                     List<List<DynamicList<point> > >& edgeAttractors,
240                     List<List<DynamicList<pointConstraint> > >& edgeConstraints,
241                     vectorField& patchAttraction,
242                     List<pointConstraint>& patchConstraints
243                 ) const;
245                 void featureAttractionUsingFeatureEdges
246                 (
247                     const label iter,
248                     const scalar featureCos,
249                     const indirectPrimitivePatch& pp,
250                     const scalarField& snapDist,
252                     const List<List<point> >& pointFaceNormals,
253                     const List<List<point> >& pointFaceDisp,
254                     const List<List<point> >& pointFaceCentres,
256                     vectorField& patchAttraction,
257                     List<pointConstraint>& patchConstraints
258                 ) const;
259                 void preventFaceSqueeze
260                 (
261                     const label iter,
262                     const scalar featureCos,
263                     const indirectPrimitivePatch& pp,
264                     const scalarField& snapDist,
266                     vectorField& patchAttraction,
267                     List<pointConstraint>& patchConstraints
268                 ) const;
270                 vectorField calcNearestSurfaceFeature
271                 (
272                     const label iter,
273                     const scalar featureCos,
274                     const scalar featureAttract,
275                     const scalarField& snapDist,
276                     const vectorField& nearestDisp,
277                     motionSmoother& meshMover
278                 ) const;
281         //- Disallow default bitwise copy construct
282         autoSnapDriver(const autoSnapDriver&);
284         //- Disallow default bitwise assignment
285         void operator=(const autoSnapDriver&);
288 public:
290     //- Runtime type information
291     ClassName("autoSnapDriver");
294     // Constructors
296         //- Construct from components
297         autoSnapDriver
298         (
299             meshRefinement& meshRefiner,
300             const labelList& globalToPatch
301         );
304     // Member Functions
306         // Snapping
308             //- Merge baffles.
309             autoPtr<mapPolyMesh> mergeZoneBaffles(const List<labelPair>&);
311             //- Calculate edge length per patch point.
312             scalarField calcSnapDistance
313             (
314                 const snapParameters& snapParams,
315                 const indirectPrimitivePatch&
316             ) const;
318             //- Smooth the mesh (patch and internal) to increase visibility
319             //  of surface points (on castellated mesh) w.r.t. surface.
320             void preSmoothPatch
321             (
322                 const snapParameters& snapParams,
323                 const label nInitErrors,
324                 const List<labelPair>& baffles,
325                 motionSmoother&
326             ) const;
328             //- Get points both on patch and facezone.
329             labelList getZoneSurfacePoints
330             (
331                 const indirectPrimitivePatch&,
332                 const word& zoneName
333             ) const;
335             //- Per patch point calculate point on nearest surface. Set as
336             //  boundary conditions of motionSmoother displacement field. Return
337             //  displacement of patch points.
338             vectorField calcNearestSurface
339             (
340                 const scalarField& snapDist,
341                 motionSmoother& meshMover
342             ) const;
345             //- Smooth the displacement field to the internal.
346             void smoothDisplacement
347             (
348                 const snapParameters& snapParams,
349                 motionSmoother&
350             ) const;
352             //- Do the hard work: move the mesh according to displacement,
353             //  locally relax the displacement. Return true if ended up with
354             //  correct mesh, false if not.
355             bool scaleMesh
356             (
357                 const snapParameters& snapParams,
358                 const label nInitErrors,
359                 const List<labelPair>& baffles,
360                 motionSmoother&
361             );
363             //- Repatch faces according to surface nearest the face centre
364             autoPtr<mapPolyMesh> repatchToSurface
365             (
366                 const snapParameters& snapParams,
367                 const labelList& adaptPatchIDs
368             );
370             void doSnap
371             (
372                 const dictionary& snapDict,
373                 const dictionary& motionDict,
374                 const scalar featureCos,
375                 const snapParameters& snapParams
376             );
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 } // End namespace Foam
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 #endif
389 // ************************************************************************* //