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-2014 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  (
135  "displacementMotionSolver::"
136  "displacementMotionSolver\n"
137  "(\n"
138  " const polyMesh&,\n"
139  " const IOdictionary&,\n"
140  " const word&\n"
141  ")"
142  ) << "Number of points in mesh " << mesh.nPoints()
143  << " differs from number of points " << points0_.size()
144  << " read from file "
145  <<
146  IOobject
147  (
148  "points",
149  time().constant(),
151  mesh,
154  false
155  ).filePath()
156  << exit(FatalError);
157  }
158 }
159 
160 
161 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
162 
164 {}
165 
166 
167 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
168 
170 {
171  // No local data to update
172 }
173 
174 
176 {
177  // pointMesh already updates pointFields
178 
180 
181  // Map points0_. Bit special since we somehow have to come up with
182  // a sensible points0 position for introduced points.
183  // Find out scaling between points0 and current points
184 
185  // Get the new points either from the map or the mesh
186  const pointField& points =
187  (
188  mpm.hasMotionPoints()
189  ? mpm.preMotionPoints()
190  : mesh().points()
191  );
192 
193  // Note: boundBox does reduce
194  const vector span0 = boundBox(points0_).span();
195  const vector span = boundBox(points).span();
196 
197  vector scaleFactors(cmptDivide(span0, span));
198 
199  pointField newPoints0(mpm.pointMap().size());
200 
201  forAll(newPoints0, pointI)
202  {
203  label oldPointI = mpm.pointMap()[pointI];
204 
205  if (oldPointI >= 0)
206  {
207  label masterPointI = mpm.reversePointMap()[oldPointI];
208 
209  if (masterPointI == pointI)
210  {
211  newPoints0[pointI] = points0_[oldPointI];
212  }
213  else
214  {
215  // New point - assume motion is scaling
216  newPoints0[pointI] = points0_[oldPointI] + cmptMultiply
217  (
218  scaleFactors,
219  points[pointI] - points[masterPointI]
220  );
221  }
222  }
223  else
224  {
226  (
227  "displacementMotionSolver::updateMesh"
228  "(const mapPolyMesh&)"
229  ) << "Cannot determine co-ordinates of introduced vertices."
230  << " New vertex " << pointI << " at co-ordinate "
231  << points[pointI] << exit(FatalError);
232  }
233  }
234 
235  twoDCorrectPoints(newPoints0);
236 
237  points0_.transfer(newPoints0);
238 
239  // points0 changed - set to write and check-in to database
240  points0_.rename("points0");
241  points0_.writeOpt() = IOobject::AUTO_WRITE;
242  points0_.instance() = time().timeName();
243  points0_.checkIn();
244 }
245 
246 
247 // ************************************************************************* //
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
const pointField & points
virtual ~displacementMotionSolver()
Destructor.
virtual void updateMesh(const mapPolyMesh &)
Update local data for topology changes.
fileName filePath() const
Return complete path + object name if the file exists.
Definition: IOobject.C:323
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:178
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:465
static const pointMesh & New(const polyMesh &mesh)
bool hasMotionPoints() const
Has valid preMotionPoints?
Definition: mapPolyMesh.H:615
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:84
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
dynamicFvMesh & mesh
Virtual base class for mesh motion solver.
Definition: motionSolver.H:53
Namespace for OpenFOAM.
const pointField & preMotionPoints() const
Pre-motion point positions.
Definition: mapPolyMesh.H:609
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1035
#define forAll(list, i)
Definition: UList.H:421
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
error FatalError
Constant dispersed-phase particle diameter model.
const labelList & pointMap() const
Old point map.
Definition: mapPolyMesh.H:392
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: polyMesh.C:812
bool headerOk()
Read and check header info.
Definition: IOobject.C:424
IOobject points0IO(const polyMesh &mesh) const
Return IO object for points0.
label nPoints() const
defineTypeNameAndDebug(combustionModel, 0)
word timeName
Definition: getTimeIndex.H:3