FreeFOAM The Cross-Platform CFD Toolkit
patchProbesTemplates.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "patchProbes.H"
27 #include <finiteVolume/volFields.H>
28 #include <OpenFOAM/IOmanip.H>
29 
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
34 void Foam::patchProbes::sampleAndWrite
35 (
36  const GeometricField<Type, fvPatchField, volMesh>& vField
37 )
38 {
39  Field<Type> values = sample(vField);
40 
41  if (Pstream::master())
42  {
43  unsigned int w = IOstream::defaultPrecision() + 7;
44  OFstream& probeStream = *probeFilePtrs_[vField.name()];
45 
46  probeStream << setw(w) << vField.time().value();
47 
48  forAll(values, probeI)
49  {
50  probeStream << ' ' << setw(w) << values[probeI];
51  }
52  probeStream << endl;
53  }
54 }
55 
56 
57 template <class Type>
58 void Foam::patchProbes::sampleAndWrite
59 (
60  const fieldGroup<Type>& fields
61 )
62 {
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  obr_.time().timeName(),
75  refCast<const polyMesh>(obr_),
78  false
79  ),
80  refCast<const fvMesh>(obr_)
81  )
82  );
83  }
84  else
85  {
86  objectRegistry::const_iterator iter = obr_.find(fields[fieldI]);
87 
88  if
89  (
90  iter != obr_.end()
91  && iter()->type()
93  )
94  {
95  sampleAndWrite
96  (
97  obr_.lookupObject
98  <GeometricField<Type, fvPatchField, volMesh> >
99  (
100  fields[fieldI]
101  )
102  );
103  }
104  }
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
111 template<class Type>
113 Foam::patchProbes::sample
114 (
115  const GeometricField<Type, fvPatchField, volMesh>& vField
116 ) const
117 {
118  const Type unsetVal(-VGREAT*pTraits<Type>::one);
119 
120  tmp<Field<Type> > tValues
121  (
122  new Field<Type>(probeLocations_.size(), unsetVal)
123  );
124 
125  Field<Type>& values = tValues();
126 
127  const polyBoundaryMesh& patches = vField.mesh().boundaryMesh();
128 
129  forAll(probeLocations_, probeI)
130  {
131  label faceI = elementList_[probeI];
132 
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  }
140 
141  Pstream::listCombineGather(values, isNotEqOp<Type>());
143 
144  return tValues;
145 }
146 
147 
148 template<class Type>
150 Foam::patchProbes::sample(const word& fieldName) const
151 {
152  return sample
153  (
154  obr_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
155  (
156  fieldName
157  )
158  );
159 }
160 
161 
162 // ************************ vim: set sw=4 sts=4 et: ************************ //