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

probesTemplates.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 "probes.H"
00028 #include "volFields.H"
00029 #include "IOmanip.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 //- comparison operator for probes class
00037 template<class T>
00038 class isNotEqOp
00039 {
00040 public:
00041 
00042     void operator()(T& x, const T& y) const
00043     {
00044         const T unsetVal(-VGREAT*pTraits<T>::one);
00045 
00046         if (x != unsetVal)
00047         {
00048             // Keep x.
00049 
00050             // Note:chould check for y != unsetVal but multiple sample cells
00051             // already handled in read().
00052         }
00053         else
00054         {
00055             // x is not set. y might be.
00056             x = y;
00057         }
00058     }
00059 };
00060 
00061 }
00062 
00063 
00064 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00065 
00066 template<class Type>
00067 Foam::label Foam::probes::countFields
00068 (
00069     fieldGroup<Type>& fieldList,
00070     const wordList& fieldTypes
00071 ) const
00072 {
00073     fieldList.setSize(fieldNames_.size());
00074     label nFields = 0;
00075 
00076     forAll(fieldNames_, fieldI)
00077     {
00078         if
00079         (
00080             fieldTypes[fieldI]
00081          == GeometricField<Type, fvPatchField, volMesh>::typeName
00082         )
00083         {
00084             fieldList[nFields] = fieldNames_[fieldI];
00085             nFields++;
00086         }
00087     }
00088 
00089     fieldList.setSize(nFields);
00090 
00091     return nFields;
00092 }
00093 
00094 
00095 template<class Type>
00096 void Foam::probes::sampleAndWrite
00097 (
00098     const GeometricField<Type, fvPatchField, volMesh>& vField
00099 )
00100 {
00101     Field<Type> values = sample(vField);
00102 
00103     if (Pstream::master())
00104     {
00105         unsigned int w = IOstream::defaultPrecision() + 7;
00106         OFstream& probeStream = *probeFilePtrs_[vField.name()];
00107 
00108         probeStream << setw(w) << vField.time().value();
00109 
00110         forAll(values, probeI)
00111         {
00112             probeStream << ' ' << setw(w) << values[probeI];
00113         }
00114         probeStream << endl;
00115     }
00116 }
00117 
00118 
00119 template <class Type>
00120 void Foam::probes::sampleAndWrite
00121 (
00122     const fieldGroup<Type>& fields
00123 )
00124 {
00125     forAll(fields, fieldI)
00126     {
00127         if (loadFromFiles_)
00128         {
00129             sampleAndWrite
00130             (
00131                 GeometricField<Type, fvPatchField, volMesh>
00132                 (
00133                     IOobject
00134                     (
00135                         fields[fieldI],
00136                         obr_.time().timeName(),
00137                         refCast<const polyMesh>(obr_),
00138                         IOobject::MUST_READ,
00139                         IOobject::NO_WRITE,
00140                         false
00141                     ),
00142                     refCast<const fvMesh>(obr_)
00143                 )
00144             );
00145         }
00146         else
00147         {
00148             objectRegistry::const_iterator iter = obr_.find(fields[fieldI]);
00149 
00150             if
00151             (
00152                 iter != obr_.end()
00153              && iter()->type()
00154              == GeometricField<Type, fvPatchField, volMesh>::typeName
00155             )
00156             {
00157                 sampleAndWrite
00158                 (
00159                     obr_.lookupObject
00160                     <GeometricField<Type, fvPatchField, volMesh> >
00161                     (
00162                         fields[fieldI]
00163                     )
00164                 );
00165             }
00166         }
00167     }
00168 }
00169 
00170 
00171 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00172 
00173 template<class Type>
00174 Foam::tmp<Foam::Field<Type> >
00175 Foam::probes::sample
00176 (
00177     const GeometricField<Type, fvPatchField, volMesh>& vField
00178 ) const
00179 {
00180     const Type unsetVal(-VGREAT*pTraits<Type>::one);
00181 
00182     tmp<Field<Type> > tValues
00183     (
00184         new Field<Type>(probeLocations_.size(), unsetVal)
00185     );
00186 
00187     Field<Type>& values = tValues();
00188 
00189     forAll(probeLocations_, probeI)
00190     {
00191         if (cellList_[probeI] >= 0)
00192         {
00193             values[probeI] = vField[cellList_[probeI]];
00194         }
00195     }
00196 
00197     Pstream::listCombineGather(values, isNotEqOp<Type>());
00198     Pstream::listCombineScatter(values);
00199 
00200     return tValues;
00201 }
00202 
00203 
00204 template<class Type>
00205 Foam::tmp<Foam::Field<Type> >
00206 Foam::probes::sample(const word& fieldName) const
00207 {
00208     return sample
00209     (
00210         obr_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
00211         (
00212             fieldName
00213         )
00214     );
00215 }
00216 
00217 
00218 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd