displacementMotionSolverMeshMover.C
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) 2015 OpenFOAM Foundation
9  Copyright (C) 2015 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "pointConstraints.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(displacementMotionSolverMeshMover, 1);
38 
40  (
41  externalDisplacementMeshMover,
42  displacementMotionSolverMeshMover,
43  dictionary
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 bool Foam::displacementMotionSolverMeshMover::moveMesh
51 (
52  const dictionary& moveDict,
53  const label nAllowableErrors,
54  labelList& checkFaces
55 )
56 {
57  const label nRelaxIter = moveDict.get<label>("nRelaxIter");
58 
59  meshMover_.setDisplacementPatchFields();
60 
61  Info<< typeName << " : Moving mesh ..." << endl;
62 
63  scalar oldErrorReduction = -1;
64 
65  bool meshOk = false;
66 
67  for (label iter = 0; iter < 2*nRelaxIter; ++ iter)
68  {
69  Info<< typeName << " : Iteration " << iter << endl;
70 
71  if (iter == nRelaxIter)
72  {
73  Info<< typeName
74  << " : Displacement scaling for error reduction set to 0."
75  << endl;
76  oldErrorReduction = meshMover_.setErrorReduction(0.0);
77  }
78 
79  if
80  (
81  meshMover_.scaleMesh
82  (
83  checkFaces,
84  baffles_,
85  meshMover_.paramDict(),
86  moveDict,
87  true,
88  nAllowableErrors
89  )
90  )
91  {
92  Info<< typeName << " : Successfully moved mesh" << endl;
93  meshOk = true;
94  break;
95  }
96  }
97 
98  if (oldErrorReduction >= 0)
99  {
100  meshMover_.setErrorReduction(oldErrorReduction);
101  }
102 
103  Info<< typeName << " : Finished moving mesh ..." << endl;
104 
105  return meshOk;
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 
112 (
113  const dictionary& dict,
114  const List<labelPair>& baffles,
115  pointVectorField& pointDisplacement,
116  const bool dryRun
117 )
118 :
119  externalDisplacementMeshMover(dict, baffles, pointDisplacement, dryRun),
120 
121  solverPtr_
122  (
124  (
125  dict.get<word>("solver"),
126  pointDisplacement.mesh()(),
128  (
129  IOobject
130  (
131  "motionSolverDict",
132  pointDisplacement.mesh().time().constant(),
133  pointDisplacement.db(),
136  false
137  ),
138  dict
139  ),
140  pointDisplacement,
142  (
143  IOobject
144  (
145  "points0",
146  pointDisplacement.mesh().time().constant(),
147  pointDisplacement.db(),
150  false
151  ),
152  pointDisplacement.mesh()().points()
153  )
154  )
155  ),
156 
157  adaptPatchIDs_(getFixedValueBCs(pointDisplacement)),
158  adaptPatchPtr_(getPatch(mesh(), adaptPatchIDs_)),
159 
160  scale_
161  (
162  IOobject
163  (
164  "scale",
165  pointDisplacement.time().timeName(),
166  pointDisplacement.db(),
169  ),
170  pMesh(),
171  dimensionedScalar("scale", dimless, 1.0)
172  ),
173 
174  oldPoints_(mesh().points()),
175 
176  meshMover_
177  (
178  const_cast<polyMesh&>(mesh()),
179  const_cast<pointMesh&>(pMesh()),
180  adaptPatchPtr_(),
181  pointDisplacement,
182  scale_,
183  oldPoints_,
184  adaptPatchIDs_,
185  dict,
186  dryRun
187  ),
188 
189  fieldSmoother_(mesh())
190 {}
191 
192 
193 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
194 
196 {}
197 
198 
199 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
200 
202 (
203  const dictionary& moveDict,
204  const label nAllowableErrors,
205  labelList& checkFaces
206 )
207 {
208  // Correct and smooth the patch displacements so points next to
209  // points where the extrusion was disabled also use less extrusion.
210  // Note that this has to update the pointDisplacement boundary conditions
211  // as well, not just the internal field.
212  {
213  const label nSmoothPatchThickness = meshRefinement::get<label>
214  (
215  moveDict, "nSmoothThickness", dryRun_, keyType::REGEX
216  );
217 
218  const word minThicknessName = meshRefinement::get<word>
219  (
220  moveDict, "minThicknessName", dryRun_, keyType::REGEX, word::null
221  );
222 
223  scalarField zeroMinThickness;
224 
225  if (minThicknessName == "none")
226  {
227  zeroMinThickness = scalarField(adaptPatchPtr_().nPoints(), Zero);
228  }
229 
230  const scalarField& minThickness =
231  (
232  (minThicknessName == "none")
233  ? zeroMinThickness
234  : mesh().lookupObject<scalarField>(minThicknessName)
235  );
236 
237  const bitSet isPatchMasterPoint
238  (
240  (
241  mesh(),
242  adaptPatchPtr_().meshPoints()
243  )
244  );
245 
246  const bitSet isPatchMasterEdge
247  (
249  (
250  mesh(),
251  adaptPatchPtr_().meshEdges
252  (
253  mesh().edges(),
254  mesh().pointEdges()
255  )
256  )
257  );
258 
259  // Smooth patch displacement
260 
261  vectorField displacement
262  (
263  pointDisplacement().internalField(),
264  adaptPatchPtr_().meshPoints()
265  );
266 
267  fieldSmoother_.minSmoothField
268  (
269  nSmoothPatchThickness,
270  isPatchMasterPoint,
271  isPatchMasterEdge,
272  adaptPatchPtr_(),
273  minThickness,
274  displacement
275  );
276 
277 
278  scalar resid = 0;
279 
280  forAll(displacement, patchPointI)
281  {
282  const label pointI(adaptPatchPtr_().meshPoints()[patchPointI]);
283 
284  resid += mag(pointDisplacement()[pointI]-displacement[patchPointI]);
285 
286  pointDisplacement()[pointI] = displacement[patchPointI];
287  }
288 
289  // Take over smoothed displacements on bcs
290  meshMover_.setDisplacementPatchFields();
291  }
292 
293  // Use motionSolver to calculate internal displacement
294  {
295  solverPtr_->pointDisplacement() == pointDisplacement();
296  // Force solving and constraining - just so its pointDisplacement gets
297  // the correct value
298  (void)solverPtr_->newPoints();
299  pointDisplacement() == solverPtr_->pointDisplacement();
300  }
301 
302  return moveMesh(moveDict, nAllowableErrors, checkFaces);
303 }
304 
305 
307 {
309 
310  // Update motion solver for new geometry
311  solverPtr_->movePoints(p);
312 
313  // Update motionSmoother for new geometry (moves adaptPatchPtr_)
314  meshMover_.movePoints();
315 
316  // Assume current mesh location is correct (reset oldPoints, scale)
317  meshMover_.correct();
318 }
319 
320 
321 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::displacementMotionSolverMeshMover::displacementMotionSolverMeshMover
displacementMotionSolverMeshMover(const dictionary &dict, const List< labelPair > &baffles, pointVectorField &pointDisplacement, const bool dryRun)
Construct from a polyMesh and an IOdictionary.
Definition: displacementMotionSolverMeshMover.C:112
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::motionSmootherAlgo::setErrorReduction
scalar setErrorReduction(const scalar)
Set the errorReduction (by how much to scale the displacement.
Definition: motionSmootherAlgo.C:698
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::displacementMotionSolver::New
static autoPtr< displacementMotionSolver > New(const word &solverTypeName, const polyMesh &, const IOdictionary &, const pointVectorField &pointDisplacement, const pointIOField &points0)
Select constructed from polyMesh, dictionary and components.
Definition: displacementMotionSolver.C:87
Foam::displacementMotionSolverMeshMover::~displacementMotionSolverMeshMover
virtual ~displacementMotionSolverMeshMover()
Destructor.
Definition: displacementMotionSolverMeshMover.C:195
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::displacementMotionSolverMeshMover::movePoints
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Definition: displacementMotionSolverMeshMover.C:306
Foam::motionSmootherAlgo::scaleMesh
bool scaleMesh(labelList &checkFaces, const bool smoothMesh=true, const label nAllow=0)
Move mesh with given scale. Return true if mesh ok or has.
Definition: motionSmootherAlgo.C:712
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::meshRefinement::getMasterEdges
static bitSet getMasterEdges(const polyMesh &mesh, const labelList &meshEdges)
Determine master edge for subset of edges. If coupled.
Definition: meshRefinement.C:3140
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
pointConstraints.H
displacementMotionSolverMeshMover.H
Foam::externalDisplacementMeshMover::movePoints
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Definition: externalDisplacementMeshMover.C:175
Foam::displacementMotionSolverMeshMover::move
virtual bool move(const dictionary &, const label nAllowableErrors, labelList &checkFaces)
Move mesh using current pointDisplacement boundary values.
Definition: displacementMotionSolverMeshMover.C:202
Foam::externalDisplacementMeshMover
Virtual base class for mesh movers with externally provided displacement field giving the boundary co...
Definition: externalDisplacementMeshMover.H:58
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::externalDisplacementMeshMover::baffles_
List< labelPair > baffles_
Baffles in the mesh.
Definition: externalDisplacementMeshMover.H:65
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:51
Foam::motionSmootherAlgo::paramDict
const dictionary & paramDict() const
Definition: motionSmootherAlgo.C:385
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::keyType::REGEX
Regular expression.
Definition: keyType.H:82
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::motionSmootherAlgo::setDisplacementPatchFields
static void setDisplacementPatchFields(const labelList &patchIDs, pointVectorField &pointDisplacement)
Set patch fields on patchIDs to be consistent with.
Definition: motionSmootherAlgo.C:404
Foam::GeometricField< vector, pointPatchField, pointMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::meshRefinement::getMasterPoints
static bitSet getMasterPoints(const polyMesh &mesh, const labelList &meshPoints)
Determine master point for subset of points. If coupled.
Definition: meshRefinement.C:3104
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189