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 | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "pointConstraints.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(displacementMotionSolverMeshMover, 1);
35 
37  (
38  externalDisplacementMeshMover,
39  displacementMotionSolverMeshMover,
40  dictionary
41  );
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
48 (
49  const dictionary& moveDict,
50  const label nAllowableErrors,
51  labelList& checkFaces
52 )
53 {
54  const label nRelaxIter = readLabel(moveDict.lookup("nRelaxIter"));
55 
56  meshMover_.setDisplacementPatchFields();
57 
58  Info<< typeName << " : Moving mesh ..." << endl;
59 
60  scalar oldErrorReduction = -1;
61 
62  bool meshOk = false;
63 
64  for (label iter = 0; iter < 2*nRelaxIter; ++ iter)
65  {
66  Info<< typeName << " : Iteration " << iter << endl;
67 
68  if (iter == nRelaxIter)
69  {
70  Info<< typeName
71  << " : Displacement scaling for error reduction set to 0."
72  << endl;
73  oldErrorReduction = meshMover_.setErrorReduction(0.0);
74  }
75 
76  if
77  (
78  meshMover_.scaleMesh
79  (
80  checkFaces,
81  baffles_,
82  meshMover_.paramDict(),
83  moveDict,
84  true,
85  nAllowableErrors
86  )
87  )
88  {
89  Info<< typeName << " : Successfully moved mesh" << endl;
90  meshOk = true;
91  break;
92  }
93  }
94 
95  if (oldErrorReduction >= 0)
96  {
97  meshMover_.setErrorReduction(oldErrorReduction);
98  }
99 
100  Info<< typeName << " : Finished moving mesh ..." << endl;
101 
102  return meshOk;
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107 
109 (
110  const dictionary& dict,
111  const List<labelPair>& baffles,
112  pointVectorField& pointDisplacement
113 )
114 :
115  externalDisplacementMeshMover(dict, baffles, pointDisplacement),
116 
117  solverPtr_
118  (
120  (
121  dict.lookup("solver"),
122  pointDisplacement.mesh()(),
124  (
125  IOobject
126  (
127  "motionSolverDict",
128  pointDisplacement.mesh().time().constant(),
129  pointDisplacement.db(),
130  IOobject::NO_READ,
131  IOobject::NO_WRITE,
132  false
133  ),
134  dict
135  ),
136  pointDisplacement,
138  (
139  IOobject
140  (
141  "points0",
142  pointDisplacement.mesh().time().constant(),
143  pointDisplacement.db(),
144  IOobject::NO_READ,
145  IOobject::NO_WRITE,
146  false
147  ),
148  pointDisplacement.mesh()().points()
149  )
150  )
151  ),
152 
153  adaptPatchIDs_(getFixedValueBCs(pointDisplacement)),
154  adaptPatchPtr_(getPatch(mesh(), adaptPatchIDs_)),
155 
156  scale_
157  (
158  IOobject
159  (
160  "scale",
161  pointDisplacement.time().timeName(),
162  pointDisplacement.db(),
163  IOobject::NO_READ,
164  IOobject::AUTO_WRITE
165  ),
166  pMesh(),
167  dimensionedScalar("scale", dimless, 1.0)
168  ),
169 
170  oldPoints_(mesh().points()),
171 
172  meshMover_
173  (
174  const_cast<polyMesh&>(mesh()),
175  const_cast<pointMesh&>(pMesh()),
176  adaptPatchPtr_(),
177  pointDisplacement,
178  scale_,
179  oldPoints_,
180  adaptPatchIDs_,
181  dict
182  ),
183 
184  fieldSmoother_(mesh())
185 {}
186 
187 
188 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
189 
191 {}
192 
193 
194 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
195 
197 (
198  const dictionary& moveDict,
199  const label nAllowableErrors,
200  labelList& checkFaces
201 )
202 {
203  // Correct and smooth the patch displacements so points next to
204  // points where the extrusion was disabled also use less extrusion.
205  // Note that this has to update the pointDisplacement boundary conditions
206  // as well, not just the internal field.
207  {
208  const label nSmoothPatchThickness = readLabel
209  (
210  moveDict.lookup("nSmoothThickness")
211  );
212 
213  const word minThicknessName = word(moveDict.lookup("minThicknessName"));
214 
215  scalarField zeroMinThickness;
216 
217  if (minThicknessName == "none")
218  {
219  zeroMinThickness = scalarField(adaptPatchPtr_().nPoints(), 0.0);
220  }
221 
222  const scalarField& minThickness =
223  (
224  (minThicknessName == "none")
225  ? zeroMinThickness
226  : mesh().lookupObject<scalarField>(minThicknessName)
227  );
228 
229  const PackedBoolList isPatchMasterPoint
230  (
232  (
233  mesh(),
234  adaptPatchPtr_().meshPoints()
235  )
236  );
237 
238  const PackedBoolList isPatchMasterEdge
239  (
241  (
242  mesh(),
243  adaptPatchPtr_().meshEdges
244  (
245  mesh().edges(),
246  mesh().pointEdges()
247  )
248  )
249  );
250 
251  // Smooth patch displacement
252 
253  vectorField displacement
254  (
255  pointDisplacement().internalField(),
256  adaptPatchPtr_().meshPoints()
257  );
258 
259  fieldSmoother_.minSmoothField
260  (
261  nSmoothPatchThickness,
262  isPatchMasterPoint,
263  isPatchMasterEdge,
264  adaptPatchPtr_(),
265  minThickness,
266  displacement
267  );
268 
269 
270  scalar resid = 0;
271 
272  forAll(displacement, patchPointI)
273  {
274  const label pointI(adaptPatchPtr_().meshPoints()[patchPointI]);
275 
276  resid += mag(pointDisplacement()[pointI]-displacement[patchPointI]);
277 
278  pointDisplacement()[pointI] = displacement[patchPointI];
279  }
280 
281  // Take over smoothed displacements on bcs
282  meshMover_.setDisplacementPatchFields();
283  }
284 
285  // Use motionSolver to calculate internal displacement
286  {
287  solverPtr_->pointDisplacement() == pointDisplacement();
288  // Force solving and constraining - just so its pointDisplacement gets
289  // the correct value
290  (void)solverPtr_->newPoints();
291  pointDisplacement() == solverPtr_->pointDisplacement();
292  }
293 
294  return moveMesh(moveDict, nAllowableErrors, checkFaces);
295 }
296 
297 
299 {
301 
302  // Update motion solver for new geometry
303  solverPtr_->movePoints(p);
304 
305  // Update motionSmoother for new geometry (moves adaptPatchPtr_)
306  meshMover_.movePoints();
307 
308  // Assume current mesh location is correct (reset oldPoints, scale)
309  meshMover_.correct();
310 }
311 
312 
313 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:48
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::PackedBoolList
A bit-packed bool list.
Definition: PackedBoolList.H:63
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::displacementMotionSolverMeshMover::~displacementMotionSolverMeshMover
virtual ~displacementMotionSolverMeshMover()
Destructor.
Definition: displacementMotionSolverMeshMover.C:190
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::displacementMotionSolverMeshMover::displacementMotionSolverMeshMover
displacementMotionSolverMeshMover(const dictionary &dict, const List< labelPair > &baffles, pointVectorField &pointDisplacemen)
Construct from a polyMesh and an IOdictionary.
Definition: displacementMotionSolverMeshMover.C:109
Foam::IOField< vector >
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::displacementMotionSolverMeshMover::movePoints
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Definition: displacementMotionSolverMeshMover.C:298
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
pointConstraints.H
displacementMotionSolverMeshMover.H
Foam::externalDisplacementMeshMover::movePoints
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Definition: externalDisplacementMeshMover.C:172
Foam::displacementMotionSolverMeshMover::move
virtual bool move(const dictionary &, const label nAllowableErrors, labelList &checkFaces)
Move mesh using current pointDisplacement boundary values.
Definition: displacementMotionSolverMeshMover.C:197
Foam::externalDisplacementMeshMover
Virtual base class for mesh movers with externally provided displacement field giving the boundary co...
Definition: externalDisplacementMeshMover.H:56
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:41
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
Foam::meshRefinement::getMasterEdges
static PackedBoolList getMasterEdges(const polyMesh &mesh, const labelList &meshEdges)
Determine master edge for subset of edges. If coupled.
Definition: meshRefinement.C:2784
internalField
conserve internalField()+
Foam::meshRefinement::getMasterPoints
static PackedBoolList getMasterPoints(const polyMesh &mesh, const labelList &meshPoints)
Determine master point for subset of points. If coupled.
Definition: meshRefinement.C:2747
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::displacementMotionSolverMeshMover::moveMesh
bool moveMesh(const dictionary &moveDict, const label nAllowableErrors, labelList &checkFaces)
Apply the mesh mover algorithm.
Definition: displacementMotionSolverMeshMover.C:48
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)