1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
29 #include "mapPolyMesh.H"
30 #include "MapFaFields.H"
31 #include "faMeshMapper.H"
32 #include "areaFields.H"
33 #include "edgeFields.H"
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 bool Foam::faMesh::updateMesh(const mapPolyMesh& mpm) const
41 Info<< "bool faMesh::updateMesh(const mapPolyMesh& mpm) const : "
42 << "Updating mesh" << endl;
51 // Create fa mesh mapper, using the old mesh
52 const faMeshMapper mapper(*this, mpm);
57 // Cast away const for interface reasons. HJ, 12/Aug/2011
58 faMesh& m = const_cast<faMesh&>(*this);
61 // Clear existing mesh data
65 m.faceLabels_ = mapper.areaMap().newFaceLabels();
67 const indirectPrimitivePatch& bp = patch();
70 const label nTotalEdges = bp.nEdges();
71 const label nInternalEdges = bp.nInternalEdges();
72 const labelListList& edgeFaces = bp.edgeFaces();
74 labelListList patchEdges(boundary_.size());
76 // Special handling required for faces that have more than one edge
77 // Each patch will be visited separately
79 labelList edgeToPatch(nTotalEdges - nInternalEdges, -1);
80 const labelList& newFaceLabelsMap = mapper.areaMap().newFaceLabelsMap();
82 const labelListList& oldPatchEdgeFaces = mapper.oldPatchEdgeFaces();
84 forAll (oldPatchEdgeFaces, patchI)
86 labelList& curPatchEdges = patchEdges[patchI];
87 curPatchEdges.setSize(nTotalEdges - nInternalEdges);
88 label nCurPatchEdges = 0;
90 // Note: it is possible to pick up the old-to-new boundary patch
91 // mapping, but currently this is not done. HJ, 13/Aug/2011
94 labelHashSet oldFaceLookup(oldPatchEdgeFaces[patchI]);
96 for (label edgeI = nInternalEdges; edgeI < nTotalEdges; edgeI++)
98 if (edgeToPatch[edgeI - nInternalEdges] > -1)
100 // Edge already found; continue with the next one
104 // Boundary edges will only have one face next to them
105 const label oldFaceIndex = newFaceLabelsMap[edgeFaces[edgeI][0]];
107 if (oldFaceIndex > -1)
109 // Old face exists. See if it has got an edge in this patch
110 if (oldFaceLookup.found(oldFaceIndex))
112 // Face found, add it to the patch
113 curPatchEdges[nCurPatchEdges] = edgeI;
116 edgeToPatch[edgeI - nInternalEdges] = patchI;
121 // Collected all faces for the current patch
122 curPatchEdges.setSize(nCurPatchEdges);
125 // Set new edges for all patches
126 forAll (m.boundary_, patchI)
128 m.boundary_[patchI].resetEdges(patchEdges[patchI]);
131 m.setPrimitiveMeshData();
133 // Create global mesh data
134 if (Pstream::parRun())
139 // Calculate topology for the patches (processor-processor comms etc.)
140 m.boundary_.updateMesh();
142 // Calculate the geometry for the patches (transformation tensors etc.)
143 m.boundary_.calcGeometry();
152 // Update edge interpolation
153 edgeInterpolation::movePoints();
159 void Foam::faMesh::mapFields(const faMeshMapper& mapper) const
161 // Map all the areaFields in the objectRegistry
162 MapGeometricFields<scalar, faPatchField, faMeshMapper, areaMesh>(mapper);
163 MapGeometricFields<vector, faPatchField, faMeshMapper, areaMesh>(mapper);
164 MapGeometricFields<sphericalTensor, faPatchField, faMeshMapper, areaMesh>
166 MapGeometricFields<symmTensor, faPatchField, faMeshMapper, areaMesh>
168 MapGeometricFields<tensor, faPatchField, faMeshMapper, areaMesh>(mapper);
170 // Map all the edgeFields in the objectRegistry
171 MapGeometricFields<scalar, faePatchField, faMeshMapper, edgeMesh>(mapper);
172 MapGeometricFields<vector, faePatchField, faMeshMapper, edgeMesh>(mapper);
173 MapGeometricFields<sphericalTensor, faePatchField, faMeshMapper, edgeMesh>
175 MapGeometricFields<symmTensor, faePatchField, faMeshMapper, edgeMesh>
177 MapGeometricFields<tensor, faePatchField, faMeshMapper, edgeMesh>(mapper);
181 void Foam::faMesh::mapOldAreas(const faMeshMapper& mapper) const
187 InfoIn("void faMesh::mapOldAreas(const faMeshMapper& mapper)")
188 << "Mapping old face areas." << endl;
191 scalarField& S0 = *S0Ptr_;
193 scalarField savedS0(S0);
194 S0.setSize(nFaces());
196 const labelList& faceMap = mapper.areaMap().newFaceLabelsMap();
198 // Map existing old areas; for new faces set area to zero
199 forAll (faceMap, faceI)
201 if (faceMap[faceI] > -1)
203 S0[faceI] = savedS0[faceMap[faceI]];
216 InfoIn("void faMesh::mapOldAreas(const faMeshMapper& mapper)")
217 << "Mapping old-old face areas." << endl;
220 scalarField& S00 = *S00Ptr_;
222 scalarField savedS00(S00);
223 S00.setSize(nFaces());
225 const labelList& faceMap = mapper.areaMap().newFaceLabelsMap();
227 // Map old areas for existing faces; for new faces, set area to zero
228 forAll (faceMap, faceI)
230 if (faceMap[faceI] > -1)
232 S00[faceI] = savedS00[faceMap[faceI]];
244 // ************************************************************************* //