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 (
73 )
74 :
76  dimensioned<Type>(rhs)
77 {}
78 
79 
80 template<class Type>
82 (
83  const IOobject& io
84 )
85 :
86  regIOobject(io),
88 {
89  // For if MUST_READ_IF_MODIFIED
90  addWatch();
91 
92  // Read unless NO_READ
93  readHeaderOk(IOstreamOption::BINARY, typeName);
94 }
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
99 template<class Type>
101 {
102  dictionary dict(is);
103 
104  // The dimensions
105  scalar multiplier(1);
106  this->dimensions().read
107  (
108  dict.lookup("dimensions", keyType::LITERAL),
109  multiplier
110  );
111 
112  // The value
113  dict.readEntry("value", this->value(), keyType::LITERAL);
114  this->value() *= multiplier;
115 
116  return is.good();
117 }
118 
119 
120 template<class Type>
122 {
123  // The dimensions
124  scalar multiplier(1);
125  os.writeKeyword("dimensions");
126  this->dimensions().write(os, multiplier) << token::END_STATEMENT << nl;
127 
128  // The value
129  os.writeEntry("value", this->value()/multiplier) << nl;
130 
131  return os.good();
132 }
133 
134 
135 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
136 
137 template<class Type>
139 (
141 )
142 {
144 }
145 
146 
147 template<class Type>
149 (
150  const dimensioned<Type>& rhs
151 )
152 {
154 }
155 
156 
157 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
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:49
Generic dimensioned Type class.
const dimensionSet dimless
Dimensionless.
bool writeData(Ostream &) const
WriteData function 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
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
OBJstream os(runTime.globalPath()/outputName)
virtual bool readData(Istream &)
ReadData function 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:274
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:69
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
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:157