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  List<T> result(l.size());
41  forAll(l, i)
42  {
43  result[i] = toStandard(l[i]);
44  }
45  return result;
46 }
47 
48 
49 template<class T>
52 {
53  return standard() ? tmp<Field<T>>(f) : f*multiplier_;
54 }
55 
56 
57 template<class T>
60 {
61  return standard() ? tf : tf*multiplier_;
62 }
63 
64 
65 template<class T>
67 {
68  if (!standard())
69  {
70  t *= multiplier_;
71  }
72 }
73 
74 
75 template<class T>
77 {
78  if (!standard())
79  {
80  forAll(l, i)
81  {
82  makeStandard(l[i]);
83  }
84  }
85 }
86 
87 
88 template<class T>
90 {
91  return standard() ? t : t/multiplier_;
92 }
93 
94 
95 template<class T>
97 {
98  List<T> result(l.size());
99  forAll(l, i)
100  {
101  result[i] = toUser(l[i]);
102  }
103  return result;
104 }
105 
106 
107 template<class T>
110 {
111  return standard() ? tmp<Field<T>>(f) : f/multiplier_;
112 }
113 
114 
115 template<class T>
118 {
119  return standard() ? tf : tf/multiplier_;
120 }
121 
122 
123 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
124 
125 template<class Type>
127 (
128  Ostream& os,
129  const unitConversion& defaultUnits,
130  const Type& t
131 )
132 {
133  return writeEntry(os, defaultUnits.toUser(t));
134 }
135 
136 
137 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
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 writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
labelList f(nPoints)