points0MotionSolver.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) 2012-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2019 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 
29 #include "points0MotionSolver.H"
30 #include "mapPolyMesh.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(points0MotionSolver, 0);
37 }
38 
39 
40 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
41 
43 {
44  const word instance =
46  (
47  mesh.meshDir(),
48  "points0",
50  );
51 
52  IOobject io
53  (
54  "points0",
55  instance,
57  mesh,
60  false
61  );
62 
63  // If points0 are located in constant directory, verify their existence
64  // or fallback to a copy of the original mesh points
65  if
66  (
67  instance == mesh.time().constant()
68  && !io.typeHeaderOk<pointIOField>()
69  )
70  {
71  io.rename("points");
72  }
73 
74  return io;
75 }
76 
77 
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 
80 Foam::points0MotionSolver::points0MotionSolver
81 (
82  const polyMesh& mesh,
83  const IOdictionary& dict,
84  const word& type
85 )
86 :
89  points0_(points0IO(mesh))
90 {
91  if
92  (
94  && (points0_.size() > mesh.nPoints())
95  )
96  {
97  // Allowed
98  }
99  else if (points0_.size() != mesh.nPoints())
100  {
102  << "Number of points in mesh " << mesh.nPoints()
103  << " differs from number of points " << points0_.size()
104  << " read from file "
105  << typeFilePath<pointIOField>
106  (
107  IOobject
108  (
109  "points",
110  time().constant(),
112  mesh,
115  false
116  )
117  )
118  << exit(FatalError);
119  }
120 }
121 
122 
123 Foam::points0MotionSolver::points0MotionSolver
124 (
125  const polyMesh& mesh,
126  const IOdictionary& dict,
127  const pointIOField& points0,
128  const word& type
129 )
130 :
132  zoneMotion(dict, mesh),
133  points0_(points0)
134 {
135  if (points0_.size() != mesh.nPoints())
136  {
138  << "Number of points in mesh " << mesh.nPoints()
139  << " differs from number of points " << points0_.size()
140  << " read from file " << points0.filePath()
141  << exit(FatalError);
142  }
143 }
144 
145 
146 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
147 
149 {}
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
155 {}
156 
157 
159 {
160  // pointMesh already updates pointFields
161 
163 
164  // Map points0_. Bit special since we somehow have to come up with
165  // a sensible points0 position for introduced points.
166  // Find out scaling between points0 and current points
167 
168  // Get the new points either from the map or the mesh
169  const pointField& points =
170  (
171  mpm.hasMotionPoints()
172  ? mpm.preMotionPoints()
173  : mesh().points()
174  );
175 
176  // Note: boundBox does reduce
177  const vector span0 = boundBox(points0_).span();
178  const vector span = boundBox(points).span();
179 
180  vector scaleFactors(cmptDivide(span0, span));
181 
182  pointField newPoints0(mpm.pointMap().size());
183 
184  forAll(newPoints0, pointi)
185  {
186  label oldPointi = mpm.pointMap()[pointi];
187 
188  if (oldPointi >= 0)
189  {
190  label masterPointi = mpm.reversePointMap()[oldPointi];
191 
192  if (masterPointi == pointi)
193  {
194  newPoints0[pointi] = points0_[oldPointi];
195  }
196  else
197  {
198  // New point - assume motion is scaling
199  newPoints0[pointi] = points0_[oldPointi] + cmptMultiply
200  (
201  scaleFactors,
202  points[pointi] - points[masterPointi]
203  );
204  }
205  }
206  else
207  {
209  << "Cannot determine coordinates of introduced vertices."
210  << " New vertex " << pointi << " at coordinate "
211  << points[pointi] << exit(FatalError);
212  }
213  }
214 
215  twoDCorrectPoints(newPoints0);
216 
217  points0_.transfer(newPoints0);
218 
219  // points0 changed - set to write and check-in to database
220  points0_.rename("points0");
221  points0_.writeOpt() = IOobject::AUTO_WRITE;
222  points0_.instance() = time().timeName();
223  points0_.checkIn();
224 }
225 
226 
227 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
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::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::FieldBase::allowConstructFromLargerSize
static bool allowConstructFromLargerSize
Definition: FieldBase.H:61
Foam::IOobject::typeHeaderOk
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) and check its info.
Definition: IOobjectTemplates.C:39
mapPolyMesh.H
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobjectI.H:191
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:321
Foam::mapPolyMesh::preMotionPoints
const pointField & preMotionPoints() const
Pre-motion point positions.
Definition: mapPolyMesh.H:613
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::points0MotionSolver::points0IO
static IOobject points0IO(const polyMesh &mesh)
Return IO object for points0.
Definition: points0MotionSolver.C:42
Foam::boundBox::span
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:127
Foam::Field< vector >
points0MotionSolver.H
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:122
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::points0MotionSolver::~points0MotionSolver
virtual ~points0MotionSolver()
Destructor.
Definition: points0MotionSolver.C:148
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobject::rename
virtual void rename(const word &newName)
Rename.
Definition: IOobject.H:389
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
Definition: Time.C:797
Foam::polyMesh::meshDir
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: polyMesh.C:840
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
points0
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false)))
Foam::zoneMotion
Definition: zoneMotion.H:55
Foam::points0MotionSolver::movePoints
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Definition: points0MotionSolver.C:154
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::motionSolver
Virtual base class for mesh motion solver.
Definition: motionSolver.H:58
Foam::points0MotionSolver::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update local data for topology changes.
Definition: points0MotionSolver.C:158
Foam::mapPolyMesh::reversePointMap
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:469
Foam::Vector< scalar >
Foam::mapPolyMesh::pointMap
const labelList & pointMap() const
Old point map.
Definition: mapPolyMesh.H:396
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::motionSolver::updateMesh
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:213
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::primitiveMesh::nPoints
label nPoints() const
Number of mesh points.
Definition: primitiveMeshI.H:37
Foam::motionSolver::mesh
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:144
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::mapPolyMesh::hasMotionPoints
bool hasMotionPoints() const
Has valid preMotionPoints?
Definition: mapPolyMesh.H:619
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
constant
constant condensation/saturation model.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::IOobject::MUST_READ
Definition: IOobject.H:120