ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / fields / GeometricFields / GeometricField / GeometricBoundaryField.C
blob85d7a29440e38a041491a814a8995f24cc95b41e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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 "emptyPolyPatch.H"
27 #include "commSchedule.H"
28 #include "globalMeshData.H"
29 #include "cyclicPolyPatch.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 template<class Type, template<class> class PatchField, class GeoMesh>
34 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
35 GeometricBoundaryField
37     const BoundaryMesh& bmesh,
38     const DimensionedField<Type, GeoMesh>& field,
39     const word& patchFieldType
42     FieldField<PatchField, Type>(bmesh.size()),
43     bmesh_(bmesh)
45     if (debug)
46     {
47         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
48                "GeometricBoundaryField::"
49                "GeometricBoundaryField(const BoundaryMesh&, "
50                "const Field<Type>&, const word&)"
51             << endl;
52     }
54     forAll(bmesh_, patchi)
55     {
56         this->set
57         (
58             patchi,
59             PatchField<Type>::New
60             (
61                 patchFieldType,
62                 bmesh_[patchi],
63                 field
64             )
65         );
66     }
70 template<class Type, template<class> class PatchField, class GeoMesh>
71 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
72 GeometricBoundaryField
74     const BoundaryMesh& bmesh,
75     const DimensionedField<Type, GeoMesh>& field,
76     const wordList& patchFieldTypes,
77     const wordList& constraintTypes
80     FieldField<PatchField, Type>(bmesh.size()),
81     bmesh_(bmesh)
83     if (debug)
84     {
85         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
86                "GeometricBoundaryField::"
87                "GeometricBoundaryField(const BoundaryMesh&, "
88                "const Field<Type>&, const wordList&, const wordList&)"
89             << endl;
90     }
92     if
93     (
94         patchFieldTypes.size() != this->size()
95      || (constraintTypes.size() && (constraintTypes.size() != this->size()))
96     )
97     {
98         FatalErrorIn
99         (
100             "GeometricField<Type, PatchField, GeoMesh>::"
101             "GeometricBoundaryField::"
102             "GeometricBoundaryField(const BoundaryMesh&, "
103             "const Field<Type>&, const wordList&, const wordList&)"
104         )   << "Incorrect number of patch type specifications given" << nl
105             << "    Number of patches in mesh = " << bmesh.size()
106             << " number of patch type specifications = "
107             << patchFieldTypes.size()
108             << abort(FatalError);
109     }
111     if (constraintTypes.size())
112     {
113         forAll(bmesh_, patchi)
114         {
115             this->set
116             (
117                 patchi,
118                 PatchField<Type>::New
119                 (
120                     patchFieldTypes[patchi],
121                     constraintTypes[patchi],
122                     bmesh_[patchi],
123                     field
124                 )
125             );
126         }
127     }
128     else
129     {
130         forAll(bmesh_, patchi)
131         {
132             this->set
133             (
134                 patchi,
135                 PatchField<Type>::New
136                 (
137                     patchFieldTypes[patchi],
138                     bmesh_[patchi],
139                     field
140                 )
141             );
142         }
143     }
147 template<class Type, template<class> class PatchField, class GeoMesh>
148 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
149 GeometricBoundaryField
151     const BoundaryMesh& bmesh,
152     const DimensionedField<Type, GeoMesh>& field,
153     const PtrList<PatchField<Type> >& ptfl
156     FieldField<PatchField, Type>(bmesh.size()),
157     bmesh_(bmesh)
159     if (debug)
160     {
161         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
162                "GeometricBoundaryField::"
163                "GeometricBoundaryField(const BoundaryMesh&, "
164                "const Field<Type>&, const PatchField<Type>List&)"
165             << endl;
166     }
168     forAll(bmesh_, patchi)
169     {
170         this->set(patchi, ptfl[patchi].clone(field));
171     }
175 template<class Type, template<class> class PatchField, class GeoMesh>
176 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
177 GeometricBoundaryField
179     const DimensionedField<Type, GeoMesh>& field,
180     const typename GeometricField<Type, PatchField, GeoMesh>::
181     GeometricBoundaryField& btf
184     FieldField<PatchField, Type>(btf.size()),
185     bmesh_(btf.bmesh_)
187     if (debug)
188     {
189         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
190                "GeometricBoundaryField::"
191                "GeometricBoundaryField(const GeometricBoundaryField<Type, "
192                "PatchField, BoundaryMesh>&)"
193             << endl;
194     }
196     forAll(bmesh_, patchi)
197     {
198         this->set(patchi, btf[patchi].clone(field));
199     }
203 // Construct as copy
204 // Dangerous because Field may be set to a field which gets deleted.
205 // Need new type of GeometricBoundaryField, one which IS part of a geometric
206 // field for which snGrad etc. may be called and a free standing
207 // GeometricBoundaryField for which such operations are unavailable.
208 template<class Type, template<class> class PatchField, class GeoMesh>
209 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
210 GeometricBoundaryField
212     const typename GeometricField<Type, PatchField, GeoMesh>::
213     GeometricBoundaryField& btf
216     FieldField<PatchField, Type>(btf),
217     bmesh_(btf.bmesh_)
219     if (debug)
220     {
221         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
222                "GeometricBoundaryField::"
223                "GeometricBoundaryField(const GeometricBoundaryField<Type, "
224                "PatchField, BoundaryMesh>&)"
225             << endl;
226     }
230 template<class Type, template<class> class PatchField, class GeoMesh>
231 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
232 GeometricBoundaryField
234     const BoundaryMesh& bmesh,
235     const DimensionedField<Type, GeoMesh>& field,
236     const dictionary& dict
239     FieldField<PatchField, Type>(bmesh.size()),
240     bmesh_(bmesh)
242     if (debug)
243     {
244         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
245                "GeometricBoundaryField::"
246                "GeometricBoundaryField"
247                "(const BoundaryMesh&, const Field<Type>&, const dictionary&)"
248             << endl;
249     }
251     forAll(bmesh_, patchi)
252     {
253         if (bmesh_[patchi].type() != emptyPolyPatch::typeName)
254         {
255             if
256             (
257                 bmesh_[patchi].type() == cyclicPolyPatch::typeName
258              && !dict.found(bmesh_[patchi].name())
259             )
260             {
261                 FatalIOErrorIn
262                 (
263                     "GeometricField<Type, PatchField, GeoMesh>::\n"
264                     "GeometricBoundaryField::GeometricBoundaryField\n"
265                     "(\n"
266                     "    const BoundaryMesh&,\n"
267                     "    const DimensionedField<Type, GeoMesh>&,\n"
268                     "    const dictionary&\n"
269                     ")",
270                     dict
271                 )   << "Cannot find patchField entry for cyclic "
272                     << bmesh_[patchi].name() << endl
273                     << "Is your field uptodate with split cyclics?" << endl
274                     << "Run foamUpgradeCyclics to convert mesh and fields"
275                     << " to split cyclics." << exit(FatalIOError);
276             }
278             this->set
279             (
280                 patchi,
281                 PatchField<Type>::New
282                 (
283                     bmesh_[patchi],
284                     field,
285                     dict.subDict(bmesh_[patchi].name())
286                 )
287             );
288         }
289         else
290         {
291             this->set
292             (
293                 patchi,
294                 PatchField<Type>::New
295                 (
296                     emptyPolyPatch::typeName,
297                     bmesh_[patchi],
298                     field
299                 )
300             );
301         }
302     }
306 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
308 template<class Type, template<class> class PatchField, class GeoMesh>
309 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
310 updateCoeffs()
312     if (debug)
313     {
314         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
315                "GeometricBoundaryField::"
316                "updateCoeffs()" << endl;
317     }
319     forAll(*this, patchi)
320     {
321         this->operator[](patchi).updateCoeffs();
322     }
326 template<class Type, template<class> class PatchField, class GeoMesh>
327 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
328 evaluate()
330     if (debug)
331     {
332         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
333                "GeometricBoundaryField::"
334                "evaluate()" << endl;
335     }
337     if
338     (
339         Pstream::defaultCommsType == Pstream::blocking
340      || Pstream::defaultCommsType == Pstream::nonBlocking
341     )
342     {
343         forAll(*this, patchi)
344         {
345             this->operator[](patchi).initEvaluate(Pstream::defaultCommsType);
346         }
348         // Block for any outstanding requests
349         if
350         (
351             Pstream::parRun()
352          && Pstream::defaultCommsType == Pstream::nonBlocking
353         )
354         {
355             Pstream::waitRequests();
356         }
358         forAll(*this, patchi)
359         {
360             this->operator[](patchi).evaluate(Pstream::defaultCommsType);
361         }
362     }
363     else if (Pstream::defaultCommsType == Pstream::scheduled)
364     {
365         const lduSchedule& patchSchedule =
366             bmesh_.mesh().globalData().patchSchedule();
368         forAll(patchSchedule, patchEvali)
369         {
370             if (patchSchedule[patchEvali].init)
371             {
372                 this->operator[](patchSchedule[patchEvali].patch)
373                     .initEvaluate(Pstream::scheduled);
374             }
375             else
376             {
377                 this->operator[](patchSchedule[patchEvali].patch)
378                     .evaluate(Pstream::scheduled);
379             }
380         }
381     }
382     else
383     {
384         FatalErrorIn("GeometricBoundaryField::evaluate()")
385             << "Unsuported communications type "
386             << Pstream::commsTypeNames[Pstream::defaultCommsType]
387             << exit(FatalError);
388     }
392 template<class Type, template<class> class PatchField, class GeoMesh>
393 Foam::wordList
394 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
395 types() const
397     const FieldField<PatchField, Type>& pff = *this;
399     wordList Types(pff.size());
401     forAll(pff, patchi)
402     {
403         Types[patchi] = pff[patchi].type();
404     }
406     return Types;
410 template<class Type, template<class> class PatchField, class GeoMesh>
411 typename Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField
412 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
413 boundaryInternalField() const
415     typename GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField
416         BoundaryInternalField(*this);
418     forAll(BoundaryInternalField, patchi)
419     {
420         BoundaryInternalField[patchi] ==
421             this->operator[](patchi).patchInternalField();
422     }
424     return BoundaryInternalField;
428 template<class Type, template<class> class PatchField, class GeoMesh>
429 Foam::lduInterfaceFieldPtrsList
430 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
431 interfaces() const
433     lduInterfaceFieldPtrsList interfaces(this->size());
435     forAll(interfaces, patchi)
436     {
437         if (isA<lduInterfaceField>(this->operator[](patchi)))
438         {
439             interfaces.set
440             (
441                 patchi,
442                 &refCast<const lduInterfaceField>(this->operator[](patchi))
443             );
444         }
445     }
447     return interfaces;
451 template<class Type, template<class> class PatchField, class GeoMesh>
452 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
453 writeEntry(const word& keyword, Ostream& os) const
455     os  << keyword << nl << token::BEGIN_BLOCK << incrIndent << nl;
457     forAll(*this, patchi)
458     {
459         os  << indent << this->operator[](patchi).patch().name() << nl
460             << indent << token::BEGIN_BLOCK << nl
461             << incrIndent << this->operator[](patchi) << decrIndent
462             << indent << token::END_BLOCK << endl;
463     }
465     os  << decrIndent << token::END_BLOCK << endl;
467     // Check state of IOstream
468     os.check
469     (
470         "GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::"
471         "writeEntry(const word& keyword, Ostream& os) const"
472     );
476 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
478 template<class Type, template<class> class PatchField, class GeoMesh>
479 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
480 operator=
482     const typename GeometricField<Type, PatchField, GeoMesh>::
483     GeometricBoundaryField& bf
486     FieldField<PatchField, Type>::operator=(bf);
490 template<class Type, template<class> class PatchField, class GeoMesh>
491 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
492 operator=
494     const FieldField<PatchField, Type>& ptff
497     FieldField<PatchField, Type>::operator=(ptff);
501 template<class Type, template<class> class PatchField, class GeoMesh>
502 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
503 operator=
505     const Type& t
508     FieldField<PatchField, Type>::operator=(t);
512 // Forced assignments
513 template<class Type, template<class> class PatchField, class GeoMesh>
514 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
515 operator==
517     const typename GeometricField<Type, PatchField, GeoMesh>::
518     GeometricBoundaryField& bf
521     forAll((*this), patchI)
522     {
523         this->operator[](patchI) == bf[patchI];
524     }
528 template<class Type, template<class> class PatchField, class GeoMesh>
529 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
530 operator==
532     const FieldField<PatchField, Type>& ptff
535     forAll((*this), patchI)
536     {
537         this->operator[](patchI) == ptff[patchI];
538     }
542 template<class Type, template<class> class PatchField, class GeoMesh>
543 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
544 operator==
546     const Type& t
549     forAll((*this), patchI)
550     {
551         this->operator[](patchI) == t;
552     }
556 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
558 template<class Type, template<class> class PatchField, class GeoMesh>
559 Foam::Ostream& Foam::operator<<
561     Ostream& os,
562     const typename GeometricField<Type, PatchField, GeoMesh>::
563     GeometricBoundaryField& bf
566     os << static_cast<const FieldField<PatchField, Type>&>(bf);
567     return os;
571 // ************************************************************************* //