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 #include "transformField.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const word& fieldName,
36  const tmp<Field<Type>>& tfield
37 ) const
38 {
39  if (verbose_)
40  {
41  Info<< "Writing field " << fieldName;
42  }
43 
44  tmp<Field<Type>> tadjusted;
45 
46  // Output scaling for the variable, but not for integer types
47  // which are typically ids etc.
48  if (!std::is_integral<Type>::value)
49  {
50  scalar value;
51 
52  // Remove *uniform* reference level
53  if
54  (
55  fieldLevel_.readIfPresent(fieldName, value, keyType::REGEX)
56  && !equal(value, 0)
57  )
58  {
59  // Could also detect brackets (...) and read accordingly
60  // or automatically scale by 1/sqrt(nComponents) instead ...
61 
62  Type refLevel;
63  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt)
64  {
65  setComponent(refLevel, cmpt) = value;
66  }
67 
68  if (verbose_)
69  {
70  Info<< " [level " << refLevel << ']';
71  }
72 
73  if (!tadjusted)
74  {
75  // Steal or clone
76  tadjusted.reset(tfield.ptr());
77  }
78 
79  // Remove offset level
80  tadjusted.ref() -= refLevel;
81  }
82 
83  // Apply scaling
84  if
85  (
86  fieldScale_.readIfPresent(fieldName, value, keyType::REGEX)
87  && !equal(value, 1)
88  )
89  {
90  if (verbose_)
91  {
92  Info<< " [scaling " << value << ']';
93  }
94 
95  if (!tadjusted)
96  {
97  // Steal or clone
98  tadjusted.reset(tfield.ptr());
99  }
100 
101  // Apply scaling
102  tadjusted.ref() *= value;
103  }
104 
105  // Rotate fields (vector and non-spherical tensors)
106  if
107  (
110  && !geometryTransform_.R().is_identity()
111  )
112  {
113  if (!tadjusted)
114  {
115  // Steal or clone
116  tadjusted.reset(tfield.ptr());
117  }
118 
120  (
121  tadjusted.ref(),
123  tadjusted()
124  );
125  }
126  }
128  return (tadjusted ? tadjusted : tfield);
129 }
130 
131 
132 template<class Type>
135 {
136  UPtrList<const Field<Type>> fieldPtrs(1);
137  fieldPtrs.set(0, &field);
139  return fieldPtrs;
140 }
141 
142 
143 template<class Type>
146 {
147  UPtrList<const Field<Type>> fieldPtrs(fieldValues.size());
148  forAll(fieldValues, i)
149  {
150  fieldPtrs.set(i, &(fieldValues[i]));
151  }
153  return fieldPtrs;
154 }
155 
156 
157 template<class Type>
159 (
160  Ostream& os,
161  const coordSet& coords,
162  const UList<Type>& values,
163  const char* sep
164 )
165 {
166  forAll(coords, pointi)
167  {
168  // Output coordinate (point or scalar) with separator
169  if (coords.hasVectorAxis())
170  {
171  const vector& p = coords.vectorCoord(pointi);
172  os << p.x() << sep << p.y() << sep << p.z();
173  }
174  else
175  {
176  os << coords.scalarCoord(pointi);
177  }
178 
179  // Output component values with separator
180  const auto& val = values[pointi];
182  {
183  os << sep << component(val, d);
184  }
185  os << nl;
186  }
187 }
188 
189 
190 // ************************************************************************* //
rDeltaTY field()
uint8_t direction
Definition: direction.H:46
bool equal(const T &a, const T &b)
Compare two values for equality.
Definition: label.H:164
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:235
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
const vector & vectorCoord(const label index) const
Get point according to axis="xyz" specification.
Definition: coordSet.C:181
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
virtual const tensor & R() const
Return const reference to the rotation tensor.
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
Spatial transformation functions for primitive fields.
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 class for handling words, derived from Foam::string.
Definition: word.H:63
dictionary fieldScale_
Field scaling (on output)
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
dictionary fieldLevel_
Field level to remove (on output)
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...
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
OBJstream os(runTime.globalPath()/outputName)
static void writeTable(Ostream &os, const coordSet &coords, const UList< Type > &values, const char *sep)
Write coordinates and values.
coordSystem::cartesian geometryTransform_
Local coordinate system transformation.
bool verbose_
Additional output verbosity.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool valid() const
Same as good() - 2023-07.
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
label & setComponent(label &val, const direction) noexcept
Non-const access to integer-type (has no components)
Definition: label.H:144
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
tmp< Field< Type > > adjustFieldTemplate(const word &fieldName, const tmp< Field< Type >> &tfield) const
Regular expression.
Definition: keyType.H:83
void reset(tmp< T > &&other) noexcept
Clear existing and transfer ownership.
Definition: tmpI.H:338
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:366