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-2026 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
33 void Foam::patchProbes::sampleAndWrite(const VolField<Type>& vField)
34 {
35  Field<Type> values(sample(vField));
36 
37  if (Pstream::master())
38  {
39  unsigned int w = IOstream::defaultPrecision() + 7;
40  OFstream& probeStream = probeFilePtrs_[vField.name()];
41 
42  probeStream
43  << setw(w)
44  << vField.time().userTimeValue();
45 
46  forAll(values, probei)
47  {
48  probeStream << ' ' << setw(w) << values[probei];
49  }
50  probeStream << endl;
51  }
52 }
53 
54 
55 template<class Type>
56 void Foam::patchProbes::sampleAndWrite(const SurfaceField<Type>& sField)
57 {
58  Field<Type> values(sample(sField));
59 
60  if (Pstream::master())
61  {
62  unsigned int w = IOstream::defaultPrecision() + 7;
63  OFstream& probeStream = probeFilePtrs_[sField.name()];
64 
65  probeStream
66  << setw(w)
67  << sField.time().userTimeValue();
68 
69  forAll(values, probei)
70  {
71  probeStream << ' ' << setw(w) << values[probei];
72  }
73  probeStream << endl;
74  }
75 }
76 
77 
78 template<class Type>
79 void Foam::patchProbes::sampleAndWrite(const fieldGroup<Type>& fields)
80 {
81  forAll(fields, fieldi)
82  {
83  objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
84 
85  if
86  (
87  iter != objectRegistry::end()
88  && iter()->type() == VolField<Type>::typeName
89  )
90  {
91  sampleAndWrite
92  (
93  mesh_.lookupObject<VolField<Type>>
94  (
95  fields[fieldi]
96  )
97  );
98  }
99  }
100 }
101 
102 
103 template<class Type>
104 void Foam::patchProbes::sampleAndWriteSurfaceFields
105 (
106  const fieldGroup<Type>& fields
107 )
108 {
109  forAll(fields, fieldi)
110  {
111  objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
112 
113  if
114  (
115  iter != objectRegistry::end()
116  && iter()->type() == SurfaceField<Type>::typeName
117  )
118  {
119  sampleAndWrite
120  (
121  mesh_.lookupObject<SurfaceField<Type>>
122  (
123  fields[fieldi]
124  )
125  );
126  }
127  }
128 }
129 
130 
131 template<class Type>
133 Foam::patchProbes::sample(const VolField<Type>& vField) const
134 {
135  const Type unsetVal(-vGreat*pTraits<Type>::one);
136 
137  tmp<Field<Type>> tValues
138  (
139  new Field<Type>(locations_.size(), unsetVal)
140  );
141 
142  Field<Type>& values = tValues.ref();
143 
144  const polyBoundaryMesh& patches = mesh_.poly().boundary();
145 
146  forAll(locations_, probei)
147  {
148  label facei = faceList_[probei];
149 
150  if (facei >= 0)
151  {
152  label patchi = patches.whichPatch(facei);
153  label localFacei = patches[patchi].whichFace(facei);
154  values[probei] = vField.boundaryField()[patchi][localFacei];
155  }
156  }
157 
160 
161  return tValues;
162 }
163 
164 
165 template<class Type>
167 Foam::patchProbes::sample(const SurfaceField<Type>& sField) const
168 {
169  const Type unsetVal(-vGreat*pTraits<Type>::one);
170 
171  tmp<Field<Type>> tValues
172  (
173  new Field<Type>(locations_.size(), unsetVal)
174  );
175 
176  Field<Type>& values = tValues.ref();
177 
178  const polyBoundaryMesh& patches = mesh_.poly().boundary();
179 
180  forAll(locations_, probei)
181  {
182  label facei = faceList_[probei];
183 
184  if (facei >= 0)
185  {
186  label patchi = patches.whichPatch(facei);
187  label localFacei = patches[patchi].whichFace(facei);
188  values[probei] = sField.boundaryField()[patchi][localFacei];
189  }
190  }
191 
194 
195  return tValues;
196 }
197 
198 
199 template<class Type>
201 Foam::patchProbes::sample(const word& fieldName) const
202 {
203  return sample
204  (
205  mesh_.lookupObject<VolField<Type>>
206  (
207  fieldName
208  )
209  );
210 }
211 
212 
213 // ************************************************************************* //
Istream and Ostream manipulators taking arguments.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Pre-declare SubField and related Field type.
Definition: Field.H:83
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:473
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:134
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:197
A class for handling words, derived from string.
Definition: word.H:63
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:234
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:288
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
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