patchProbesTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
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 "volFields.H"
28 #include "IOmanip.H"
29 
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
34 void Foam::patchProbes::sampleAndWrite
35 (
36  const VolField<Type>& 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
47  << setw(w)
48  << vField.time().userTimeValue();
49 
50  forAll(values, probei)
51  {
52  probeStream << ' ' << setw(w) << values[probei];
53  }
54  probeStream << endl;
55  }
56 }
57 
58 
59 template<class Type>
60 void Foam::patchProbes::sampleAndWrite
61 (
62  const SurfaceField<Type>& sField
63 )
64 {
65  Field<Type> values(sample(sField));
66 
67  if (Pstream::master())
68  {
69  unsigned int w = IOstream::defaultPrecision() + 7;
70  OFstream& probeStream = *probeFilePtrs_[sField.name()];
71 
72  probeStream
73  << setw(w)
74  << sField.time().userTimeValue();
75 
76  forAll(values, probei)
77  {
78  probeStream << ' ' << setw(w) << values[probei];
79  }
80  probeStream << endl;
81  }
82 }
83 
84 
85 template<class Type>
86 void Foam::patchProbes::sampleAndWrite
87 (
88  const fieldGroup<Type>& fields
89 )
90 {
91  forAll(fields, fieldi)
92  {
93  objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
94 
95  if
96  (
97  iter != objectRegistry::end()
98  && iter()->type()
100  )
101  {
102  sampleAndWrite
103  (
104  mesh_.lookupObject
105  <VolField<Type>>
106  (
107  fields[fieldi]
108  )
109  );
110  }
111  }
112 }
113 
114 
115 template<class Type>
116 void Foam::patchProbes::sampleAndWriteSurfaceFields
117 (
118  const fieldGroup<Type>& fields
119 )
120 {
121  forAll(fields, fieldi)
122  {
123  objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
124 
125  if
126  (
127  iter != objectRegistry::end()
128  && iter()->type()
130  )
131  {
132  sampleAndWrite
133  (
134  mesh_.lookupObject
135  <SurfaceField<Type>>
136  (
137  fields[fieldi]
138  )
139  );
140  }
141  }
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
147 template<class Type>
149 Foam::patchProbes::sample
150 (
151  const VolField<Type>& vField
152 ) const
153 {
154  const Type unsetVal(-vGreat*pTraits<Type>::one);
155 
156  tmp<Field<Type>> tValues
157  (
158  new Field<Type>(this->size(), unsetVal)
159  );
160 
161  Field<Type>& values = tValues.ref();
162 
163  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
164 
165  forAll(*this, probei)
166  {
167  label facei = elementList_[probei];
168 
169  if (facei >= 0)
170  {
171  label patchi = patches.whichPatch(facei);
172  label localFacei = patches[patchi].whichFace(facei);
173  values[probei] = vField.boundaryField()[patchi][localFacei];
174  }
175  }
176 
179 
180  return tValues;
181 }
182 
183 
184 template<class Type>
186 Foam::patchProbes::sample(const word& fieldName) const
187 {
188  return sample
189  (
190  mesh_.lookupObject<VolField<Type>>
191  (
192  fieldName
193  )
194  );
195 }
196 
197 
198 template<class Type>
200 Foam::patchProbes::sample
201 (
202  const SurfaceField<Type>& sField
203 ) const
204 {
205  const Type unsetVal(-vGreat*pTraits<Type>::one);
206 
207  tmp<Field<Type>> tValues
208  (
209  new Field<Type>(this->size(), unsetVal)
210  );
211 
212  Field<Type>& values = tValues.ref();
213 
214  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
215 
216  forAll(*this, probei)
217  {
218  label facei = elementList_[probei];
219 
220  if (facei >= 0)
221  {
222  label patchi = patches.whichPatch(facei);
223  label localFacei = patches[patchi].whichFace(facei);
224  values[probei] = sField.boundaryField()[patchi][localFacei];
225  }
226  }
227 
230 
231  return tValues;
232 }
233 // ************************************************************************* //
Istream and Ostream manipulators taking arguments.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Pre-declare SubField and related Field type.
Definition: Field.H:82
static const char *const typeName
Definition: Field.H:105
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
friend class const_iterator
Declare friendship with the const_iterator.
Definition: HashTable.H:197
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:458
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Traits class for primitives.
Definition: pTraits.H:53
Foam::polyBoundaryMesh.
HashPtrTable< OFstream > probeFilePtrs_
Current open files.
Definition: probes.H:132
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
A class for handling words, derived from string.
Definition: word.H:62
label patchi
const fvPatchList & patches
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:230
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112