intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / src / dynamicMesh / fvMeshDistribute / fvMeshDistributeTemplates.C
blob48db5e47552918d9555f3ef68acc95e1fc0be9c6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 "mapPolyMesh.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 template<class GeoField>
32 void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
34     HashTable<const GeoField*> flds
35     (
36         mesh.objectRegistry::lookupClass<GeoField>()
37     );
39     for
40     (
41         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
42         iter != flds.end();
43         ++iter
44     )
45     {
46         const GeoField& fld = *iter();
48         Pout<< "Field:" << iter.key() << " internalsize:" << fld.size()
49             //<< " value:" << fld
50             << endl;
52         forAll(fld.boundaryField(), patchI)
53         {
54             Pout<< "    " << patchI
55                 << ' ' << fld.boundaryField()[patchI].patch().name()
56                 << ' ' << fld.boundaryField()[patchI].type()
57                 << ' ' << fld.boundaryField()[patchI].size()
58                 << endl;
59         }
60     }
64 template<class GeoField>
65 void Foam::fvMeshDistribute::addPatchFields(const word& patchFieldType)
67     HashTable<const GeoField*> flds
68     (
69         mesh_.objectRegistry::lookupClass<GeoField>()
70     );
72     for
73     (
74         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
75         iter != flds.end();
76         ++iter
77     )
78     {
79         const GeoField& fld = *iter();
81         typename GeoField::GeometricBoundaryField& bfld =
82             const_cast<typename GeoField::GeometricBoundaryField&>
83             (
84                 fld.boundaryField()
85             );
87         label sz = bfld.size();
88         bfld.setSize(sz + 1);
89         bfld.set
90         (
91             sz,
92             GeoField::PatchFieldType::New
93             (
94                 patchFieldType,
95                 mesh_.boundary()[sz],
96                 fld.dimensionedInternalField()
97             )
98         );
99     }
103 // Delete trailing patch fields
104 template<class GeoField>
105 void Foam::fvMeshDistribute::deleteTrailingPatchFields()
107     HashTable<const GeoField*> flds
108     (
109         mesh_.objectRegistry::lookupClass<GeoField>()
110     );
112     for
113     (
114         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
115         iter != flds.end();
116         ++iter
117     )
118     {
119         const GeoField& fld = *iter();
121         typename GeoField::GeometricBoundaryField& bfld =
122             const_cast<typename GeoField::GeometricBoundaryField&>
123             (
124                 fld.boundaryField()
125             );
127         // Shrink patchFields
128         bfld.setSize(bfld.size() - 1);
129     }
133 // Save whole boundary field
134 template <class T, class Mesh>
135 void Foam::fvMeshDistribute::saveBoundaryFields
137     PtrList<FieldField<fvsPatchField, T> >& bflds
138 ) const
140     typedef GeometricField<T, fvsPatchField, Mesh> fldType;
142     HashTable<const fldType*> flds
143     (
144         mesh_.objectRegistry::lookupClass<fldType>()
145     );
147     bflds.setSize(flds.size());
149     label i = 0;
151     for
152     (
153         typename HashTable<const fldType*>::const_iterator iter = flds.begin();
154         iter != flds.end();
155         ++iter
156     )
157     {
158         const fldType& fld = *iter();
160         bflds.set(i, fld.boundaryField().clone().ptr());
162         i++;
163     }
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
181     (
182         mesh_.objectRegistry::lookupClass<fldType>()
183     );
185     if (flds.size() != oldBflds.size())
186     {
187         FatalErrorIn("fvMeshDistribute::mapBoundaryFields") << "problem"
188             << abort(FatalError);
189     }
191     label fieldI = 0;
193     for
194     (
195         typename HashTable<const fldType*>::const_iterator iter = flds.begin();
196         iter != flds.end();
197         ++iter
198     )
199     {
200         const fldType& fld = *iter();
201         typename fldType::GeometricBoundaryField& bfld =
202             const_cast<typename fldType::GeometricBoundaryField&>
203             (
204                 fld.boundaryField()
205             );
208         const FieldField<fvsPatchField, T>& oldBfld = oldBflds[fieldI++];
210         // Pull from old boundary field into bfld.
212         forAll(bfld, patchI)
213         {
214             fvsPatchField<T>& patchFld = bfld[patchI];
215             label faceI = patchFld.patch().patch().start();
217             forAll(patchFld, i)
218             {
219                 label oldFaceI = faceMap[faceI++];
221                 // Find patch and local patch face oldFaceI was in.
222                 forAll(oldPatchStarts, oldPatchI)
223                 {
224                     label oldLocalI = oldFaceI - oldPatchStarts[oldPatchI];
226                     if (oldLocalI >= 0 && oldLocalI < oldBfld[oldPatchI].size())
227                     {
228                         patchFld[i] = oldBfld[oldPatchI][oldLocalI];
229                     }
230                 }
231             }
232         }
233     }
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
246     (
247         mesh_.objectRegistry::lookupClass<GeoField>()
248     );
250     for
251     (
252         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
253         iter != flds.end();
254         ++iter
255     )
256     {
257         const GeoField& fld = *iter();
259         typename GeoField::GeometricBoundaryField& bfld =
260             const_cast<typename GeoField::GeometricBoundaryField&>
261             (
262                 fld.boundaryField()
263             );
265         forAll(bfld, patchI)
266         {
267             if (bfld[patchI].type() == patchFieldType)
268             {
269                 bfld[patchI] == initVal;
270             }
271         }
272     }
276 // Send fields. Note order supplied so we can receive in exactly the same order.
277 template<class GeoField>
278 void Foam::fvMeshDistribute::sendFields
280     const label domain,
281     const wordList& fieldNames,
282     const fvMeshSubset& subsetter
285     forAll(fieldNames, i)
286     {
287         //Pout<< "Subsetting field " << fieldNames[i]
288         //    << " for domain:" << domain
289         //    << endl;
291         // Send all fieldNames. This has to be exactly the same set as is
292         // being received!
293         const GeoField& fld =
294             subsetter.baseMesh().lookupObject<GeoField>(fieldNames[i]);
296         tmp<GeoField> tsubfld = subsetter.interpolate(fld);
298         // Send
299         OPstream toNbr(Pstream::blocking, domain);
300         toNbr << tsubfld();
301     }
305 // Opposite of sendFields
306 template<class GeoField>
307 void Foam::fvMeshDistribute::receiveFields
309     const label domain,
310     const wordList& fieldNames,
311     fvMesh& mesh,
312     PtrList<GeoField>& fields
315     fields.setSize(fieldNames.size());
317     forAll(fieldNames, i)
318     {
319         //Pout<< "Receiving field " << fieldNames[i]
320         //    << " from domain:" << domain
321         //    << endl;
323         IPstream fromNbr(Pstream::blocking, domain);
325         fields.set
326         (
327             i,
328             new GeoField
329             (
330                 IOobject
331                 (
332                     fieldNames[i],
333                     mesh.time().timeName(),
334                     mesh,
335                     IOobject::NO_READ,
336                     IOobject::AUTO_WRITE
337                 ),
338                 mesh,
339                 fromNbr
340             )
341         );
342     }
346 // ************************************************************************* //