componentDisplacementMotionSolver.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) 2020 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 
30 #include "mapPolyMesh.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(componentDisplacementMotionSolver, 0);
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 Foam::direction Foam::componentDisplacementMotionSolver::cmpt
43 (
44  const word& cmptName
45 ) const
46 {
47  if (cmptName == "x")
48  {
49  return vector::X;
50  }
51  else if (cmptName == "y")
52  {
53  return vector::Y;
54  }
55  else if (cmptName == "z")
56  {
57  return vector::Z;
58  }
59  else
60  {
62  << "Given component name " << cmptName << " should be x, y or z"
63  << exit(FatalError);
64 
65  return 0;
66  }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
72 Foam::componentDisplacementMotionSolver::componentDisplacementMotionSolver
73 (
74  const polyMesh& mesh,
75  const IOdictionary& dict,
76  const word& type
77 )
78 :
80  cmptName_(coeffDict().get<word>("component")),
81  cmpt_(cmpt(cmptName_)),
82  points0_
83  (
85  (
86  IOobject
87  (
88  "points",
89  time().constant(),
91  mesh,
94  false
95  )
96  ).component(cmpt_)
97  ),
98  pointDisplacement_
99  (
100  IOobject
101  (
102  "pointDisplacement" + cmptName_,
103  mesh.time().timeName(),
104  mesh,
107  ),
109  )
110 {
111  if (points0_.size() != mesh.nPoints())
112  {
114  << "Number of points in mesh " << mesh.nPoints()
115  << " differs from number of points " << points0_.size()
116  << " read from file "
117  << typeFilePath<pointIOField>
118  (
119  IOobject
120  (
121  "points",
122  mesh.time().constant(),
124  mesh,
127  false
128  )
129  )
130  << exit(FatalError);
131  }
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
136 
138 {}
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
144 {
145  // No local data to update
146 }
147 
148 
150 {
151  // pointMesh already updates pointFields.
152 
154 
155  // Map points0_. Bit special since we somehow have to come up with
156  // a sensible points0 position for introduced points.
157  // Find out scaling between points0 and current points
158 
159  // Get the new points either from the map or the mesh
160  const scalarField points
161  (
162  mpm.hasMotionPoints()
163  ? mpm.preMotionPoints().component(cmpt_)
164  : mesh().points().component(cmpt_)
165  );
166 
167  // Get extents of points0 and points and determine scale
168  const scalar scale =
169  (gMax(points0_)-gMin(points0_))
170  /(gMax(points)-gMin(points));
171 
172  scalarField newPoints0(mpm.pointMap().size());
173 
174  forAll(newPoints0, pointi)
175  {
176  label oldPointi = mpm.pointMap()[pointi];
177 
178  if (oldPointi >= 0)
179  {
180  label masterPointi = mpm.reversePointMap()[oldPointi];
181 
182  if (masterPointi == pointi)
183  {
184  newPoints0[pointi] = points0_[oldPointi];
185  }
186  else
187  {
188  // New point. Assume motion is scaling.
189  newPoints0[pointi] =
190  points0_[oldPointi]
191  + scale*(points[pointi]-points[masterPointi]);
192  }
193  }
194  else
195  {
197  << "Cannot work out coordinates of introduced vertices."
198  << " New vertex " << pointi << " at coordinate "
199  << points[pointi] << exit(FatalError);
200  }
201  }
202  points0_.transfer(newPoints0);
203 }
204 
205 
206 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
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:169
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::Vector< scalar >::Z
Definition: Vector.H:81
Foam::Vector< scalar >::Y
Definition: Vector.H:81
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
mapPolyMesh.H
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:321
Foam::MeshObject< polyMesh, UpdateableMeshObject, pointMesh >::New
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::mapPolyMesh::preMotionPoints
const pointField & preMotionPoints() const
Pre-motion point positions.
Definition: mapPolyMesh.H:613
Foam::componentDisplacementMotionSolver::movePoints
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Definition: componentDisplacementMotionSolver.C:143
componentDisplacementMotionSolver.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::componentDisplacementMotionSolver::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update local data for topology changes.
Definition: componentDisplacementMotionSolver.C:149
Foam::Field< vector >
Foam::Vector< scalar >::X
Definition: Vector.H:81
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::componentDisplacementMotionSolver::~componentDisplacementMotionSolver
virtual ~componentDisplacementMotionSolver()
Destructor.
Definition: componentDisplacementMotionSolver.C:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Field::component
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:539
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::motionSolver
Virtual base class for mesh motion solver.
Definition: motionSolver.H:58
Foam::mapPolyMesh::reversePointMap
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:469
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::direction
uint8_t direction
Definition: direction.H:52
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::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
constant
constant condensation/saturation model.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Foam::IOobject::MUST_READ
Definition: IOobject.H:185