BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / mesh / autoMesh / autoHexMesh / meshRefinement / meshRefinementTemplates.C
blobc4999c64c3a902a29d5459f6eb728593df0f956d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "meshRefinement.H"
27 #include "fvMesh.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 // Add a T entry
37 template<class T> void meshRefinement::updateList
39     const labelList& newToOld,
40     const T& nullValue,
41     List<T>& elems
44     List<T> newElems(newToOld.size(), nullValue);
46     forAll(newElems, i)
47     {
48         label oldI = newToOld[i];
50         if (oldI >= 0)
51         {
52             newElems[i] = elems[oldI];
53         }
54     }
56     elems.transfer(newElems);
60 // Compare two lists over all boundary faces
61 template<class T>
62 void meshRefinement::testSyncBoundaryFaceList
64     const scalar tol,
65     const string& msg,
66     const UList<T>& faceData,
67     const UList<T>& syncedFaceData
68 ) const
70     label nBFaces = mesh_.nFaces() - mesh_.nInternalFaces();
72     if (faceData.size() != nBFaces || syncedFaceData.size() != nBFaces)
73     {
74         FatalErrorIn
75         (
76             "meshRefinement::testSyncBoundaryFaceList"
77             "(const scalar, const string&, const List<T>&, const List<T>&)"
78         )   << "Boundary faces:" << nBFaces
79             << " faceData:" << faceData.size()
80             << " syncedFaceData:" << syncedFaceData.size()
81             << abort(FatalError);
82     }
84     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
86     forAll(patches, patchI)
87     {
88         const polyPatch& pp = patches[patchI];
90         label bFaceI = pp.start() - mesh_.nInternalFaces();
92         forAll(pp, i)
93         {
94             const T& data = faceData[bFaceI];
95             const T& syncData = syncedFaceData[bFaceI];
97             if (mag(data - syncData) > tol)
98             {
99                 label faceI = pp.start()+i;
101                 FatalErrorIn("testSyncFaces")
102                     << msg
103                     << "patchFace:" << i
104                     << " face:" << faceI
105                     << " fc:" << mesh_.faceCentres()[faceI]
106                     << " patch:" << pp.name()
107                     << " faceData:" << data
108                     << " syncedFaceData:" << syncData
109                     << " diff:" << mag(data - syncData)
110                     << abort(FatalError);
111             }
113             bFaceI++;
114         }
115     }
119 //template <class T, class Mesh>
120 template<class GeoField>
121 void meshRefinement::addPatchFields(fvMesh& mesh, const word& patchFieldType)
123     HashTable<const GeoField*> flds
124     (
125         mesh.objectRegistry::lookupClass<GeoField>()
126     );
128     forAllConstIter(typename HashTable<const GeoField*>, flds, iter)
129     {
130         const GeoField& fld = *iter();
132         typename GeoField::GeometricBoundaryField& bfld =
133             const_cast<typename GeoField::GeometricBoundaryField&>
134             (
135                 fld.boundaryField()
136             );
138         label sz = bfld.size();
139         bfld.setSize(sz+1);
140         bfld.set
141         (
142             sz,
143             GeoField::PatchFieldType::New
144             (
145                 patchFieldType,
146                 mesh.boundary()[sz],
147                 fld.dimensionedInternalField()
148             )
149         );
150     }
154 // Reorder patch field
155 template<class GeoField>
156 void meshRefinement::reorderPatchFields(fvMesh& mesh, const labelList& oldToNew)
158     HashTable<const GeoField*> flds
159     (
160         mesh.objectRegistry::lookupClass<GeoField>()
161     );
163     forAllConstIter(typename HashTable<const GeoField*>, flds, iter)
164     {
165         const GeoField& fld = *iter();
167         typename GeoField::GeometricBoundaryField& bfld =
168             const_cast<typename GeoField::GeometricBoundaryField&>
169             (
170                 fld.boundaryField()
171             );
173         bfld.reorder(oldToNew);
174     }
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 } // End namespace Foam
184 // ************************************************************************* //