coordSetWriterTemplates.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 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
29 
30 template<class Type>
33 {
34  UPtrList<const Field<Type>> fieldPtrs(1);
35  fieldPtrs.set(0, &field);
36 
37  return fieldPtrs;
38 }
39 
40 
41 template<class Type>
44 {
45  UPtrList<const Field<Type>> fieldPtrs(fieldValues.size());
46  forAll(fieldValues, i)
47  {
48  fieldPtrs.set(i, &(fieldValues[i]));
49  }
50 
51  return fieldPtrs;
52 }
53 
54 
55 template<class Type>
57 (
58  Ostream& os,
59  const coordSet& coords,
60  const UList<Type>& values,
61  const char* sep
62 )
63 {
64  forAll(coords, pointi)
65  {
66  // Output coordinate (point or scalar) with separator
67  if (coords.hasVectorAxis())
68  {
69  const vector& p = coords.vectorCoord(pointi);
70  os << p.x() << sep << p.y() << sep << p.z();
71  }
72  else
73  {
74  os << coords.scalarCoord(pointi);
75  }
76 
77  // Output component values with separator
78  const auto& val = values[pointi];
79  for (direction d=0; d < pTraits<Type>::nComponents; ++d)
80  {
81  os << sep << component(val, d);
82  }
83  os << nl;
84  }
85 }
86 
87 
88 // ************************************************************************* //
rDeltaTY field()
uint8_t direction
Definition: direction.H:48
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
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:414
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
static UPtrList< const Field< Type > > repackageFields(const Field< Type > &field)
Repackage field into a UPtrList.
Holds list of sampling positions.
Definition: coordSet.H:49
Generic templated field type.
Definition: Field.H:62
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:100
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:99
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
static void writeTable(Ostream &os, const coordSet &coords, const UList< Type > &values, const char *sep)
Write coordinates and values.
volScalarField & p
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
scalar scalarCoord(const label index) const
Get coordinate of point according to axis specification.
Definition: coordSet.C:134
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Definition: UPtrList.H:361