OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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