displacementMotionSolver.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) 2012-2016 OpenFOAM Foundation
6  \\/ M anipulation |
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 
27 #include "mapPolyMesh.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(displacementMotionSolver, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * * Protected Data Members * * * * * * * * * * * * * //
38 
40 (
41  const polyMesh& mesh
42 ) const
43 {
44  const word instance =
45  time().findInstance
46  (
47  mesh.meshDir(),
48  "points0",
50  );
51 
52  if (instance != time().constant())
53  {
54  // points0 written to a time folder
55 
56  return
57  IOobject
58  (
59  "points0",
60  instance,
62  mesh,
65  false
66  );
67  }
68  else
69  {
70  // check that points0 are actually in constant directory
71 
72  IOobject io
73  (
74  "points0",
75  instance,
77  mesh,
80  false
81  );
82 
83  if (io.headerOk())
84  {
85  return io;
86  }
87  else
88  {
89  // copy of original mesh points
90 
91  return
92  IOobject
93  (
94  "points",
95  instance,
97  mesh,
100  false
101  );
102  }
103  }
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
108 
109 Foam::displacementMotionSolver::displacementMotionSolver
110 (
111  const polyMesh& mesh,
112  const IOdictionary& dict,
113  const word& type
114 )
115 :
116  motionSolver(mesh, dict, type),
117  pointDisplacement_
118  (
119  IOobject
120  (
121  "pointDisplacement",
122  time().timeName(),
123  mesh,
126  ),
127  pointMesh::New(mesh)
128  ),
129  points0_(pointIOField(points0IO(mesh)))
130 {
131  if (points0_.size() != mesh.nPoints())
132  {
134  << "Number of points in mesh " << mesh.nPoints()
135  << " differs from number of points " << points0_.size()
136  << " read from file "
137  <<
138  IOobject
139  (
140  "points",
141  time().constant(),
143  mesh,
146  false
147  ).filePath()
148  << exit(FatalError);
149  }
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
162 {
163  // No local data to update
164 }
165 
166 
168 {
169  // pointMesh already updates pointFields
170 
172 
173  // Map points0_. Bit special since we somehow have to come up with
174  // a sensible points0 position for introduced points.
175  // Find out scaling between points0 and current points
176 
177  // Get the new points either from the map or the mesh
178  const pointField& points =
179  (
180  mpm.hasMotionPoints()
181  ? mpm.preMotionPoints()
182  : mesh().points()
183  );
184 
185  // Note: boundBox does reduce
186  const vector span0 = boundBox(points0_).span();
187  const vector span = boundBox(points).span();
188 
189  vector scaleFactors(cmptDivide(span0, span));
190 
191  pointField newPoints0(mpm.pointMap().size());
192 
193  forAll(newPoints0, pointi)
194  {
195  label oldPointi = mpm.pointMap()[pointi];
196 
197  if (oldPointi >= 0)
198  {
199  label masterPointi = mpm.reversePointMap()[oldPointi];
200 
201  if (masterPointi == pointi)
202  {
203  newPoints0[pointi] = points0_[oldPointi];
204  }
205  else
206  {
207  // New point - assume motion is scaling
208  newPoints0[pointi] = points0_[oldPointi] + cmptMultiply
209  (
210  scaleFactors,
211  points[pointi] - points[masterPointi]
212  );
213  }
214  }
215  else
216  {
218  << "Cannot determine co-ordinates of introduced vertices."
219  << " New vertex " << pointi << " at co-ordinate "
220  << points[pointi] << exit(FatalError);
221  }
222  }
223 
224  twoDCorrectPoints(newPoints0);
225 
226  points0_.transfer(newPoints0);
227 
228  // points0 changed - set to write and check-in to database
229  points0_.rename("points0");
230  points0_.writeOpt() = IOobject::AUTO_WRITE;
231  points0_.instance() = time().timeName();
232  points0_.checkIn();
233 }
234 
235 
236 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
IOobject points0IO(const polyMesh &mesh) const
Return IO object for points0.
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
bool hasMotionPoints() const
Has valid preMotionPoints?
Definition: mapPolyMesh.H:613
const labelList & pointMap() const
Old point map.
Definition: mapPolyMesh.H:390
Virtual base class for mesh motion solver.
Definition: motionSolver.H:53
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
virtual void updateMesh(const mapPolyMesh &)
Update local data for topology changes.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: polyMesh.C:766
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
static const pointMesh & New(const polyMesh &mesh)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
virtual void movePoints(const pointField &)
Update local data for geometry changes.
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:174
dynamicFvMesh & mesh
fileName filePath() const
Return complete path + object name if the file exists.
Definition: IOobject.C:299
const pointField & points
A class for handling words, derived from string.
Definition: word.H:59
word timeName
Definition: getTimeIndex.H:3
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:84
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
virtual ~displacementMotionSolver()
Destructor.
Constant dispersed-phase particle diameter model.
label nPoints() const
bool headerOk()
Read and check header info.
Definition: IOobject.C:400
const pointField & preMotionPoints() const
Pre-motion point positions.
Definition: mapPolyMesh.H:607
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Namespace for OpenFOAM.
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:463