FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

GeometricBoundaryField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/emptyPolyPatch.H>
00027 #include <OpenFOAM/commSchedule.H>
00028 #include <OpenFOAM/globalMeshData.H>
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 template<class Type, template<class> class PatchField, class GeoMesh>
00033 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00034 GeometricBoundaryField
00035 (
00036     const BoundaryMesh& bmesh,
00037     const DimensionedField<Type, GeoMesh>& field,
00038     const word& patchFieldType
00039 )
00040 :
00041     FieldField<PatchField, Type>(bmesh.size()),
00042     bmesh_(bmesh)
00043 {
00044     if (debug)
00045     {
00046         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
00047                "GeometricBoundaryField::"
00048                "GeometricBoundaryField(const BoundaryMesh&, "
00049                "const Field<Type>&, const word&)"
00050             << endl;
00051     }
00052 
00053     forAll(bmesh_, patchi)
00054     {
00055         this->set
00056         (
00057             patchi,
00058             PatchField<Type>::New
00059             (
00060                 patchFieldType,
00061                 bmesh_[patchi],
00062                 field
00063             )
00064         );
00065     }
00066 }
00067 
00068 
00069 template<class Type, template<class> class PatchField, class GeoMesh>
00070 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00071 GeometricBoundaryField
00072 (
00073     const BoundaryMesh& bmesh,
00074     const DimensionedField<Type, GeoMesh>& field,
00075     const wordList& patchFieldTypes
00076 )
00077 :
00078     FieldField<PatchField, Type>(bmesh.size()),
00079     bmesh_(bmesh)
00080 {
00081     if (debug)
00082     {
00083         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
00084                "GeometricBoundaryField::"
00085                "GeometricBoundaryField(const BoundaryMesh&, "
00086                "const Field<Type>&, const wordList&)"
00087             << endl;
00088     }
00089 
00090     if (patchFieldTypes.size() != this->size())
00091     {
00092         FatalErrorIn
00093         (
00094             "GeometricField<Type, PatchField, GeoMesh>::"
00095             "GeometricBoundaryField::"
00096             "GeometricBoundaryField(const BoundaryMesh&, "
00097             "const Field<Type>&, const wordList&)"
00098         )   << "Incorrect number of patch type specifications given" << nl
00099             << "    Number of patches in mesh = " << bmesh.size()
00100             << " number of patch type specifications = "
00101             << patchFieldTypes.size()
00102             << abort(FatalError);
00103     }
00104 
00105     forAll(bmesh_, patchi)
00106     {
00107         this->set
00108         (
00109             patchi,
00110             PatchField<Type>::New
00111             (
00112                 patchFieldTypes[patchi],
00113                 bmesh_[patchi],
00114                 field
00115             )
00116         );
00117     }
00118 }
00119 
00120 
00121 template<class Type, template<class> class PatchField, class GeoMesh>
00122 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00123 GeometricBoundaryField
00124 (
00125     const BoundaryMesh& bmesh,
00126     const DimensionedField<Type, GeoMesh>& field,
00127     const PtrList<PatchField<Type> >& ptfl
00128 )
00129 :
00130     FieldField<PatchField, Type>(bmesh.size()),
00131     bmesh_(bmesh)
00132 {
00133     if (debug)
00134     {
00135         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
00136                "GeometricBoundaryField::"
00137                "GeometricBoundaryField(const BoundaryMesh&, "
00138                "const Field<Type>&, const PatchField<Type>List&)"
00139             << endl;
00140     }
00141 
00142     forAll(bmesh_, patchi)
00143     {
00144         this->set(patchi, ptfl[patchi].clone(field));
00145     }
00146 }
00147 
00148 
00149 template<class Type, template<class> class PatchField, class GeoMesh>
00150 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00151 GeometricBoundaryField
00152 (
00153     const DimensionedField<Type, GeoMesh>& field,
00154     const typename GeometricField<Type, PatchField, GeoMesh>::
00155     GeometricBoundaryField& btf
00156 )
00157 :
00158     FieldField<PatchField, Type>(btf.size()),
00159     bmesh_(btf.bmesh_)
00160 {
00161     if (debug)
00162     {
00163         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
00164                "GeometricBoundaryField::"
00165                "GeometricBoundaryField(const GeometricBoundaryField<Type, "
00166                "PatchField, BoundaryMesh>&)"
00167             << endl;
00168     }
00169 
00170     forAll(bmesh_, patchi)
00171     {
00172         this->set(patchi, btf[patchi].clone(field));
00173     }
00174 }
00175 
00176 
00177 // Construct as copy
00178 // Dangerous because Field may be set to a field which gets deleted.
00179 // Need new type of GeometricBoundaryField, one which IS part of a geometric
00180 // field for which snGrad etc. may be called and a free standing
00181 // GeometricBoundaryField for which such operations are unavailable.
00182 template<class Type, template<class> class PatchField, class GeoMesh>
00183 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00184 GeometricBoundaryField
00185 (
00186     const typename GeometricField<Type, PatchField, GeoMesh>::
00187     GeometricBoundaryField& btf
00188 )
00189 :
00190     FieldField<PatchField, Type>(btf),
00191     bmesh_(btf.bmesh_)
00192 {
00193     if (debug)
00194     {
00195         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
00196                "GeometricBoundaryField::"
00197                "GeometricBoundaryField(const GeometricBoundaryField<Type, "
00198                "PatchField, BoundaryMesh>&)"
00199             << endl;
00200     }
00201 }
00202 
00203 
00204 template<class Type, template<class> class PatchField, class GeoMesh>
00205 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00206 GeometricBoundaryField
00207 (
00208     const BoundaryMesh& bmesh,
00209     const DimensionedField<Type, GeoMesh>& field,
00210     const dictionary& dict
00211 )
00212 :
00213     FieldField<PatchField, Type>(bmesh.size()),
00214     bmesh_(bmesh)
00215 {
00216     if (debug)
00217     {
00218         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
00219                "GeometricBoundaryField::"
00220                "GeometricBoundaryField"
00221                "(const BoundaryMesh&, const Field<Type>&, const dictionary&)"
00222             << endl;
00223     }
00224 
00225     forAll(bmesh_, patchi)
00226     {
00227         if (bmesh_[patchi].type() != emptyPolyPatch::typeName)
00228         {
00229             this->set
00230             (
00231                 patchi,
00232                 PatchField<Type>::New
00233                 (
00234                     bmesh_[patchi],
00235                     field,
00236                     dict.subDict(bmesh_[patchi].name())
00237                 )
00238             );
00239         }
00240         else
00241         {
00242             this->set
00243             (
00244                 patchi,
00245                 PatchField<Type>::New
00246                 (
00247                     emptyPolyPatch::typeName,
00248                     bmesh_[patchi],
00249                     field
00250                 )
00251             );
00252         }
00253     }
00254 }
00255 
00256 
00257 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00258 
00259 template<class Type, template<class> class PatchField, class GeoMesh>
00260 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00261 updateCoeffs()
00262 {
00263     if (debug)
00264     {
00265         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
00266                "GeometricBoundaryField::"
00267                "updateCoeffs()" << endl;
00268     }
00269 
00270     forAll(*this, patchi)
00271     {
00272         this->operator[](patchi).updateCoeffs();
00273     }
00274 }
00275 
00276 
00277 template<class Type, template<class> class PatchField, class GeoMesh>
00278 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00279 evaluate()
00280 {
00281     if (debug)
00282     {
00283         Info<< "GeometricField<Type, PatchField, GeoMesh>::"
00284                "GeometricBoundaryField::"
00285                "evaluate()" << endl;
00286     }
00287 
00288     if
00289     (
00290         Pstream::defaultCommsType == Pstream::blocking
00291      || Pstream::defaultCommsType == Pstream::nonBlocking
00292     )
00293     {
00294         forAll(*this, patchi)
00295         {
00296             this->operator[](patchi).initEvaluate(Pstream::defaultCommsType);
00297         }
00298 
00299         // Block for any outstanding requests
00300         if (Pstream::defaultCommsType == Pstream::nonBlocking)
00301         {
00302             IPstream::waitRequests();
00303             OPstream::waitRequests();
00304         }
00305 
00306         forAll(*this, patchi)
00307         {
00308             this->operator[](patchi).evaluate(Pstream::defaultCommsType);
00309         }
00310     }
00311     else if (Pstream::defaultCommsType == Pstream::scheduled)
00312     {
00313         const lduSchedule& patchSchedule =
00314             bmesh_.mesh().globalData().patchSchedule();
00315 
00316         forAll(patchSchedule, patchEvali)
00317         {
00318             if (patchSchedule[patchEvali].init)
00319             {
00320                 this->operator[](patchSchedule[patchEvali].patch)
00321                     .initEvaluate(Pstream::scheduled);
00322             }
00323             else
00324             {
00325                 this->operator[](patchSchedule[patchEvali].patch)
00326                     .evaluate(Pstream::scheduled);
00327             }
00328         }
00329     }
00330     else
00331     {
00332         FatalErrorIn("GeometricBoundaryField::evaluate()")
00333             << "Unsuported communications type "
00334             << Pstream::commsTypeNames[Pstream::defaultCommsType]
00335             << exit(FatalError);
00336     }
00337 }
00338 
00339 
00340 template<class Type, template<class> class PatchField, class GeoMesh>
00341 Foam::wordList
00342 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00343 types() const
00344 {
00345     const FieldField<PatchField, Type>& pff = *this;
00346 
00347     wordList Types(pff.size());
00348 
00349     forAll(pff, patchi)
00350     {
00351         Types[patchi] = pff[patchi].type();
00352     }
00353 
00354     return Types;
00355 }
00356 
00357 
00358 template<class Type, template<class> class PatchField, class GeoMesh>
00359 typename Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField
00360 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00361 boundaryInternalField() const
00362 {
00363     typename GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField
00364         BoundaryInternalField(*this);
00365 
00366     forAll(BoundaryInternalField, patchi)
00367     {
00368         BoundaryInternalField[patchi] ==
00369             this->operator[](patchi).patchInternalField();
00370     }
00371 
00372     return BoundaryInternalField;
00373 }
00374 
00375 
00376 template<class Type, template<class> class PatchField, class GeoMesh>
00377 Foam::lduInterfaceFieldPtrsList
00378 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00379 interfaces() const
00380 {
00381     lduInterfaceFieldPtrsList interfaces(this->size());
00382 
00383     forAll (interfaces, patchi)
00384     {
00385         if (isA<lduInterfaceField>(this->operator[](patchi)))
00386         {
00387             interfaces.set
00388             (
00389                 patchi,
00390                 &refCast<const lduInterfaceField>(this->operator[](patchi))
00391             );
00392         }
00393     }
00394 
00395     return interfaces;
00396 }
00397 
00398 
00399 template<class Type, template<class> class PatchField, class GeoMesh>
00400 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00401 writeEntry(const word& keyword, Ostream& os) const
00402 {
00403     os  << keyword << nl << token::BEGIN_BLOCK << incrIndent << nl;
00404 
00405     forAll(*this, patchi)
00406     {
00407         os  << indent << this->operator[](patchi).patch().name() << nl
00408             << indent << token::BEGIN_BLOCK << nl
00409             << incrIndent << this->operator[](patchi) << decrIndent
00410             << indent << token::END_BLOCK << endl;
00411     }
00412 
00413     os  << decrIndent << token::END_BLOCK << endl;
00414 
00415     // Check state of IOstream
00416     os.check
00417     (
00418         "GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::"
00419         "writeEntry(const word& keyword, Ostream& os) const"
00420     );
00421 }
00422 
00423 
00424 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00425 
00426 template<class Type, template<class> class PatchField, class GeoMesh>
00427 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00428 operator=
00429 (
00430     const typename GeometricField<Type, PatchField, GeoMesh>::
00431     GeometricBoundaryField& bf
00432 )
00433 {
00434     FieldField<PatchField, Type>::operator=(bf);
00435 }
00436 
00437 
00438 template<class Type, template<class> class PatchField, class GeoMesh>
00439 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00440 operator=
00441 (
00442     const FieldField<PatchField, Type>& ptff
00443 )
00444 {
00445     FieldField<PatchField, Type>::operator=(ptff);
00446 }
00447 
00448 
00449 template<class Type, template<class> class PatchField, class GeoMesh>
00450 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00451 operator=
00452 (
00453     const Type& t
00454 )
00455 {
00456     FieldField<PatchField, Type>::operator=(t);
00457 }
00458 
00459 
00460 // Forced assignments
00461 template<class Type, template<class> class PatchField, class GeoMesh>
00462 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00463 operator==
00464 (
00465     const typename GeometricField<Type, PatchField, GeoMesh>::
00466     GeometricBoundaryField& bf
00467 )
00468 {
00469     forAll((*this), patchI)
00470     {
00471         this->operator[](patchI) == bf[patchI];
00472     }
00473 }
00474 
00475 
00476 template<class Type, template<class> class PatchField, class GeoMesh>
00477 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00478 operator==
00479 (
00480     const FieldField<PatchField, Type>& ptff
00481 )
00482 {
00483     forAll((*this), patchI)
00484     {
00485         this->operator[](patchI) == ptff[patchI];
00486     }
00487 }
00488 
00489 
00490 template<class Type, template<class> class PatchField, class GeoMesh>
00491 void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
00492 operator==
00493 (
00494     const Type& t
00495 )
00496 {
00497     forAll((*this), patchI)
00498     {
00499         this->operator[](patchI) == t;
00500     }
00501 }
00502 
00503 
00504 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00505 
00506 template<class Type, template<class> class PatchField, class GeoMesh>
00507 Foam::Ostream& Foam::operator<<
00508 (
00509     Ostream& os,
00510     const typename GeometricField<Type, PatchField, GeoMesh>::
00511     GeometricBoundaryField& bf
00512 )
00513 {
00514     os << static_cast<const FieldField<PatchField, Type>&>(bf);
00515     return os;
00516 }
00517 
00518 
00519 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines