faMeshUpdate.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) 2016-2017 Wikki Ltd
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 
29 #include "faMesh.H"
30 #include "mapPolyMesh.H"
31 #include "MapFaFields.H"
32 #include "faMeshMapper.H"
33 #include "areaFields.H"
34 #include "edgeFields.H"
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
39 {
40  DebugInFunction << "Updating mesh" << endl;
41 
42  // if (!mpm.morphing())
43  // {
44  // // No topo change
45  // return false;
46  // }
47 
48  // Create fa mesh mapper, using the old mesh
49  const faMeshMapper mapper(*this, mpm);
50 
51 
52  // Rebuild mesh
53 
54  // Cast away const for interface reasons. HJ, 12/Aug/2011
55  faMesh& m = const_cast<faMesh&>(*this);
56 
57 
58  // Clear existing mesh data
59  clearOut();
60 
61  // Set new labels
62  m.faceLabels_ = mapper.areaMap().newFaceLabels();
63 
64  const indirectPrimitivePatch& bp = patch();
65 
66  // Collect patch data
67  const label nTotalEdges = bp.nEdges();
68  const label nInternalEdges = bp.nInternalEdges();
69  const labelListList& edgeFaces = bp.edgeFaces();
70 
71  labelListList patchEdges(boundary_.size());
72 
73  // Special handling required for faces that have more than one edge
74  // Each patch will be visited separately
75 
76  labelList edgeToPatch(nTotalEdges - nInternalEdges, -1);
77  const labelList& newFaceLabelsMap = mapper.areaMap().newFaceLabelsMap();
78 
79  const labelListList& oldPatchEdgeFaces = mapper.oldPatchEdgeFaces();
80 
81  forAll(oldPatchEdgeFaces, patchI)
82  {
83  labelList& curPatchEdges = patchEdges[patchI];
84  curPatchEdges.setSize(nTotalEdges - nInternalEdges);
85  label nCurPatchEdges = 0;
86 
87  // Note: it is possible to pick up the old-to-new boundary patch
88  // mapping, but currently this is not done. HJ, 13/Aug/2011
89 
90  // Make a fast lookup
91  labelHashSet oldFaceLookup(oldPatchEdgeFaces[patchI]);
92 
93  for (label edgeI = nInternalEdges; edgeI < nTotalEdges; ++edgeI)
94  {
95  if (edgeToPatch[edgeI - nInternalEdges] > -1)
96  {
97  // Edge already found; continue with the next one
98  continue;
99  }
100 
101  // Boundary edges will only have one face next to them
102  const label oldFaceIndex = newFaceLabelsMap[edgeFaces[edgeI][0]];
103 
104  if (oldFaceIndex > -1)
105  {
106  // Old face exists. See if it has got an edge in this patch
107  if (oldFaceLookup.found(oldFaceIndex))
108  {
109  // Face found, add it to the patch
110  curPatchEdges[nCurPatchEdges] = edgeI;
111  nCurPatchEdges++;
112 
113  edgeToPatch[edgeI - nInternalEdges] = patchI;
114  }
115  }
116  }
117 
118  // Collected all faces for the current patch
119  curPatchEdges.setSize(nCurPatchEdges);
120  }
121 
122  // Set new edges for all patches
123  forAll(m.boundary_, patchI)
124  {
125  m.boundary_[patchI].resetEdges(patchEdges[patchI]);
126  }
127 
128  m.setPrimitiveMeshData();
129 
130  // Create global mesh data
131  if (Pstream::parRun())
132  {
133  globalData();
134  }
135 
136  // Calculate topology for the patches (processor-processor comms etc.)
137  m.boundary_.updateMesh();
138 
139  // Calculate the geometry for the patches (transformation tensors etc.)
140  m.boundary_.calcGeometry();
141 
142 
143  // Map fields
144  mapFields(mapper);
145 
146  // Map old areas
147  mapOldAreas(mapper);
148 
149  // Update edge interpolation
151 
152  return;
153 }
154 
155 
156 void Foam::faMesh::mapFields(const faMeshMapper& mapper) const
157 {
158  // Map all the areaFields in the objectRegistry
159  MapGeometricFields<scalar, faPatchField, faMeshMapper, areaMesh>(mapper);
160  MapGeometricFields<vector, faPatchField, faMeshMapper, areaMesh>(mapper);
161  MapGeometricFields<sphericalTensor, faPatchField, faMeshMapper, areaMesh>
162  (mapper);
163  MapGeometricFields<symmTensor, faPatchField, faMeshMapper, areaMesh>
164  (mapper);
165  MapGeometricFields<tensor, faPatchField, faMeshMapper, areaMesh>(mapper);
166 
167  // Map all the edgeFields in the objectRegistry
168  MapGeometricFields<scalar, faePatchField, faMeshMapper, edgeMesh>(mapper);
169  MapGeometricFields<vector, faePatchField, faMeshMapper, edgeMesh>(mapper);
170  MapGeometricFields<sphericalTensor, faePatchField, faMeshMapper, edgeMesh>
171  (mapper);
172  MapGeometricFields<symmTensor, faePatchField, faMeshMapper, edgeMesh>
173  (mapper);
174  MapGeometricFields<tensor, faePatchField, faMeshMapper, edgeMesh>(mapper);
175 }
176 
177 
178 void Foam::faMesh::mapOldAreas(const faMeshMapper& mapper) const
179 {
180  if (S0Ptr_)
181  {
182  DebugInFunction << "Mapping old face areas." << endl;
183 
184  scalarField& S0 = *S0Ptr_;
185 
186  scalarField savedS0(S0);
187  S0.setSize(nFaces());
188 
189  const labelList& faceMap = mapper.areaMap().newFaceLabelsMap();
190 
191  // Map existing old areas; for new faces set area to zero
192  forAll(faceMap, faceI)
193  {
194  if (faceMap[faceI] > -1)
195  {
196  S0[faceI] = savedS0[faceMap[faceI]];
197  }
198  else
199  {
200  S0[faceI] = 0;
201  }
202  }
203  }
204 
205  if (S00Ptr_)
206  {
207  DebugInFunction << "Mapping old-old face areas." << endl;
208 
209  scalarField& S00 = *S00Ptr_;
210 
211  scalarField savedS00(S00);
212  S00.setSize(nFaces());
213 
214  const labelList& faceMap = mapper.areaMap().newFaceLabelsMap();
215 
216  // Map old areas for existing faces; for new faces, set area to zero
217  forAll(faceMap, faceI)
218  {
219  if (faceMap[faceI] > -1)
220  {
221  S00[faceI] = savedS00[faceMap[faceI]];
222  }
223  else
224  {
225  S00[faceI] = 0;
226  }
227  }
228  }
229 
230 }
231 
232 
233 // ************************************************************************* //
Foam::faBoundaryMesh::updateMesh
void updateMesh()
Correct faBoundaryMesh after topology update.
Definition: faBoundaryMesh.C:412
Foam::faMesh::mapOldAreas
virtual void mapOldAreas(const faMeshMapper &mapper) const
Map face areas in time using given map.
Definition: faMeshUpdate.C:178
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::PrimitivePatch::edgeFaces
const labelListList & edgeFaces() const
Return edge-face addressing.
Definition: PrimitivePatch.C:242
Foam::faMesh::patch
const indirectPrimitivePatch & patch() const
Return constant reference to primitive patch.
Definition: faMesh.C:915
mapPolyMesh.H
Foam::PrimitivePatch::nEdges
label nEdges() const
Return number of edges in patch.
Definition: PrimitivePatch.H:322
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
Foam::faBoundaryMesh::calcGeometry
void calcGeometry()
Calculate the geometry for the patches.
Definition: faBoundaryMesh.C:175
Foam::faAreaMapper::newFaceLabels
const labelList & newFaceLabels() const
Return new face labels.
Definition: faAreaMapper.C:326
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
faMesh.H
faMeshMapper.H
Foam::HashSet< label, Hash< label > >
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::faMesh::globalData
const faGlobalMeshData & globalData() const
Return parallel info.
Definition: faMesh.C:1192
Foam::faMeshMapper::oldPatchEdgeFaces
const labelListList & oldPatchEdgeFaces() const
Return old patch edgeFaces.
Definition: faMeshMapper.H:184
Foam::faMeshMapper
Class holds all the necessary information for mapping fields associated with faMesh.
Definition: faMeshMapper.H:68
Foam::Field< scalar >
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:365
edgeFields.H
Foam::faAreaMapper::newFaceLabelsMap
const labelList & newFaceLabelsMap() const
Return new face labels map.
Definition: faAreaMapper.C:337
areaFields.H
Foam::faMesh::nInternalEdges
label nInternalEdges() const
Definition: faMesh.H:361
Foam::edgeInterpolation::movePoints
bool movePoints() const
Do what is necessary if the mesh has moved.
Definition: edgeInterpolation.C:161
Foam::PrimitivePatch::nInternalEdges
label nInternalEdges() const
Number of internal edges.
Definition: PrimitivePatch.C:203
Foam::List< labelList >
Foam::faMesh::mapFields
virtual void mapFields(const faMeshMapper &mapper) const
Map all fields in time using given map.
Definition: faMeshUpdate.C:156
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::faMesh::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update after topo change.
Definition: faMeshUpdate.C:38
Foam::faMesh
Finite area mesh. Used for 2-D non-Euclidian finite area method.
Definition: faMesh.H:77
Foam::HashTable::found
bool found(const Key &key) const
Return true if hashed entry is found in table.
Definition: HashTableI.H:100
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::faMeshMapper::areaMap
const faAreaMapper & areaMap() const
Return surface mapper.
Definition: faMeshMapper.H:193
MapFaFields.H
Finite area field mapping.
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:85