ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / sampling / probes / probesTemplates.C
blob5eaa64dda82577e762824edb3297764ca8a1fd42
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "probes.H"
27 #include "volFields.H"
28 #include "IOmanip.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 //- comparison operator for probes class
36 template<class T>
37 class isNotEqOp
39 public:
41     void operator()(T& x, const T& y) const
42     {
43         const T unsetVal(-VGREAT*pTraits<T>::one);
45         if (x != unsetVal)
46         {
47             // Keep x.
49             // Note:chould check for y != unsetVal but multiple sample cells
50             // already handled in read().
51         }
52         else
53         {
54             // x is not set. y might be.
55             x = y;
56         }
57     }
63 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
65 template<class Type>
66 void Foam::probes::sampleAndWrite
68     const GeometricField<Type, fvPatchField, volMesh>& vField
71     Field<Type> values(sample(vField));
73     if (Pstream::master())
74     {
75         unsigned int w = IOstream::defaultPrecision() + 7;
76         OFstream& os = *probeFilePtrs_[vField.name()];
78         os  << setw(w) << vField.time().value();
80         forAll(values, probeI)
81         {
82             os  << ' ' << setw(w) << values[probeI];
83         }
84         os  << endl;
85     }
89 template <class Type>
90 void Foam::probes::sampleAndWrite
92     const fieldGroup<Type>& fields
95     forAll(fields, fieldI)
96     {
97         if (loadFromFiles_)
98         {
99             sampleAndWrite
100             (
101                 GeometricField<Type, fvPatchField, volMesh>
102                 (
103                     IOobject
104                     (
105                         fields[fieldI],
106                         mesh_.time().timeName(),
107                         mesh_,
108                         IOobject::MUST_READ,
109                         IOobject::NO_WRITE,
110                         false
111                     ),
112                     mesh_
113                 )
114             );
115         }
116         else
117         {
118             objectRegistry::const_iterator iter = mesh_.find(fields[fieldI]);
120             if
121             (
122                 iter != objectRegistry::end()
123              && iter()->type()
124              == GeometricField<Type, fvPatchField, volMesh>::typeName
125             )
126             {
127                 sampleAndWrite
128                 (
129                     mesh_.lookupObject
130                     <GeometricField<Type, fvPatchField, volMesh> >
131                     (
132                         fields[fieldI]
133                     )
134                 );
135             }
136         }
137     }
141 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
143 template<class Type>
144 Foam::tmp<Foam::Field<Type> >
145 Foam::probes::sample
147     const GeometricField<Type, fvPatchField, volMesh>& vField
148 ) const
150     const Type unsetVal(-VGREAT*pTraits<Type>::one);
152     tmp<Field<Type> > tValues
153     (
154         new Field<Type>(this->size(), unsetVal)
155     );
157     Field<Type>& values = tValues();
159     forAll(*this, probeI)
160     {
161         if (elementList_[probeI] >= 0)
162         {
163             values[probeI] = vField[elementList_[probeI]];
164         }
165     }
167     Pstream::listCombineGather(values, isNotEqOp<Type>());
168     Pstream::listCombineScatter(values);
170     return tValues;
174 template<class Type>
175 Foam::tmp<Foam::Field<Type> >
176 Foam::probes::sample(const word& fieldName) const
178     return sample
179     (
180         mesh_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
181         (
182             fieldName
183         )
184     );
188 // ************************************************************************* //