1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
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
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 "mapPolyMesh.H"
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 template<class GeoField>
31 void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
33 HashTable<const GeoField*> flds
35 mesh.objectRegistry::lookupClass<GeoField>()
38 forAllConstIter(typename HashTable<const GeoField*>, flds, iter)
40 const GeoField& fld = *iter();
42 Pout<< "Field:" << iter.key() << " internalsize:" << fld.size()
46 forAll(fld.boundaryField(), patchI)
49 << ' ' << fld.boundaryField()[patchI].patch().name()
50 << ' ' << fld.boundaryField()[patchI].type()
51 << ' ' << fld.boundaryField()[patchI].size()
58 template<class GeoField>
59 void Foam::fvMeshDistribute::addPatchFields(const word& patchFieldType)
61 HashTable<const GeoField*> flds
63 mesh_.objectRegistry::lookupClass<GeoField>()
66 forAllConstIter(typename HashTable<const GeoField*>, flds, iter)
68 const GeoField& fld = *iter();
70 typename GeoField::GeometricBoundaryField& bfld =
71 const_cast<typename GeoField::GeometricBoundaryField&>
76 label sz = bfld.size();
81 GeoField::PatchFieldType::New
85 fld.dimensionedInternalField()
92 // Delete trailing patch fields
93 template<class GeoField>
94 void Foam::fvMeshDistribute::deleteTrailingPatchFields()
96 HashTable<const GeoField*> flds
98 mesh_.objectRegistry::lookupClass<GeoField>()
101 forAllConstIter(typename HashTable<const GeoField*>, flds, iter)
103 const GeoField& fld = *iter();
105 typename GeoField::GeometricBoundaryField& bfld =
106 const_cast<typename GeoField::GeometricBoundaryField&>
111 // Shrink patchFields
112 bfld.setSize(bfld.size() - 1);
117 // Save whole boundary field
118 template <class T, class Mesh>
119 void Foam::fvMeshDistribute::saveBoundaryFields
121 PtrList<FieldField<fvsPatchField, T> >& bflds
124 typedef GeometricField<T, fvsPatchField, Mesh> fldType;
126 HashTable<const fldType*> flds
128 mesh_.objectRegistry::lookupClass<fldType>()
131 bflds.setSize(flds.size());
135 forAllConstIter(typename HashTable<const fldType*>, flds, iter)
137 const fldType& fld = *iter();
139 bflds.set(i, fld.boundaryField().clone().ptr());
146 // Map boundary field
147 template <class T, class Mesh>
148 void Foam::fvMeshDistribute::mapBoundaryFields
150 const mapPolyMesh& map,
151 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
154 const labelList& oldPatchStarts = map.oldPatchStarts();
155 const labelList& faceMap = map.faceMap();
157 typedef GeometricField<T, fvsPatchField, Mesh> fldType;
159 HashTable<const fldType*> flds
161 mesh_.objectRegistry::lookupClass<fldType>()
164 if (flds.size() != oldBflds.size())
166 FatalErrorIn("fvMeshDistribute::mapBoundaryFields(..)") << "problem"
167 << abort(FatalError);
172 forAllConstIter(typename HashTable<const fldType*>, flds, iter)
174 const fldType& fld = *iter();
175 typename fldType::GeometricBoundaryField& bfld =
176 const_cast<typename fldType::GeometricBoundaryField&>
182 const FieldField<fvsPatchField, T>& oldBfld = oldBflds[fieldI++];
184 // Pull from old boundary field into bfld.
188 fvsPatchField<T>& patchFld = bfld[patchI];
189 label faceI = patchFld.patch().start();
193 label oldFaceI = faceMap[faceI++];
195 // Find patch and local patch face oldFaceI was in.
196 forAll(oldPatchStarts, oldPatchI)
198 label oldLocalI = oldFaceI - oldPatchStarts[oldPatchI];
200 if (oldLocalI >= 0 && oldLocalI < oldBfld[oldPatchI].size())
202 patchFld[i] = oldBfld[oldPatchI][oldLocalI];
211 // Init patch fields of certain type
212 template<class GeoField, class PatchFieldType>
213 void Foam::fvMeshDistribute::initPatchFields
215 const typename GeoField::value_type& initVal
218 HashTable<const GeoField*> flds
220 mesh_.objectRegistry::lookupClass<GeoField>()
223 forAllConstIter(typename HashTable<const GeoField*>, flds, iter)
225 const GeoField& fld = *iter();
227 typename GeoField::GeometricBoundaryField& bfld =
228 const_cast<typename GeoField::GeometricBoundaryField&>
235 if (isA<PatchFieldType>(bfld[patchI]))
237 bfld[patchI] == initVal;
244 // Send fields. Note order supplied so we can receive in exactly the same order.
245 // Note that field gets written as entry in dictionary so we
246 // can construct from subdictionary.
247 // (since otherwise the reading as-a-dictionary mixes up entries from
248 // consecutive fields)
249 // The dictionary constructed is:
252 // p {internalField ..; boundaryField ..;}
253 // k {internalField ..; boundaryField ..;}
257 // U {internalField ... }
260 // volVectorField {U {internalField ..; boundaryField ..;}}
262 template<class GeoField>
263 void Foam::fvMeshDistribute::sendFields
266 const wordList& fieldNames,
267 const fvMeshSubset& subsetter,
271 toNbr << GeoField::typeName << token::NL << token::BEGIN_BLOCK << token::NL;
272 forAll(fieldNames, i)
276 Pout<< "Subsetting field " << fieldNames[i]
277 << " for domain:" << domain << endl;
280 // Send all fieldNames. This has to be exactly the same set as is
282 const GeoField& fld =
283 subsetter.baseMesh().lookupObject<GeoField>(fieldNames[i]);
285 tmp<GeoField> tsubfld = subsetter.interpolate(fld);
288 << fieldNames[i] << token::NL << token::BEGIN_BLOCK
290 << token::NL << token::END_BLOCK << token::NL;
292 toNbr << token::END_BLOCK << token::NL;
296 // Opposite of sendFields
297 template<class GeoField>
298 void Foam::fvMeshDistribute::receiveFields
301 const wordList& fieldNames,
303 PtrList<GeoField>& fields,
304 const dictionary& fieldDicts
309 Pout<< "Receiving fields " << fieldNames
310 << " from domain:" << domain << endl;
313 fields.setSize(fieldNames.size());
315 forAll(fieldNames, i)
319 Pout<< "Constructing field " << fieldNames[i]
320 << " from domain:" << domain << endl;
331 mesh.time().timeName(),
337 fieldDicts.subDict(fieldNames[i])
344 // ************************************************************************* //