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  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 uindirectPrimitivePatch& bp = patch();
65 
66  // Collect patch data
67  const label nTotalEdges = bp.nEdges();
68  const label nInternalEdges = bp.nInternalEdges();
69  const label nBoundaryEdges = bp.nBoundaryEdges();
70  const labelListList& edgeFaces = bp.edgeFaces();
71 
72  labelListList patchEdges(boundary_.size());
73 
74  // Special handling required for faces that have more than one edge
75  // Each patch will be visited separately
76 
77  labelList edgeToPatch(nBoundaryEdges, -1);
78  const labelList& newFaceLabelsMap = mapper.areaMap().newFaceLabelsMap();
79 
80  const labelListList& oldPatchEdgeFaces = mapper.oldPatchEdgeFaces();
81 
82  forAll(oldPatchEdgeFaces, patchI)
83  {
84  labelList& curPatchEdges = patchEdges[patchI];
85  curPatchEdges.resize(nBoundaryEdges);
86  label nCurPatchEdges = 0;
87 
88  // Note: it is possible to pick up the old-to-new boundary patch
89  // mapping, but currently this is not done. HJ, 13/Aug/2011
90 
91  // Make a fast lookup
92  labelHashSet oldFaceLookup(oldPatchEdgeFaces[patchI]);
93 
94  for (label edgeI = nInternalEdges; edgeI < nTotalEdges; ++edgeI)
95  {
96  if (edgeToPatch[edgeI - nInternalEdges] > -1)
97  {
98  // Edge already found; continue with the next one
99  continue;
100  }
101 
102  // Boundary edges will only have one face next to them
103  const label oldFaceIndex = newFaceLabelsMap[edgeFaces[edgeI][0]];
104 
105  if (oldFaceIndex > -1)
106  {
107  // Old face exists. See if it has got an edge in this patch
108  if (oldFaceLookup.found(oldFaceIndex))
109  {
110  // Face found, add it to the patch
111  curPatchEdges[nCurPatchEdges] = edgeI;
112  nCurPatchEdges++;
113 
114  edgeToPatch[edgeI - nInternalEdges] = patchI;
115  }
116  }
117  }
118 
119  // Collected all faces for the current patch
120  curPatchEdges.setSize(nCurPatchEdges);
121  }
122 
123  // Set new edges for all patches
124  forAll(m.boundary_, patchI)
125  {
126  m.boundary_[patchI].resetEdges(patchEdges[patchI]);
127  }
128 
129  m.setPrimitiveMeshData();
130 
131  // Create global mesh data
132  if (Pstream::parRun())
133  {
134  globalData();
135  }
136 
137  // Calculate topology for the patches (processor-processor comms etc.)
138  m.boundary_.updateMesh();
139 
140  // Calculate the geometry for the patches (transformation tensors etc.)
141  m.boundary_.calcGeometry();
142 
143 
144  // Map fields
145  mapFields(mapper);
146 
147  // Map old areas
148  mapOldAreas(mapper);
149 
150  // Update edge interpolation
152 
153  return;
154 }
155 
156 
157 void Foam::faMesh::mapFields(const faMeshMapper& mapper) const
158 {
159  // Map all the areaFields in the objectRegistry
160  MapGeometricFields<scalar, faPatchField, faMeshMapper, areaMesh>(mapper);
161  MapGeometricFields<vector, faPatchField, faMeshMapper, areaMesh>(mapper);
162  MapGeometricFields<sphericalTensor, faPatchField, faMeshMapper, areaMesh>
163  (mapper);
164  MapGeometricFields<symmTensor, faPatchField, faMeshMapper, areaMesh>
165  (mapper);
166  MapGeometricFields<tensor, faPatchField, faMeshMapper, areaMesh>(mapper);
167 
168  // Map all the edgeFields in the objectRegistry
169  MapGeometricFields<scalar, faePatchField, faMeshMapper, edgeMesh>(mapper);
170  MapGeometricFields<vector, faePatchField, faMeshMapper, edgeMesh>(mapper);
171  MapGeometricFields<sphericalTensor, faePatchField, faMeshMapper, edgeMesh>
172  (mapper);
173  MapGeometricFields<symmTensor, faePatchField, faMeshMapper, edgeMesh>
174  (mapper);
175  MapGeometricFields<tensor, faePatchField, faMeshMapper, edgeMesh>(mapper);
176 }
177 
178 
179 void Foam::faMesh::mapOldAreas(const faMeshMapper& mapper) const
180 {
181  if (S0Ptr_)
182  {
183  DebugInFunction << "Mapping old face areas." << endl;
184 
185  scalarField& S0 = *S0Ptr_;
186 
187  scalarField savedS0(S0);
188  S0.setSize(nFaces());
189 
190  const labelList& faceMap = mapper.areaMap().newFaceLabelsMap();
191 
192  // Map existing old areas; for new faces set area to zero
193  forAll(faceMap, faceI)
194  {
195  if (faceMap[faceI] > -1)
196  {
197  S0[faceI] = savedS0[faceMap[faceI]];
198  }
199  else
200  {
201  S0[faceI] = 0;
202  }
203  }
204  }
205 
206  if (S00Ptr_)
207  {
208  DebugInFunction << "Mapping old-old face areas." << endl;
209 
210  scalarField& S00 = *S00Ptr_;
211 
212  scalarField savedS00(S00);
213  S00.setSize(nFaces());
214 
215  const labelList& faceMap = mapper.areaMap().newFaceLabelsMap();
216 
217  // Map old areas for existing faces; for new faces, set area to zero
218  forAll(faceMap, faceI)
219  {
220  if (faceMap[faceI] > -1)
221  {
222  S00[faceI] = savedS00[faceMap[faceI]];
223  }
224  else
225  {
226  S00[faceI] = 0;
227  }
228  }
229  }
230 
231 }
232 
233 
234 // ************************************************************************* //
Foam::PrimitivePatch::nBoundaryEdges
label nBoundaryEdges() const
Number of boundary edges == (nEdges() - nInternalEdges())
Definition: PrimitivePatch.C:227
Foam::faBoundaryMesh::updateMesh
void updateMesh()
Correct faBoundaryMesh after topology update.
Definition: faBoundaryMesh.C:468
Foam::faMesh::mapOldAreas
virtual void mapOldAreas(const faMeshMapper &mapper) const
Map face areas in time using given map.
Definition: faMeshUpdate.C:179
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:262
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
mapPolyMesh.H
Foam::PrimitivePatch::nEdges
label nEdges() const
Number of edges in patch.
Definition: PrimitivePatch.H:322
Foam::faBoundaryMesh::calcGeometry
void calcGeometry()
Calculate the geometry for the patches.
Definition: faBoundaryMesh.C:132
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:369
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:752
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:388
edgeFields.H
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::faMesh::nInternalEdges
label nInternalEdges() const noexcept
Number of internal faces.
Definition: faMeshI.H:68
Foam::faAreaMapper::newFaceLabelsMap
const labelList & newFaceLabelsMap() const
Return new face labels map.
Definition: faAreaMapper.C:337
Foam::faMesh::nBoundaryEdges
label nBoundaryEdges() const noexcept
Number of boundary edges (== nEdges - nInternalEdges)
Definition: faMeshI.H:74
areaFields.H
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:214
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< labelList >
Foam::faMesh::mapFields
virtual void mapFields(const faMeshMapper &mapper) const
Map all fields in time using given map.
Definition: faMeshUpdate.C:157
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:82
Foam::faMesh::patch
const uindirectPrimitivePatch & patch() const
Return constant reference to primitive patch.
Definition: faMeshI.H:122
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:79