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

patchProbesTemplates.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) 2010-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 "patchProbes.H"
00027 #include <finiteVolume/volFields.H>
00028 #include <OpenFOAM/IOmanip.H>
00029 
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 template<class Type>
00034 void Foam::patchProbes::sampleAndWrite
00035 (
00036     const GeometricField<Type, fvPatchField, volMesh>& vField
00037 )
00038 {
00039     Field<Type> values = sample(vField);
00040 
00041     if (Pstream::master())
00042     {
00043         unsigned int w = IOstream::defaultPrecision() + 7;
00044         OFstream& probeStream = *probeFilePtrs_[vField.name()];
00045 
00046         probeStream << setw(w) << vField.time().value();
00047 
00048         forAll(values, probeI)
00049         {
00050             probeStream << ' ' << setw(w) << values[probeI];
00051         }
00052         probeStream << endl;
00053     }
00054 }
00055 
00056 
00057 template <class Type>
00058 void Foam::patchProbes::sampleAndWrite
00059 (
00060     const fieldGroup<Type>& fields
00061 )
00062 {
00063     forAll(fields, fieldI)
00064     {
00065         if (loadFromFiles_)
00066         {
00067             sampleAndWrite
00068             (
00069                 GeometricField<Type, fvPatchField, volMesh>
00070                 (
00071                     IOobject
00072                     (
00073                         fields[fieldI],
00074                         obr_.time().timeName(),
00075                         refCast<const polyMesh>(obr_),
00076                         IOobject::MUST_READ,
00077                         IOobject::NO_WRITE,
00078                         false
00079                     ),
00080                     refCast<const fvMesh>(obr_)
00081                 )
00082             );
00083         }
00084         else
00085         {
00086             objectRegistry::const_iterator iter = obr_.find(fields[fieldI]);
00087 
00088             if
00089             (
00090                 iter != obr_.end()
00091              && iter()->type()
00092              == GeometricField<Type, fvPatchField, volMesh>::typeName
00093             )
00094             {
00095                 sampleAndWrite
00096                 (
00097                     obr_.lookupObject
00098                     <GeometricField<Type, fvPatchField, volMesh> >
00099                     (
00100                         fields[fieldI]
00101                     )
00102                 );
00103             }
00104         }
00105     }
00106 }
00107 
00108 
00109 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00110 
00111 template<class Type>
00112 Foam::tmp<Foam::Field<Type> >
00113 Foam::patchProbes::sample
00114 (
00115     const GeometricField<Type, fvPatchField, volMesh>& vField
00116 ) const
00117 {
00118     const Type unsetVal(-VGREAT*pTraits<Type>::one);
00119 
00120     tmp<Field<Type> > tValues
00121     (
00122         new Field<Type>(probeLocations_.size(), unsetVal)
00123     );
00124 
00125     Field<Type>& values = tValues();
00126 
00127     const polyBoundaryMesh& patches = vField.mesh().boundaryMesh();
00128 
00129     forAll(probeLocations_, probeI)
00130     {
00131         label faceI = elementList_[probeI];
00132 
00133         if (faceI >= 0)
00134         {
00135             label patchI = patches.whichPatch(faceI);
00136             label localFaceI = patches[patchI].whichFace(faceI);
00137             values[probeI] = vField.boundaryField()[patchI][localFaceI];
00138         }
00139     }
00140 
00141     Pstream::listCombineGather(values, isNotEqOp<Type>());
00142     Pstream::listCombineScatter(values);
00143 
00144     return tValues;
00145 }
00146 
00147 
00148 template<class Type>
00149 Foam::tmp<Foam::Field<Type> >
00150 Foam::patchProbes::sample(const word& fieldName) const
00151 {
00152     return sample
00153     (
00154         obr_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
00155         (
00156             fieldName
00157         )
00158     );
00159 }
00160 
00161 
00162 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines