unitConversionTemplates.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) 2024 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 "unitConversion.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class T>
32 {
33  return standard() ? t : t*multiplier_;
34 }
35 
36 
37 template<class T>
39 {
40  return Pair<T>(toStandard(p.first(), p.second()));
41 }
42 
43 
44 template<class T>
46 {
47  List<T> result(l.size());
48  forAll(l, i)
49  {
50  result[i] = toStandard(l[i]);
51  }
52  return result;
53 }
54 
55 
56 template<class T>
59 {
60  return standard() ? tmp<Field<T>>(f) : f*multiplier_;
61 }
62 
63 
64 template<class T>
67 {
68  return standard() ? tf : tf*multiplier_;
69 }
70 
71 
72 template<class T>
74 {
75  if (!standard())
76  {
77  t *= multiplier_;
78  }
79 }
80 
81 
82 template<class T>
84 {
85  if (!standard())
86  {
87  makeStandard(p.first());
88  makeStandard(p.second());
89  }
90 }
91 
92 
93 template<class T>
95 {
96  if (!standard())
97  {
98  forAll(l, i)
99  {
100  makeStandard(l[i]);
101  }
102  }
103 }
104 
105 
106 template<class T>
108 {
109  return standard() ? t : t/multiplier_;
110 }
111 
112 
113 template<class T>
115 {
116  return Pair<T>(toUser(p.first()), toUser(p.second()));
117 }
118 
119 
120 template<class T>
122 {
123  List<T> result(l.size());
124  forAll(l, i)
125  {
126  result[i] = toUser(l[i]);
127  }
128  return result;
129 }
130 
131 
132 template<class T>
135 {
136  return standard() ? tmp<Field<T>>(f) : f/multiplier_;
137 }
138 
139 
140 template<class T>
143 {
144  return standard() ? tf : tf/multiplier_;
145 }
146 
147 
148 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
149 
150 template<class Type>
152 (
153  Ostream& os,
154  const unitConversion& defaultUnits,
155  const Type& t
156 )
157 {
158  return writeEntry(os, defaultUnits.toUser(t));
159 }
160 
161 
162 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An ordered pair of two objects of type <Type> with first() and second() elements.
Definition: Pair.H:66
A class for managing temporary objects.
Definition: tmp.H:55
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
T toUser(const T &) const
Convert a value to user units.
void makeStandard(T &) const
Convert a value to standard units.
bool standard() const
Return whether this unit is standard. I.e., is its multiplier one?
T toStandard(const T &) const
Convert a value to standard units.
const tensorField & tf
void T(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
labelList f(nPoints)
volScalarField & p