FreeFOAM The Cross-Platform CFD Toolkit
probesTemplates.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) 1991-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 "probes.H"
27 #include <finiteVolume/volFields.H>
28 #include <OpenFOAM/IOmanip.H>
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 //- comparison operator for probes class
36 template<class T>
37 class isNotEqOp
38 {
39 public:
40 
41  void operator()(T& x, const T& y) const
42  {
43  const T unsetVal(-VGREAT*pTraits<T>::one);
44 
45  if (x != unsetVal)
46  {
47  // Keep x.
48 
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  }
58 };
59 
60 }
61 
62 
63 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
64 
65 template<class Type>
66 Foam::label Foam::probes::countFields
67 (
68  fieldGroup<Type>& fieldList,
69  const wordList& fieldTypes
70 ) const
71 {
72  fieldList.setSize(fieldNames_.size());
73  label nFields = 0;
74 
75  forAll(fieldNames_, fieldI)
76  {
77  if
78  (
79  fieldTypes[fieldI]
81  )
82  {
83  fieldList[nFields] = fieldNames_[fieldI];
84  nFields++;
85  }
86  }
87 
88  fieldList.setSize(nFields);
89 
90  return nFields;
91 }
92 
93 
94 template<class Type>
95 void Foam::probes::sampleAndWrite
96 (
98 )
99 {
100  Field<Type> values = sample(vField);
101 
102  if (Pstream::master())
103  {
104  unsigned int w = IOstream::defaultPrecision() + 7;
105  OFstream& probeStream = *probeFilePtrs_[vField.name()];
106 
107  probeStream << setw(w) << vField.time().value();
108 
109  forAll(values, probeI)
110  {
111  probeStream << ' ' << setw(w) << values[probeI];
112  }
113  probeStream << endl;
114  }
115 }
116 
117 
118 template <class Type>
119 void Foam::probes::sampleAndWrite
120 (
121  const fieldGroup<Type>& fields
122 )
123 {
124  forAll(fields, fieldI)
125  {
126  if (loadFromFiles_)
127  {
128  sampleAndWrite
129  (
130  GeometricField<Type, fvPatchField, volMesh>
131  (
132  IOobject
133  (
134  fields[fieldI],
135  obr_.time().timeName(),
136  refCast<const polyMesh>(obr_),
139  false
140  ),
141  refCast<const fvMesh>(obr_)
142  )
143  );
144  }
145  else
146  {
147  objectRegistry::const_iterator iter = obr_.find(fields[fieldI]);
148 
149  if
150  (
151  iter != obr_.end()
152  && iter()->type()
154  )
155  {
156  sampleAndWrite
157  (
158  obr_.lookupObject
159  <GeometricField<Type, fvPatchField, volMesh> >
160  (
161  fields[fieldI]
162  )
163  );
164  }
165  }
166  }
167 }
168 
169 
170 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
171 
172 template<class Type>
175 (
177 ) const
178 {
179  const Type unsetVal(-VGREAT*pTraits<Type>::one);
180 
181  tmp<Field<Type> > tValues
182  (
183  new Field<Type>(probeLocations_.size(), unsetVal)
184  );
185 
186  Field<Type>& values = tValues();
187 
188  forAll(probeLocations_, probeI)
189  {
190  if (elementList_[probeI] >= 0)
191  {
192  values[probeI] = vField[elementList_[probeI]];
193  }
194  }
195 
198 
199  return tValues;
200 }
201 
202 
203 template<class Type>
205 Foam::probes::sample(const word& fieldName) const
206 {
207  return sample
208  (
210  (
211  fieldName
212  )
213  );
214 }
215 
216 
217 // ************************ vim: set sw=4 sts=4 et: ************************ //