initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / autoMesh / autoHexMesh / meshRefinement / meshRefinementTemplates.C
blob6bae95fccddeaaf57e4e08e92aa5ed55da4cfd22
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "meshRefinement.H"
28 #include "fvMesh.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
37 // Add a T entry
38 template<class T> void meshRefinement::updateList
40     const labelList& newToOld,
41     const T& nullValue,
42     List<T>& elems
45     List<T> newElems(newToOld.size(), nullValue);
47     forAll(newElems, i)
48     {
49         label oldI = newToOld[i];
51         if (oldI >= 0)
52         {
53             newElems[i] = elems[oldI];
54         }
55     }
57     elems.transfer(newElems);
61 // Compare two lists over all boundary faces
62 template<class T>
63 void meshRefinement::testSyncBoundaryFaceList
65     const scalar tol,
66     const string& msg,
67     const UList<T>& faceData,
68     const UList<T>& syncedFaceData
69 ) const
71     label nBFaces = mesh_.nFaces() - mesh_.nInternalFaces();
73     if (faceData.size() != nBFaces || syncedFaceData.size() != nBFaces)
74     {
75         FatalErrorIn
76         (
77             "meshRefinement::testSyncBoundaryFaceList"
78             "(const scalar, const string&, const List<T>&, const List<T>&)"
79         )   << "Boundary faces:" << nBFaces
80             << " faceData:" << faceData.size()
81             << " syncedFaceData:" << syncedFaceData.size()
82             << abort(FatalError);
83     }
85     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
87     forAll(patches, patchI)
88     {
89         const polyPatch& pp = patches[patchI];
91         label bFaceI = pp.start() - mesh_.nInternalFaces();
93         forAll(pp, i)
94         {
95             const T& data = faceData[bFaceI];
96             const T& syncData = syncedFaceData[bFaceI];
98             if (mag(data - syncData) > tol)
99             {
100                 label faceI = pp.start()+i;
102                 FatalErrorIn("testSyncFaces")
103                     << msg
104                     << "patchFace:" << i
105                     << " face:" << faceI
106                     << " fc:" << mesh_.faceCentres()[faceI]
107                     << " patch:" << pp.name()
108                     << " faceData:" << data
109                     << " syncedFaceData:" << syncData
110                     << " diff:" << mag(data - syncData)
111                     << abort(FatalError);
112             }
114             bFaceI++;
115         }
116     }
120 //template <class T, class Mesh>
121 template<class GeoField>
122 void meshRefinement::addPatchFields(fvMesh& mesh, const word& patchFieldType)
124     HashTable<const GeoField*> flds
125     (
126         mesh.objectRegistry::lookupClass<GeoField>()
127     );
129     for
130     (
131         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
132         iter != flds.end();
133         ++iter
134     )
135     {
136         const GeoField& fld = *iter();
138         typename GeoField::GeometricBoundaryField& bfld =
139             const_cast<typename GeoField::GeometricBoundaryField&>
140             (
141                 fld.boundaryField()
142             );
144         label sz = bfld.size();
145         bfld.setSize(sz+1);
146         bfld.set
147         (
148             sz,
149             GeoField::PatchFieldType::New
150             (
151                 patchFieldType,
152                 mesh.boundary()[sz],
153                 fld.dimensionedInternalField()
154             )
155         );
156     }
160 // Reorder patch field
161 template<class GeoField>
162 void meshRefinement::reorderPatchFields(fvMesh& mesh, const labelList& oldToNew)
164     HashTable<const GeoField*> flds
165     (
166         mesh.objectRegistry::lookupClass<GeoField>()
167     );
169     for
170     (
171         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
172         iter != flds.end();
173         ++iter
174     )
175     {
176         const GeoField& fld = *iter();
178         typename GeoField::GeometricBoundaryField& bfld =
179             const_cast<typename GeoField::GeometricBoundaryField&>
180             (
181                 fld.boundaryField()
182             );
184         bfld.reorder(oldToNew);
185     }
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 } // End namespace Foam
195 // ************************************************************************* //