Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / sampling / probes / patchProbesTemplates.C
blobe66d3d7c928f53679f8ed6529f57a00753ffa56d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2010-2010 OpenCFD Ltd.
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 "patchProbes.H"
27 #include "volFields.H"
28 #include "IOmanip.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 template<class Type>
34 void Foam::patchProbes::sampleAndWrite
36     const GeometricField<Type, fvPatchField, volMesh>& vField
39     Field<Type> values(sample(vField));
41     if (Pstream::master())
42     {
43         unsigned int w = IOstream::defaultPrecision() + 7;
44         OFstream& probeStream = *probeFilePtrs_[vField.name()];
46         probeStream << setw(w) << vField.time().value();
48         forAll(values, probeI)
49         {
50             probeStream << ' ' << setw(w) << values[probeI];
51         }
52         probeStream << endl;
53     }
57 template <class Type>
58 void Foam::patchProbes::sampleAndWrite
60     const fieldGroup<Type>& fields
63     forAll(fields, fieldI)
64     {
65         if (loadFromFiles_)
66         {
67             sampleAndWrite
68             (
69                 GeometricField<Type, fvPatchField, volMesh>
70                 (
71                     IOobject
72                     (
73                         fields[fieldI],
74                         mesh_.time().timeName(),
75                         mesh_,
76                         IOobject::MUST_READ,
77                         IOobject::NO_WRITE,
78                         false
79                     ),
80                     mesh_
81                 )
82             );
83         }
84         else
85         {
86             objectRegistry::const_iterator iter = mesh_.find(fields[fieldI]);
88             if
89             (
90                 iter != objectRegistry::end()
91              && iter()->type()
92              == GeometricField<Type, fvPatchField, volMesh>::typeName
93             )
94             {
95                 sampleAndWrite
96                 (
97                     mesh_.lookupObject
98                     <GeometricField<Type, fvPatchField, volMesh> >
99                     (
100                         fields[fieldI]
101                     )
102                 );
103             }
104         }
105     }
109 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
111 template<class Type>
112 Foam::tmp<Foam::Field<Type> >
113 Foam::patchProbes::sample
115     const GeometricField<Type, fvPatchField, volMesh>& vField
116 ) const
118     const Type unsetVal(-VGREAT*pTraits<Type>::one);
120     tmp<Field<Type> > tValues
121     (
122         new Field<Type>(this->size(), unsetVal)
123     );
125     Field<Type>& values = tValues();
127     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
129     forAll(*this, probeI)
130     {
131         label faceI = elementList_[probeI];
133         if (faceI >= 0)
134         {
135             label patchI = patches.whichPatch(faceI);
136             label localFaceI = patches[patchI].whichFace(faceI);
137             values[probeI] = vField.boundaryField()[patchI][localFaceI];
138         }
139     }
141     Pstream::listCombineGather(values, isNotEqOp<Type>());
142     Pstream::listCombineScatter(values);
144     return tValues;
148 template<class Type>
149 Foam::tmp<Foam::Field<Type> >
150 Foam::patchProbes::sample(const word& fieldName) const
152     return sample
153     (
154         mesh_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
155         (
156             fieldName
157         )
158     );
162 // ************************************************************************* //