polyMeshUpdate.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) 2011-2016, 2020 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 Description
28  Update the polyMesh corresponding to the given map.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "polyMesh.H"
33 #include "mapPolyMesh.H"
34 #include "Time.H"
35 #include "globalMeshData.H"
36 #include "pointMesh.H"
37 #include "indexedOctree.H"
38 #include "treeDataCell.H"
39 
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 
43 {
45  << "Updating addressing and (optional) pointMesh/pointFields" << endl;
46 
47  // Update boundaryMesh (note that patches themselves already ok)
48 // boundary_.updateMesh(mpm);
49  boundary_.updateMesh();
50 
51  // Update zones
52  pointZones_.clearAddressing();
53  faceZones_.clearAddressing();
54  cellZones_.clearAddressing();
55 
56  // Remove the stored tet base points
57  tetBasePtIsPtr_.clear();
58  // Remove the cell tree
59  cellTreePtr_.clear();
60 
61  // Update parallel data
62  if (globalMeshDataPtr_)
63  {
64  globalMeshDataPtr_->updateMesh();
65  }
66 
68 
69  // Map the old motion points if present
70  if (oldPointsPtr_)
71  {
72  // Make a copy of the original points
73  pointField oldMotionPoints(*oldPointsPtr_);
74 
75  pointField& newMotionPoints = *oldPointsPtr_;
76 
77  // Resize the list to new size
78  newMotionPoints.resize(points_.size());
79 
80  // Map the list
81  if (mpm.hasMotionPoints())
82  {
83  newMotionPoints.map(oldMotionPoints, mpm.pointMap());
84 
85  // Any points created out-of-nothing get set to the current
86  // coordinate for lack of anything better.
87  forAll(mpm.pointMap(), newPointi)
88  {
89  if (mpm.pointMap()[newPointi] == -1)
90  {
91  newMotionPoints[newPointi] = points_[newPointi];
92  }
93  }
94  }
95  else
96  {
97  const labelList& pointMap = mpm.pointMap();
98  const labelList& revPointMap = mpm.reversePointMap();
99 
100  forAll(pointMap, newPointi)
101  {
102  label oldPointi = pointMap[newPointi];
103  if (oldPointi >= 0)
104  {
105  if (revPointMap[oldPointi] == newPointi) // master point
106  {
107  newMotionPoints[newPointi] = oldMotionPoints[oldPointi];
108  }
109  else
110  {
111  newMotionPoints[newPointi] = points_[newPointi];
112  }
113  }
114  else
115  {
116  newMotionPoints[newPointi] = points_[newPointi];
117  }
118  }
119  }
120  }
121 
122  // Map the old motion cell-centres if present
123  if (oldCellCentresPtr_)
124  {
125  // Make a copy of the original cell-centres
126  pointField oldMotionCellCentres(*oldCellCentresPtr_);
127 
128  pointField& newMotionCellCentres = *oldCellCentresPtr_;
129 
130  // Resize the list to new size
131  newMotionCellCentres.resize(cellCentres().size());
132 
133  // Map the list
134  newMotionCellCentres.map(oldMotionCellCentres, mpm.cellMap());
135 
136  // Any points created out-of-nothing get set to the current coordinate
137  // for lack of anything better.
138  forAll(mpm.cellMap(), newCelli)
139  {
140  if (mpm.cellMap()[newCelli] == -1)
141  {
142  newMotionCellCentres[newCelli] = cellCentres()[newCelli];
143  }
144  }
145  }
146 
147  meshObject::updateMesh<polyMesh>(*this, mpm);
148  meshObject::updateMesh<pointMesh>(*this, mpm);
149 
150  // Reset valid directions (could change by faces put into empty patches)
151  geometricD_ = Zero;
152  solutionD_ = Zero;
153 
154  const_cast<Time&>(time()).functionObjects().updateMesh(mpm);
155 }
156 
157 
158 // ************************************************************************* //
Foam::HashTable< regIOobject * >::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
globalMeshData.H
mapPolyMesh.H
indexedOctree.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
polyMesh.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field::map
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:240
Foam::Field< vector >
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::polyMesh::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update the mesh corresponding to given map.
Definition: polyMeshUpdate.C:42
timeName
word timeName
Definition: getTimeIndex.H:3
newPointi
label newPointi
Definition: readKivaGrid.H:496
treeDataCell.H
Foam::polyBoundaryMesh::updateMesh
void updateMesh()
Correct polyBoundaryMesh after topology update.
Definition: polyBoundaryMesh.C:1163
Time.H
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
Foam::mapPolyMesh::reversePointMap
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:469
Foam::List< label >
Foam::mapPolyMesh::pointMap
const labelList & pointMap() const
Old point map.
Definition: mapPolyMesh.H:396
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::ZoneMesh::clearAddressing
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:709
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178
pointMesh.H
Foam::polyMesh::setInstance
void setInstance(const fileName &instance, const IOobject::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: polyMeshIO.C:36
Foam::mapPolyMesh::cellMap
const labelList & cellMap() const
Old cell map.
Definition: mapPolyMesh.H:435