coordSetWriterBuffers.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "coordSetWriter.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
33 (
34  Ostream& os,
35  const UList<word>& values,
36  const char* sep
37 )
38 {
39  if (!values.empty())
40  {
41  forAll(values, coli)
42  {
43  if (coli && sep) os << sep;
44  os << values[coli];
45  }
46  os << nl;
47  }
48 }
49 
50 
52 (
53  Ostream& os,
54  const UList<scalar>& values,
55  const char* sep
56 )
57 {
58  if (!values.empty())
59  {
60  forAll(values, coli)
61  {
62  if (coli && sep) os << sep;
63  os << values[coli];
64  }
65  os << nl;
66  }
67 }
68 
69 
71 {
72  #undef doLocalCode
73  #define doLocalCode(Type) \
74  { \
75  Type##Names_.clear(); \
76  Type##Fields_.clear(); \
77  }
78 
79  doLocalCode(label);
80  doLocalCode(scalar);
85  #undef doLocalCode
86 }
87 
88 
89 Foam::label Foam::coordSetWriter::nDataColumns() const
90 {
91  label ncol = 0;
92 
93  #undef doLocalCode
94  #define doLocalCode(Type) \
95  ncol += (Type##Fields_.size() * pTraits<Type>::nComponents);
96 
97  doLocalCode(label);
98  doLocalCode(scalar);
103  #undef doLocalCode
104 
105  return ncol;
106 }
107 
108 
110 (
111  DynamicList<scalar>& buf,
112  const coordSet& coords,
113  const label pointi
114 ) const
115 {
116  buf.clear();
117 
118  if (coords.hasVectorAxis())
119  {
120  const vector& p = coords.vectorCoord(pointi);
121  buf.append(p.x());
122  buf.append(p.y());
123  buf.append(p.z());
124  }
125  else
126  {
127  buf.append(coords.scalarCoord(pointi));
128  }
129 
130  do
131  {
132  #undef doLocalCode
133  #define doLocalCode(Type) \
134  \
135  for (const auto& fld : Type##Fields_) \
136  { \
137  const auto& val = fld[pointi]; \
138  for (direction d=0; d < pTraits<Type>::nComponents; ++d) \
139  { \
140  buf.append(component(val, d)); \
141  } \
142  }
143 
144  doLocalCode(label);
145  doLocalCode(scalar);
150  #undef doLocalCode
151  }
152  while (false);
153 }
154 
155 
157 {
158  return false;
159 }
160 
161 
163 (
164  Ostream& os,
165  const coordSet& coords,
166  const char* sep
167 ) const
168 {
169  const label npts = coords.size();
170  const label ncomp = nDataColumns();
171 
172  DynamicList<scalar> compCols(3 + ncomp);
173 
174  for (label pointi = 0; pointi < npts; ++pointi)
175  {
176  getBufferLine(compCols, coords, pointi);
177  writeLine(os, compCols, sep);
178  }
179 }
180 
181 
182 // * * * * * * * * * * * * * * * * * Controls * * * * * * * * * * * * * * * //
183 
185 {
186  return buffering_;
187 }
188 
189 
190 // disabled
191 bool Foam::coordSetWriter::buffering(const bool)
192 {
193  return buffering_;
194 }
195 
196 
197 // ************************************************************************* //
virtual bool writeBuffered()
Write buffered data.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
static void writeLine(Ostream &, const UList< word > &, const char *sep)
Write line contents (eg, buffered)
label nDataColumns() const
The number of buffer data columns, after splitting into components.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void writeBufferContents(Ostream &os, const coordSet &coords, const char *sep) const
Write buffered data.
virtual bool buffering() const
True if the format uses internal buffering (eg, column output)
const vector & vectorCoord(const label index) const
Get point according to axis="xyz" specification.
Definition: coordSet.C:181
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
bool hasVectorAxis() const noexcept
True if axis specification is a vector.
Definition: coordSet.C:128
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Holds list of sampling positions.
Definition: coordSet.H:49
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:55
void clearBuffers()
Clear out buffering.
Vector< scalar > vector
Definition: vector.H:57
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicList.H:584
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:405
#define doLocalCode(Type)
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
volScalarField & p
Tensor of scalars, i.e. Tensor<scalar>.
void getBufferLine(DynamicList< scalar > &buf, const coordSet &coords, const label pointi) const
Get buffered data line (components)
scalar scalarCoord(const label index) const
Get coordinate of point according to axis specification.
Definition: coordSet.C:134