hexMeshSmootherMotionSolver.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::hexMeshSmootherMotionSolver
28 
29 Description
30  Implementation of hexMeshSmoother (part of extBlockMesh). WIP.
31 
32  See https://github.com/Etudes-NG/extBlockMesh
33  extBlockMesh Copyright (C) 2014 Etudes-NG
34 
35  Quality-based under-relaxation of point smoothing.
36 
37 Usage
38  Example of the motion solver specification in dynamicMeshDict:
39  \verbatim
40  motionSolver hexMeshSmoother;
41  hexMeshSmootherCoeffs
42  {
43  //- Number of smoothing iterations
44  nPointSmootherIter 10;
45 
46  //- Smoother to apply
47  pointSmoother geometricElementTransform;
48 
49  //- Any smoother-specific settings
50  transformationParameter 0.667;
51 
52  //- Underrelax boundary condition
53  snapScale table ((0 0.1) (10 1.0));
54  }
55 
56 SourceFiles
57  hexMeshSmootherMotionSolver.C
58 
59 \*---------------------------------------------------------------------------*/
60 
61 #ifndef hexMeshSmootherMotionSolver_H
62 #define hexMeshSmootherMotionSolver_H
63 
65 #include "Function1.H"
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 namespace Foam
70 {
71 
72 //class searchableSurfaces;
73 class pointSmoother;
74 
75 /*---------------------------------------------------------------------------*\
76  Class hexMeshSmootherMotionSolver Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 class hexMeshSmootherMotionSolver
80 :
81  public displacementMotionSolver
82 {
83 public:
84 
85  // Public Data
86 
87  //- Enumeration defining the type of attraction
88  enum pointType
89  {
90  INTERIOR = 0,
91  SURFACE = 1,
92  EDGE = 2,
93  POINT = 3
94  };
95 
96 
97 protected:
98 
99  // Protected Data
100 
101  //- Point smoothing method
102  autoPtr<pointSmoother> pointSmoother_;
103 
104  //- Number of point smoother iterations per timestep
105  const label nPointSmootherIter_;
106 
107 
108  // Mesh quality based relaxation of smoothed position
109 
110  //- Relaxation factors to use in each iteration
111  const scalarList relaxationFactors_;
112 
113  //- Per mesh point (including internal) what type
114  labelList pointTypes_;
115 
116  //- Per mesh point the last used relaxation factor
117  labelList relaxationLevel_;
118 
119  //- Relaxed point field
120  pointField relaxedPoints_;
121 
122 
124  //const labelList snapPatches_;
125  //
127  //const labelList snapZones_;
128 
129  //- Scaling for snapping
130  const autoPtr<Function1<scalar>> snapScale_;
131 
132  //- Cached per-point coupled status. For guaranteeing contributions
133  // of coupled points only done once
134  const bitSet isMasterPoint_;
135 
136  //- Create big primitivePatch for all outside and any features on it
137  const autoPtr<indirectPrimitivePatch> bnd0Ptr_;
138 
139 
140  // Private Member Functions
141 
142  //- Collect all non-constraint (i.e. no processor, cyclic, empty etc)
143  //- patches
144  static labelList nonConstraintPatches(const polyMesh& mesh);
145 
146  //- Create single patch of all supplied faces
147  static autoPtr<indirectPrimitivePatch> makePatch
148  (
149  const polyMesh& mesh,
150  const labelList& patchIDs,
151  const labelList& zoneIDs,
152  const pointField& points0
153  );
154 
155  //- Check with current points
156  void checkMesh
157  (
158  const pointField& currentPoints,
159  const vectorField& fCtrs,
160  const vectorField& fAreas,
161  const vectorField& cellCtrs,
162  const scalarField& cellVols,
163  labelHashSet& markedFaces,
164  bitSet& markedPoints
165  ) const;
166 
167  //- Apply current constraints (from pointDisplacement) to supplied
168  // locations
169  void constrainDisplacement(pointField& points) const;
170 
171  //- Relax the points (supplied in pointDisplacement)
172  bool relax
173  (
174  const scalarList& relaxationFactors,
175  const bitSet& pointsToRelax,
176  const pointField& initialPoints,
177  const pointField& wantedPoints,
178  pointField& relaxedPoints,
179  labelList& relaxationLevel
180  ) const;
181  label countPos(const labelList& elems) const;
182  labelList countZeroOrPos(const label size, const labelList& lst) const;
183 
184  //- Helper: set in bitSet all elements with a certain value
185  void select(const labelUList&, const label val, bitSet& isVal) const;
186 
187  void laplaceSmooth
188  (
189  const label type,
190  const pointField& initialPoints,
191  pointField& newPoints
192  ) const;
193  void featLaplaceSmooth
194  (
195  const indirectPrimitivePatch& pp,
196  const pointField& initialPoints,
197  pointField& newPoints
198  ) const;
199  // Snap points using boundary evaluation ...
200  void snapBoundaryPoints
201  (
202  const scalar scale,
203  const pointField& initialPoints,
204  pointField& newPoints
205  ) const;
206 
207  //- Keep points on empty patches
208  void emptyCorrectPoints(pointVectorField& pointDisplacement) const;
209 
210 
211 public:
212 
213  //- Runtime type information
214  TypeName("hexMeshSmoother");
215 
216 
217  // Constructors
218 
219  //- Construct from a polyMesh and an IOdictionary
220  hexMeshSmootherMotionSolver
221  (
222  const polyMesh&,
223  const IOdictionary&
224  );
225 
226  //- Construct from components
227  hexMeshSmootherMotionSolver
228  (
229  const polyMesh& mesh,
230  const IOdictionary& dict,
231  const pointVectorField& pointDisplacement,
232  const pointIOField& points0
233  );
234 
235 
236  //- Destructor
237  virtual ~hexMeshSmootherMotionSolver();
238 
239 
240  // Member Functions
241 
242  //- Return point location obtained from the current motion field
243  virtual tmp<pointField> curPoints() const;
244 
245  //- Solve for motion
246  virtual void solve();
247 };
248 
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 } // End namespace Foam
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 #endif
257 
258 // ************************************************************************* //
List< scalar > scalarList
List of scalar.
Definition: scalarList.H:32
const labelList patchIDs(pbm.indices(polyPatchNames, true))
dictionary dict
const labelIOList & zoneIDs
Definition: correctPhi.H:59
UEqn relax()
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:38
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field...
UList< label > labelUList
A UList of labels.
Definition: UList.H:76
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:801
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const pointField & points
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
SolverPerformance< Type > solve(faMatrix< Type > &, const dictionary &solverControls)
Solve returning the solution statistics given convergence tolerance.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:68
const scalarField & cellVols
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, IOobject::NO_REGISTER)))
Field< vector > vectorField
Specialisation of Field<T> for vector.
List< label > labelList
A List of labels.
Definition: List.H:61
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.