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

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