1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Given a displacement moves the mesh by scaling the displacement back
30 until there are no more mesh errors.
32 Holds displacement field (read upon construction since need boundary
33 conditions) and scaling factor and optional patch number on which to
34 scale back displacement.
38 // Construct iterative mesh mover.
39 motionSmoother meshMover(mesh, labelList(1, patchI));
41 // Set desired displacement:
42 meshMover.displacement() = ..
44 for (label iter = 0; iter < maxIter; iter++)
46 if (meshMover.scaleMesh(true))
48 Info<< "Successfully moved mesh" << endl;
55 Shared points (parallel): a processor can have points which are part of
56 pp on another processor but have no pp itself (i.e. it has points
57 and/or edges but no faces of pp). Hence we have to be careful when e.g.
58 synchronising displacements that the value from the processor which has
59 faces of pp get priority. This is currently handled in setDisplacement
60 by resetting the internal displacement to zero before doing anything
61 else. The combine operator used will give preference to non-zero
64 Various routines take baffles. These are sets of boundary faces that
65 are treated as a single internal face. This is a hack used to apply
66 movement to internal faces.
70 motionSmootherTemplates.C
72 \*---------------------------------------------------------------------------*/
74 #ifndef motionSmoother_H
75 #define motionSmoother_H
77 #include "pointFields.H"
78 #include "labelHashSet.H"
79 #include "PackedList.H"
80 #include "indirectPrimitivePatch.H"
81 #include "className.H"
82 #include "twoDPointCorrector.H"
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 class polyMeshGeometry;
92 /*---------------------------------------------------------------------------*\
93 Class motionSmoother Declaration
94 \*---------------------------------------------------------------------------*/
100 //- To synchronise displacements. We want max displacement since
101 // this is what is specified on pp and internal mesh will have
102 // zero displacement.
108 void operator()(vector& x, const vector& y) const
110 for (direction i = 0; i < vector::nComponents; i++)
112 scalar magX = mag(x[i]);
113 scalar magY = mag(y[i]);
119 else if (magX == magY)
133 //- Reference to polyMesh. Non-const since we move mesh.
136 //- Reference to pointMesh
139 //- Reference to face subset of all adaptPatchIDs
140 indirectPrimitivePatch& pp_;
142 //- Indices of fixedValue patches that we're allowed to modify the
144 const labelList adaptPatchIDs_;
147 // Smoothing and checking parameters
148 dictionary paramDict_;
152 //- Displacement field
153 pointVectorField displacement_;
155 //- Scale factor for displacement
156 pointScalarField scale_;
158 //- Starting mesh position
159 pointField oldPoints_;
161 //- Is mesh point on boundary or not
162 PackedList<1> isInternalPoint_;
164 //- Is edge master (always except if on coupled boundary and on
166 PackedList<1> isMasterEdge_;
168 //- 2-D motion corrector
169 twoDPointCorrector twoDCorrector_;
171 // Muli-patch constraints (from pointPatchInterpolation)
173 labelList patchPatchPointConstraintPoints_;
174 tensorField patchPatchPointConstraintTensors_;
177 // Private Member Functions
179 //- Average of connected points.
180 template <class Type>
181 tmp<GeometricField<Type, pointPatchField, pointMesh> > avg
183 const GeometricField<Type, pointPatchField, pointMesh>& fld,
184 const scalarField& edgeWeight,
185 const bool separation
188 //- Check constraints
190 static void checkConstraints
192 GeometricField<Type, pointPatchField, pointMesh>&
195 //- Multi-patch constraints
197 void applyCornerConstraints
199 GeometricField<Type, pointPatchField, pointMesh>&
202 //- Test synchronisation of pointField
203 template<class Type, class CombineOp>
207 const CombineOp& cop,
209 const bool separation
212 //- Assemble tensors for multi-patch constraints
213 void makePatchPatchAddressing();
215 static void checkFld(const pointScalarField&);
217 //- Get points used by given faces
218 labelHashSet getPoints(const labelHashSet&) const;
220 //- explicit smoothing and min on all affected internal points
223 const PackedList<1>& isAffectedPoint,
224 const pointScalarField& fld,
225 pointScalarField& newFld
228 //- same but only on selected points (usually patch points)
231 const PackedList<1>& isAffectedPoint,
232 const labelList& meshPoints,
233 const pointScalarField& fld,
234 pointScalarField& newFld
237 //- Scale certain (internal) points of a field
240 const labelHashSet& pointLabels,
245 //- As above but points have to be in meshPoints as well
246 // (usually to scale patch points)
249 const labelList& meshPoints,
250 const labelHashSet& pointLabels,
255 //- Helper function. Is point internal?
256 bool isInternalPoint(const label pointI) const;
258 //- Given a set of faces that cause smoothing and a number of
259 // iterations determine the maximum set of points who are affected
260 // and the accordingly affected faces.
261 void getAffectedFacesAndPoints
263 const label nPointIter,
264 const faceSet& wrongFaces,
266 labelList& affectedFaces,
267 PackedList<1>& isAffectedPoint
270 //- Disallow default bitwise copy construct
271 motionSmoother(const motionSmoother&);
273 //- Disallow default bitwise assignment
274 void operator=(const motionSmoother&);
279 ClassName("motionSmoother");
283 //- Construct from mesh, patches to work on and smoothing parameters.
284 // Reads displacement field (only boundary conditions used)
289 indirectPrimitivePatch& pp, // 'outside' points
290 const labelList& adaptPatchIDs, // patches forming 'outside'
291 const dictionary& paramDict
294 //- Construct from mesh, patches to work on and smoothing parameters and
295 // displacementfield (only boundary conditions used)
299 indirectPrimitivePatch& pp, // 'outside' points
300 const labelList& adaptPatchIDs, // patches forming 'outside'
301 const pointVectorField&,
302 const dictionary& paramDict
315 //- Reference to mesh
316 const polyMesh& mesh() const;
318 //- Reference to pointMesh
319 const pointMesh& pMesh() const;
321 //- Reference to patch
322 const indirectPrimitivePatch& patch() const;
324 //- Patch labels that are being adapted
325 const labelList& adaptPatchIDs() const;
327 //- Reference to displacement field
328 pointVectorField& displacement();
330 //- Reference to displacement field
331 const pointVectorField& displacement() const;
333 //- Reference to scale field
334 const pointScalarField& scale() const;
336 //- Starting mesh position
337 const pointField& oldPoints() const;
339 //- Return reference to 2D point motion correction
340 twoDPointCorrector& twoDCorrector()
342 return twoDCorrector_;
349 //- Take over existing mesh position.
352 //- Set displacement field from displacement on patch points.
353 // Modify provided displacement to be consistent with actual
354 // boundary conditions on displacement. Note: resets the
355 // displacement to be 0 on coupled patches beforehand
356 // to make sure shared points
357 // partially on pp (on some processors) and partially not
358 // (on other processors) get the value from pp.
359 void setDisplacement(pointField& patchDisp);
361 //- Special correctBoundaryConditions which evaluates fixedValue
362 // patches first so they get overwritten with any constraint
364 void correctBoundaryConditions(pointVectorField&) const;
366 //- Move mesh. Does 2D correction (modifies passed pointField) and
367 // polyMesh::movePoints. Returns swept volumes.
368 tmp<scalarField> movePoints(pointField&);
370 //- Set the errorReduction (by how much to scale the displacement
371 // at error locations) parameter. Returns the old value.
372 // Set to 0 (so revert to old mesh) grows out one cell layer
374 scalar setErrorReduction(const scalar);
376 //- Move mesh with given scale. Return true if mesh ok or has
377 // less than nAllow errors, false
378 // otherwise and locally update scale. Smoothmesh=false means only
379 // patch points get moved.
380 // Parallel ok (as long as displacement field is consistent
384 labelList& checkFaces,
385 const bool smoothMesh = true,
386 const label nAllow = 0
389 //- Move mesh (with baffles) with given scale.
392 labelList& checkFaces,
393 const List<labelPair>& baffles,
394 const bool smoothMesh = true,
395 const label nAllow = 0
401 //- Check mesh with mesh settings in dict. Collects incorrect faces
402 // in set. Returns true if one or more faces in error.
404 static bool checkMesh
407 const polyMesh& mesh,
408 const dictionary& dict,
409 labelHashSet& wrongFaces
412 //- Check (subset of mesh) with mesh settings in dict.
413 // Collects incorrect faces in set. Returns true if one
414 // or more faces in error. Parallel ok.
415 static bool checkMesh
418 const polyMesh& mesh,
419 const dictionary& dict,
420 const labelList& checkFaces,
421 labelHashSet& wrongFaces
424 //- Check (subset of mesh including baffles) with mesh settings
425 // in dict. Collects incorrect faces in set. Returns true if one
426 // or more faces in error. Parallel ok.
427 static bool checkMesh
430 const polyMesh& mesh,
431 const dictionary& dict,
432 const labelList& checkFaces,
433 const List<labelPair>& baffles,
434 labelHashSet& wrongFaces
437 //- Check part of mesh with mesh settings in dict.
438 // Collects incorrect faces in set. Returns true if one or
439 // more faces in error. Parallel ok.
440 static bool checkMesh
443 const dictionary& dict,
444 const polyMeshGeometry&,
445 const labelList& checkFaces,
446 labelHashSet& wrongFaces
449 //- Check part of mesh including baffles with mesh settings in dict.
450 // Collects incorrect faces in set. Returns true if one or
451 // more faces in error. Parallel ok.
452 static bool checkMesh
455 const dictionary& dict,
456 const polyMeshGeometry&,
457 const labelList& checkFaces,
458 const List<labelPair>& baffles,
459 labelHashSet& wrongFaces
462 // Helper functions to manipulate displacement vector.
464 //- Fully explicit smoothing of internal points with varying
466 template <class Type>
469 const GeometricField<Type, pointPatchField, pointMesh>& fld,
470 const scalarField& edgeWeight,
471 const bool separation,
472 GeometricField<Type, pointPatchField, pointMesh>& newFld
478 void motionSmoother::applyCornerConstraints<scalar>
480 GeometricField<scalar, pointPatchField, pointMesh>& pf
484 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
486 } // End namespace Foam
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491 # include "motionSmootherTemplates.C"
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 // ************************************************************************* //