FreeFOAM The Cross-Platform CFD Toolkit
meshRefinementTemplates.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "meshRefinement.H"
27 #include <finiteVolume/fvMesh.H>
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 
36 // Add a T entry
37 template<class T> void meshRefinement::updateList
38 (
39  const labelList& newToOld,
40  const T& nullValue,
41  List<T>& elems
42 )
43 {
44  List<T> newElems(newToOld.size(), nullValue);
45 
46  forAll(newElems, i)
47  {
48  label oldI = newToOld[i];
49 
50  if (oldI >= 0)
51  {
52  newElems[i] = elems[oldI];
53  }
54  }
55 
56  elems.transfer(newElems);
57 }
58 
59 
60 // Compare two lists over all boundary faces
61 template<class T>
63 (
64  const scalar tol,
65  const string& msg,
66  const UList<T>& faceData,
67  const UList<T>& syncedFaceData
68 ) const
69 {
70  label nBFaces = mesh_.nFaces() - mesh_.nInternalFaces();
71 
72  if (faceData.size() != nBFaces || syncedFaceData.size() != nBFaces)
73  {
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  }
83 
84  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
85 
86  forAll(patches, patchI)
87  {
88  const polyPatch& pp = patches[patchI];
89 
90  label bFaceI = pp.start() - mesh_.nInternalFaces();
91 
92  forAll(pp, i)
93  {
94  const T& data = faceData[bFaceI];
95  const T& syncData = syncedFaceData[bFaceI];
96 
97  if (mag(data - syncData) > tol)
98  {
99  label faceI = pp.start()+i;
100 
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  }
112 
113  bFaceI++;
114  }
115  }
116 }
117 
118 
119 //template <class T, class Mesh>
120 template<class GeoField>
121 void meshRefinement::addPatchFields(fvMesh& mesh, const word& patchFieldType)
122 {
124  (
125  mesh.objectRegistry::lookupClass<GeoField>()
126  );
127 
128  for
129  (
130  typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
131  iter != flds.end();
132  ++iter
133  )
134  {
135  const GeoField& fld = *iter();
136 
137  typename GeoField::GeometricBoundaryField& bfld =
138  const_cast<typename GeoField::GeometricBoundaryField&>
139  (
140  fld.boundaryField()
141  );
142 
143  label sz = bfld.size();
144  bfld.setSize(sz+1);
145  bfld.set
146  (
147  sz,
148  GeoField::PatchFieldType::New
149  (
150  patchFieldType,
151  mesh.boundary()[sz],
152  fld.dimensionedInternalField()
153  )
154  );
155  }
156 }
157 
158 
159 // Reorder patch field
160 template<class GeoField>
161 void meshRefinement::reorderPatchFields(fvMesh& mesh, const labelList& oldToNew)
162 {
163  HashTable<const GeoField*> flds
164  (
165  mesh.objectRegistry::lookupClass<GeoField>()
166  );
167 
168  for
169  (
170  typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
171  iter != flds.end();
172  ++iter
173  )
174  {
175  const GeoField& fld = *iter();
176 
177  typename GeoField::GeometricBoundaryField& bfld =
178  const_cast<typename GeoField::GeometricBoundaryField&>
179  (
180  fld.boundaryField()
181  );
182 
183  bfld.reorder(oldToNew);
184  }
185 }
186 
187 
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // ************************ vim: set sw=4 sts=4 et: ************************ //