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