UniformDimensionedField.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const IOobject& io,
37  const dimensioned<Type>& dt
38 )
39 :
40  regIOobject(io),
41  dimensioned<Type>(dt)
42 {
43  if (dimensioned<Type>::name().empty())
44  {
46  }
47 
48  // Read value
49  readHeaderOk(IOstreamOption::BINARY, typeName);
50 }
51 
52 
53 template<class Type>
55 (
56  const IOobject& io,
57  const dimensionSet& dims,
58  const Type& val
59 )
60 :
61  regIOobject(io),
62  dimensioned<Type>(regIOobject::name(), dims, val)
63 {
64  // Read value
65  readHeaderOk(IOstreamOption::BINARY, typeName);
66 }
67 
68 
69 template<class Type>
71 (
72  const IOobject& io,
73  const Type& val,
74  const dimensionSet& dims
75 )
76 :
77  regIOobject(io),
78  dimensioned<Type>(regIOobject::name(), dims, val)
79 {
80  // Read value
81  readHeaderOk(IOstreamOption::BINARY, typeName);
82 }
83 
84 
85 template<class Type>
87 (
89 )
90 :
92  dimensioned<Type>(rhs)
93 {}
94 
95 
96 template<class Type>
98 (
99  const IOobject& io
100 )
101 :
102  regIOobject(io),
104 {
105  // For if MUST_READ_IF_MODIFIED
106  addWatch();
107 
108  // Read unless NO_READ
109  readHeaderOk(IOstreamOption::BINARY, typeName);
110 }
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
115 template<class Type>
117 {
118  dictionary dict(is);
119 
120  // The dimensions
121  scalar multiplier(1);
122  this->dimensions().read
123  (
124  dict.lookup("dimensions", keyType::LITERAL),
125  multiplier
126  );
127 
128  // The value
129  dict.readEntry("value", this->value(), keyType::LITERAL);
130  this->value() *= multiplier;
131 
132  return is.good();
133 }
134 
135 
136 template<class Type>
138 {
139  // The dimensions
140  scalar multiplier(1);
141  os.writeKeyword("dimensions");
142  this->dimensions().write(os, multiplier);
143  os.endEntry();
144 
145  // The value
146  os.writeEntry("value", this->value()/multiplier) << nl;
147 
148  return os.good();
149 }
150 
151 
152 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
153 
154 template<class Type>
156 (
158 )
159 {
161 }
162 
163 
164 template<class Type>
166 (
167  const dimensioned<Type>& rhs
168 )
169 {
171 }
172 
173 
174 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Generic dimensioned Type class.
const dimensionSet dimless
Dimensionless.
bool writeData(Ostream &) const
The writeData method required for regIOobject write operation.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
virtual bool readData(Istream &)
The readData method required for regIOobject read operation.
Dimensioned<Type> registered with the database as a registered IOobject which has the functionality o...
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:281
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
UniformDimensionedField(const IOobject &io, const dimensioned< Type > &dt)
Construct from components. Either reads or uses supplied value.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127