1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 "mapPolyMesh.H"
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 template<class GeoField>
32 void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
34 HashTable<const GeoField*> flds
36 mesh.objectRegistry::lookupClass<GeoField>()
41 typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
46 const GeoField& fld = *iter();
48 Pout<< "Field:" << iter.key() << " internalsize:" << fld.size()
52 forAll(fld.boundaryField(), patchI)
55 << ' ' << fld.boundaryField()[patchI].patch().name()
56 << ' ' << fld.boundaryField()[patchI].type()
57 << ' ' << fld.boundaryField()[patchI].size()
64 template<class GeoField>
65 void Foam::fvMeshDistribute::addPatchFields(const word& patchFieldType)
67 HashTable<const GeoField*> flds
69 mesh_.objectRegistry::lookupClass<GeoField>()
74 typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
79 const GeoField& fld = *iter();
81 typename GeoField::GeometricBoundaryField& bfld =
82 const_cast<typename GeoField::GeometricBoundaryField&>
87 label sz = bfld.size();
92 GeoField::PatchFieldType::New
96 fld.dimensionedInternalField()
103 // Delete trailing patch fields
104 template<class GeoField>
105 void Foam::fvMeshDistribute::deleteTrailingPatchFields()
107 HashTable<const GeoField*> flds
109 mesh_.objectRegistry::lookupClass<GeoField>()
114 typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
119 const GeoField& fld = *iter();
121 typename GeoField::GeometricBoundaryField& bfld =
122 const_cast<typename GeoField::GeometricBoundaryField&>
127 // Shrink patchFields
128 bfld.setSize(bfld.size() - 1);
133 // Save whole boundary field
134 template <class T, class Mesh>
135 void Foam::fvMeshDistribute::saveBoundaryFields
137 PtrList<FieldField<fvsPatchField, T> >& bflds
140 typedef GeometricField<T, fvsPatchField, Mesh> fldType;
142 HashTable<const fldType*> flds
144 mesh_.objectRegistry::lookupClass<fldType>()
147 bflds.setSize(flds.size());
153 typename HashTable<const fldType*>::const_iterator iter = flds.begin();
158 const fldType& fld = *iter();
160 bflds.set(i, fld.boundaryField().clone().ptr());
167 // Map boundary field
168 template <class T, class Mesh>
169 void Foam::fvMeshDistribute::mapBoundaryFields
171 const mapPolyMesh& map,
172 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
175 const labelList& oldPatchStarts = map.oldPatchStarts();
176 const labelList& faceMap = map.faceMap();
178 typedef GeometricField<T, fvsPatchField, Mesh> fldType;
180 HashTable<const fldType*> flds
182 mesh_.objectRegistry::lookupClass<fldType>()
185 if (flds.size() != oldBflds.size())
187 FatalErrorIn("fvMeshDistribute::mapBoundaryFields") << "problem"
188 << abort(FatalError);
195 typename HashTable<const fldType*>::const_iterator iter = flds.begin();
200 const fldType& fld = *iter();
201 typename fldType::GeometricBoundaryField& bfld =
202 const_cast<typename fldType::GeometricBoundaryField&>
208 const FieldField<fvsPatchField, T>& oldBfld = oldBflds[fieldI++];
210 // Pull from old boundary field into bfld.
214 fvsPatchField<T>& patchFld = bfld[patchI];
215 label faceI = patchFld.patch().patch().start();
219 label oldFaceI = faceMap[faceI++];
221 // Find patch and local patch face oldFaceI was in.
222 forAll(oldPatchStarts, oldPatchI)
224 label oldLocalI = oldFaceI - oldPatchStarts[oldPatchI];
226 if (oldLocalI >= 0 && oldLocalI < oldBfld[oldPatchI].size())
228 patchFld[i] = oldBfld[oldPatchI][oldLocalI];
237 // Init patch fields of certain type
238 template<class GeoField>
239 void Foam::fvMeshDistribute::initPatchFields
241 const word& patchFieldType,
242 const typename GeoField::value_type& initVal
245 HashTable<const GeoField*> flds
247 mesh_.objectRegistry::lookupClass<GeoField>()
252 typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
257 const GeoField& fld = *iter();
259 typename GeoField::GeometricBoundaryField& bfld =
260 const_cast<typename GeoField::GeometricBoundaryField&>
267 if (bfld[patchI].type() == patchFieldType)
269 bfld[patchI] == initVal;
276 // Send fields. Note order supplied so we can receive in exactly the same order.
277 template<class GeoField>
278 void Foam::fvMeshDistribute::sendFields
281 const wordList& fieldNames,
282 const fvMeshSubset& subsetter
285 forAll(fieldNames, i)
287 //Pout<< "Subsetting field " << fieldNames[i]
288 // << " for domain:" << domain
291 // Send all fieldNames. This has to be exactly the same set as is
293 const GeoField& fld =
294 subsetter.baseMesh().lookupObject<GeoField>(fieldNames[i]);
296 tmp<GeoField> tsubfld = subsetter.interpolate(fld);
299 OPstream toNbr(Pstream::blocking, domain);
305 // Opposite of sendFields
306 template<class GeoField>
307 void Foam::fvMeshDistribute::receiveFields
310 const wordList& fieldNames,
312 PtrList<GeoField>& fields
315 fields.setSize(fieldNames.size());
317 forAll(fieldNames, i)
319 //Pout<< "Receiving field " << fieldNames[i]
320 // << " from domain:" << domain
323 IPstream fromNbr(Pstream::blocking, domain);
333 mesh.time().timeName(),
346 // ************************************************************************* //