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-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 
27 #include "mapPolyMesh.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(displacementMotionSolver, 0);
34  defineRunTimeSelectionTable(displacementMotionSolver, displacement);
35 }
36 
37 
38 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
39 
41 {
42  const word instance =
44  (
45  mesh.meshDir(),
46  "points0",
48  );
49 
50  if (instance != mesh.time().constant())
51  {
52  // points0 written to a time folder
53 
54  return
55  IOobject
56  (
57  "points0",
58  instance,
59  mesh.meshDir(),
60  mesh,
63  false
64  );
65  }
66  else
67  {
68  // check that points0 are actually in constant directory
69 
70  IOobject io
71  (
72  "points0",
73  instance,
74  mesh.meshDir(),
75  mesh,
78  false
79  );
80 
81  if (io.headerOk())
82  {
83  return io;
84  }
85  else
86  {
87  // copy of original mesh points
88 
89  return
90  IOobject
91  (
92  "points",
93  instance,
94  mesh.meshDir(),
95  mesh,
98  false
99  );
100  }
101  }
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
108 (
109  const polyMesh& mesh,
110  const IOdictionary& dict,
111  const word& type
112 )
113 :
115  pointDisplacement_
116  (
117  IOobject
118  (
119  "pointDisplacement",
120  time().timeName(),
121  mesh,
124  ),
126  ),
127  points0_(pointIOField(points0IO(mesh)))
128 {
129  if (points0_.size() != mesh.nPoints())
130  {
132  << "Number of points in mesh " << mesh.nPoints()
133  << " differs from number of points " << points0_.size()
134  << " read from file "
135  << IOobject
136  (
137  "points",
138  time().constant(),
139  mesh.meshDir(),
140  mesh,
143  false
144  ).filePath()
145  << exit(FatalError);
146  }
147 }
148 
149 
151 (
152  const polyMesh& mesh,
153  const IOdictionary& dict,
154  const pointVectorField& pointDisplacement,
155  const pointIOField& points0,
156  const word& type
157 )
158 :
160  pointDisplacement_
161  (
162  IOobject(pointDisplacement, "pointDisplacement"),
163  pointDisplacement
164  ),
165  points0_(points0)
166 {
167  if (points0_.size() != mesh.nPoints())
168  {
170  << "Number of points in mesh " << mesh.nPoints()
171  << " differs from number of points " << points0_.size()
172  << " read from file " << points0.filePath()
173  << exit(FatalError);
174  }
175 }
176 
177 
178 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
179 
182 (
183  const word& solverTypeName,
184  const polyMesh& mesh,
185  const IOdictionary& solverDict,
186  const pointVectorField& pointDisplacement,
187  const pointIOField& points0
188 )
189 {
190  //const word solverTypeName(solverDict.lookup("solver"));
191 
192  Info<< "Selecting motion solver: " << solverTypeName << endl;
193 
194  const_cast<Time&>(mesh.time()).libs().open
195  (
196  solverDict,
197  "motionSolverLibs",
198  displacementConstructorTablePtr_
199  );
200 
201  if (!displacementConstructorTablePtr_)
202  {
204  << "solver table is empty"
205  << exit(FatalError);
206  }
207 
208  displacementConstructorTable::iterator cstrIter =
209  displacementConstructorTablePtr_->find(solverTypeName);
210 
211  if (cstrIter == displacementConstructorTablePtr_->end())
212  {
214  << "Unknown solver type "
215  << solverTypeName << nl << nl
216  << "Valid solver types are:" << endl
217  << displacementConstructorTablePtr_->sortedToc()
218  << exit(FatalError);
219  }
220 
222  (
223  cstrIter()
224  (
225  mesh,
226  solverDict,
227  pointDisplacement,
228  points0
229  )
230  );
231 }
232 
233 
234 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
235 
237 {}
238 
239 
240 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
241 
243 {
244  // No local data to update
245 }
246 
247 
249 {
250  // pointMesh already updates pointFields
251 
253 
254  // Map points0_. Bit special since we somehow have to come up with
255  // a sensible points0 position for introduced points.
256  // Find out scaling between points0 and current points
257 
258  // Get the new points either from the map or the mesh
259  const pointField& points =
260  (
261  mpm.hasMotionPoints()
262  ? mpm.preMotionPoints()
263  : mesh().points()
264  );
265 
266  // Note: boundBox does reduce
267  const vector span0 = boundBox(points0_).span();
268  const vector span = boundBox(points).span();
269 
270  vector scaleFactors(cmptDivide(span0, span));
271 
272  pointField newPoints0(mpm.pointMap().size());
273 
274  forAll(newPoints0, pointI)
275  {
276  label oldPointI = mpm.pointMap()[pointI];
277 
278  if (oldPointI >= 0)
279  {
280  label masterPointI = mpm.reversePointMap()[oldPointI];
281 
282  if (masterPointI == pointI)
283  {
284  newPoints0[pointI] = points0_[oldPointI];
285  }
286  else
287  {
288  // New point - assume motion is scaling
289  newPoints0[pointI] = points0_[oldPointI] + cmptMultiply
290  (
291  scaleFactors,
292  points[pointI] - points[masterPointI]
293  );
294  }
295  }
296  else
297  {
299  << "Cannot determine co-ordinates of introduced vertices."
300  << " New vertex " << pointI << " at co-ordinate "
301  << points[pointI] << exit(FatalError);
302  }
303  }
304 
305  twoDCorrectPoints(newPoints0);
306 
307  points0_.transfer(newPoints0);
308 
309  // points0 changed - set to write and check-in to database
310  points0_.rename("points0");
311  points0_.writeOpt() = IOobject::AUTO_WRITE;
312  points0_.instance() = time().timeName();
313  points0_.checkIn();
314 }
315 
316 
317 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::IOobject::filePath
fileName filePath() const
Return complete path + object name if the file exists.
Definition: IOobject.C:336
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
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:182
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::IOField< vector >
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
mapPolyMesh.H
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::displacementMotionSolver::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update local data for topology changes.
Definition: displacementMotionSolver.C:248
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mapPolyMesh::preMotionPoints
const pointField & preMotionPoints() const
Pre-motion point positions.
Definition: mapPolyMesh.H:609
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobject.H:350
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::MeshObject< polyMesh, UpdateableMeshObject, pointMesh >::New
static const pointMesh & New(const polyMesh &mesh)
Definition: MeshObject.C:44
constant
Constant dispersed-phase particle diameter model.
Foam::boundBox::span
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:84
Foam::IOobject::headerOk
bool headerOk()
Read and check header info.
Definition: IOobject.C:439
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::displacementMotionSolver::~displacementMotionSolver
virtual ~displacementMotionSolver()
Destructor.
Definition: displacementMotionSolver.C:236
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::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Time::findInstance
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Return the location of "dir" containing the file "name".
Definition: findInstance.C:38
Foam::polyMesh::meshDir
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: polyMesh.C:766
displacementMotionSolver.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::autoPtr< Foam::displacementMotionSolver >
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::motionSolver
Virtual base class for mesh motion solver.
Definition: motionSolver.H:53
Foam::displacementMotionSolver::movePoints
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Definition: displacementMotionSolver.C:242
Foam::mapPolyMesh::reversePointMap
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:465
Foam::IOobject::IOobject
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:116
Foam::Vector< scalar >
Foam::mapPolyMesh::pointMap
const labelList & pointMap() const
Old point map.
Definition: mapPolyMesh.H:392
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePaths.H:130
Foam::motionSolver::updateMesh
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:174
points
const pointField & points
Definition: gmvOutputHeader.H:1
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::displacementMotionSolver::displacementMotionSolver
displacementMotionSolver(const displacementMotionSolver &)
Disallow default bitwise copy construct.
Foam::motionSolver::mesh
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:125
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::mapPolyMesh::hasMotionPoints
bool hasMotionPoints() const
Has valid preMotionPoints?
Definition: mapPolyMesh.H:615
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::displacementMotionSolver::points0IO
static IOobject points0IO(const polyMesh &mesh)
Return IO object for points0.
Definition: displacementMotionSolver.C:40
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: IOobject.H:110
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)