1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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/>.
28 Given a displacement moves the mesh by scaling the displacement back
29 until there are no more mesh errors.
31 Holds displacement field (read upon construction since need boundary
32 conditions) and scaling factor and optional patch number on which to
33 scale back displacement.
37 // Construct iterative mesh mover.
38 motionSmoother meshMover(mesh, labelList(1, patchI));
40 // Set desired displacement:
41 meshMover.displacement() = ..
43 for (label iter = 0; iter < maxIter; iter++)
45 if (meshMover.scaleMesh(true))
47 Info<< "Successfully moved mesh" << endl;
54 - Shared points (parallel): a processor can have points which are part of
55 pp on another processor but have no pp itself (i.e. it has points
56 and/or edges but no faces of pp). Hence we have to be careful when e.g.
57 synchronising displacements that the value from the processor which has
58 faces of pp get priority. This is currently handled in setDisplacement
59 by resetting the internal displacement to zero before doing anything
60 else. The combine operator used will give preference to non-zero
63 - Various routines take baffles. These are sets of boundary faces that
64 are treated as a single internal face. This is a hack used to apply
65 movement to internal faces.
67 - Mesh constraints are looked up from the supplied dictionary. (uses
72 motionSmootherTemplates.C
74 \*---------------------------------------------------------------------------*/
76 #ifndef motionSmoother_H
77 #define motionSmoother_H
79 #include "pointFields.H"
81 #include "PackedBoolList.H"
82 #include "indirectPrimitivePatch.H"
83 #include "className.H"
84 #include "twoDPointCorrector.H"
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 class polyMeshGeometry;
94 /*---------------------------------------------------------------------------*\
95 Class motionSmoother Declaration
96 \*---------------------------------------------------------------------------*/
102 //- To synchronise displacements. We want max displacement since
103 // this is what is specified on pp and internal mesh will have
104 // zero displacement.
110 void operator()(vector& x, const vector& y) const
112 for (direction i = 0; i < vector::nComponents; i++)
114 scalar magX = mag(x[i]);
115 scalar magY = mag(y[i]);
121 else if (magX == magY)
135 //- Reference to polyMesh. Non-const since we move mesh.
138 //- Reference to pointMesh
141 //- Reference to face subset of all adaptPatchIDs
142 indirectPrimitivePatch& pp_;
144 //- Indices of fixedValue patches that we're allowed to modify the
146 const labelList adaptPatchIDs_;
149 // Smoothing and checking parameters
150 dictionary paramDict_;
154 //- Displacement field
155 pointVectorField displacement_;
157 //- Scale factor for displacement
158 pointScalarField scale_;
160 //- Starting mesh position
161 pointField oldPoints_;
163 //- Is mesh point on boundary or not
164 PackedBoolList isInternalPoint_;
166 //- Is edge master (always except if on coupled boundary and on
168 PackedBoolList isMasterEdge_;
170 //- 2-D motion corrector
171 twoDPointCorrector twoDCorrector_;
173 // Muli-patch constraints (from pointPatchInterpolation)
175 labelList patchPatchPointConstraintPoints_;
176 tensorField patchPatchPointConstraintTensors_;
179 // Private Member Functions
181 //- Average of connected points.
182 template <class Type>
183 tmp<GeometricField<Type, pointPatchField, pointMesh> > avg
185 const GeometricField<Type, pointPatchField, pointMesh>& fld,
186 const scalarField& edgeWeight
189 //- Average postion of connected points.
190 template <class Type>
191 tmp<GeometricField<Type, pointPatchField, pointMesh> > avgPositions
193 const GeometricField<Type, pointPatchField, pointMesh>& fld,
194 const scalarField& edgeWeight
197 //- Check constraints
199 static void checkConstraints
201 GeometricField<Type, pointPatchField, pointMesh>&
204 //- Multi-patch constraints
206 void applyCornerConstraints
208 GeometricField<Type, pointPatchField, pointMesh>&
211 //- Test synchronisation of generic field (not positions!) on points
212 template<class Type, class CombineOp>
216 const CombineOp& cop,
221 //- Test synchronisation of points
222 void testSyncPositions(const pointField&, const scalar maxMag) const;
224 //- Assemble tensors for multi-patch constraints
225 void makePatchPatchAddressing();
227 static void checkFld(const pointScalarField&);
229 //- Get points used by given faces
230 labelHashSet getPoints(const labelHashSet&) const;
232 //- explicit smoothing and min on all affected internal points
235 const PackedBoolList& isAffectedPoint,
236 const pointScalarField& fld,
237 pointScalarField& newFld
240 //- same but only on selected points (usually patch points)
243 const PackedBoolList& isAffectedPoint,
244 const labelList& meshPoints,
245 const pointScalarField& fld,
246 pointScalarField& newFld
249 //- Scale certain (internal) points of a field
252 const labelHashSet& pointLabels,
257 //- As above but points have to be in meshPoints as well
258 // (usually to scale patch points)
261 const labelList& meshPoints,
262 const labelHashSet& pointLabels,
267 //- Helper function. Is point internal?
268 bool isInternalPoint(const label pointI) const;
270 //- Given a set of faces that cause smoothing and a number of
271 // iterations determine the maximum set of points who are affected
272 // and the accordingly affected faces.
273 void getAffectedFacesAndPoints
275 const label nPointIter,
276 const faceSet& wrongFaces,
278 labelList& affectedFaces,
279 PackedBoolList& isAffectedPoint
282 //- Disallow default bitwise copy construct
283 motionSmoother(const motionSmoother&);
285 //- Disallow default bitwise assignment
286 void operator=(const motionSmoother&);
291 ClassName("motionSmoother");
295 //- Construct from mesh, patches to work on and smoothing parameters.
296 // Reads displacement field (only boundary conditions used)
301 indirectPrimitivePatch& pp, // 'outside' points
302 const labelList& adaptPatchIDs, // patches forming 'outside'
303 const dictionary& paramDict
306 //- Construct from mesh, patches to work on and smoothing parameters and
307 // displacementfield (only boundary conditions used)
311 indirectPrimitivePatch& pp, // 'outside' points
312 const labelList& adaptPatchIDs, // patches forming 'outside'
313 const pointVectorField&,
314 const dictionary& paramDict
326 //- Reference to mesh
327 const polyMesh& mesh() const;
329 //- Reference to pointMesh
330 const pointMesh& pMesh() const;
332 //- Reference to patch
333 const indirectPrimitivePatch& patch() const;
335 //- Patch labels that are being adapted
336 const labelList& adaptPatchIDs() const;
338 const dictionary& paramDict() const;
340 //- Reference to displacement field
341 pointVectorField& displacement();
343 //- Reference to displacement field
344 const pointVectorField& displacement() const;
346 //- Reference to scale field
347 const pointScalarField& scale() const;
349 //- Starting mesh position
350 const pointField& oldPoints() const;
352 //- Return reference to 2D point motion correction
353 twoDPointCorrector& twoDCorrector()
355 return twoDCorrector_;
362 //- Take over existing mesh position.
365 //- Set displacement field from displacement on patch points.
366 // Modify provided displacement to be consistent with actual
367 // boundary conditions on displacement. Note: resets the
368 // displacement to be 0 on coupled patches beforehand
369 // to make sure shared points
370 // partially on pp (on some processors) and partially not
371 // (on other processors) get the value from pp.
372 void setDisplacement(pointField& patchDisp);
374 //- Special correctBoundaryConditions which evaluates fixedValue
375 // patches first so they get overwritten with any constraint
377 void correctBoundaryConditions(pointVectorField&) const;
379 //- Move mesh. Does 2D correction (modifies passed pointField) and
380 // polyMesh::movePoints. Returns swept volumes.
381 tmp<scalarField> movePoints(pointField&);
383 //- Set the errorReduction (by how much to scale the displacement
384 // at error locations) parameter. Returns the old value.
385 // Set to 0 (so revert to old mesh) grows out one cell layer
387 scalar setErrorReduction(const scalar);
389 //- Move mesh with given scale. Return true if mesh ok or has
390 // less than nAllow errors, false
391 // otherwise and locally update scale. Smoothmesh=false means only
392 // patch points get moved.
393 // Parallel ok (as long as displacement field is consistent
397 labelList& checkFaces,
398 const bool smoothMesh = true,
399 const label nAllow = 0
402 //- Move mesh (with baffles) with given scale.
405 labelList& checkFaces,
406 const List<labelPair>& baffles,
407 const bool smoothMesh = true,
408 const label nAllow = 0
411 //- Move mesh with externally provided mesh constraints
414 labelList& checkFaces,
415 const List<labelPair>& baffles,
416 const dictionary& paramDict,
417 const dictionary& meshQualityDict,
418 const bool smoothMesh = true,
419 const label nAllow = 0
425 //- Check mesh with mesh settings in dict. Collects incorrect faces
426 // in set. Returns true if one or more faces in error.
428 static bool checkMesh
431 const polyMesh& mesh,
432 const dictionary& dict,
433 labelHashSet& wrongFaces
436 //- Check (subset of mesh) with mesh settings in dict.
437 // Collects incorrect faces in set. Returns true if one
438 // or more faces in error. Parallel ok.
439 static bool checkMesh
442 const polyMesh& mesh,
443 const dictionary& dict,
444 const labelList& checkFaces,
445 labelHashSet& wrongFaces
448 //- Check (subset of mesh including baffles) with mesh settings
449 // in dict. Collects incorrect faces in set. Returns true if one
450 // or more faces in error. Parallel ok.
451 static bool checkMesh
454 const polyMesh& mesh,
455 const dictionary& dict,
456 const labelList& checkFaces,
457 const List<labelPair>& baffles,
458 labelHashSet& wrongFaces
461 //- Check part of mesh with mesh settings in dict.
462 // Collects incorrect faces in set. Returns true if one or
463 // more faces in error. Parallel ok.
464 static bool checkMesh
467 const dictionary& dict,
468 const polyMeshGeometry&,
469 const labelList& checkFaces,
470 labelHashSet& wrongFaces
473 //- Check part of mesh including baffles with mesh settings in dict.
474 // Collects incorrect faces in set. Returns true if one or
475 // more faces in error. Parallel ok.
476 static bool checkMesh
479 const dictionary& dict,
480 const polyMeshGeometry&,
481 const labelList& checkFaces,
482 const List<labelPair>& baffles,
483 labelHashSet& wrongFaces
486 // Helper functions to manipulate displacement vector.
488 //- Fully explicit smoothing of fields (not positions)
489 // of internal points with varying diffusivity.
490 template <class Type>
493 const GeometricField<Type, pointPatchField, pointMesh>& fld,
494 const scalarField& edgeWeight,
495 GeometricField<Type, pointPatchField, pointMesh>& newFld
501 void motionSmoother::applyCornerConstraints<scalar>
503 GeometricField<scalar, pointPatchField, pointMesh>& pf
507 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
509 } // End namespace Foam
511 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
514 # include "motionSmootherTemplates.C"
517 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
521 // ************************************************************************* //