UniformDimensionedField.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) 2011-2026 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 
27 
28 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
29 
30 template<class Type>
32 {
33  if
34  (
35  ro == IOobject::MUST_READ
36  || ro == IOobject::MUST_READ_IF_MODIFIED
37  || (ro == IOobject::READ_IF_PRESENT && headerOk())
38  )
39  {
40  dictionary dict(readStream(type()));
41 
42  this->dimensions().read(dict.lookup("dimensions"));
43 
44  this->value() = dict.lookup<Type>("value", this->dimensions());
45  }
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 template<class Type>
53 (
54  const IOobject& io,
55  const bool read
56 )
57 :
58  regIOobject(io),
61 {
62  if (read) this->read(IOobject::MUST_READ);
63 }
64 
65 
66 template<class Type>
68 (
69  const IOobject& io,
70  const dimensioned<Type>& dt,
71  const bool read
72 )
73 :
74  regIOobject(io),
75  dimensioned<Type>(dt),
77 {
78  if (read) this->read(io.readOpt());
79 }
80 
81 
82 template<class Type>
84 (
86 )
87 :
88  regIOobject(udt),
89  dimensioned<Type>(udt),
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
95 
96 template<class Type>
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
103 template<class Type>
105 {
106  this->storeOldTimes();
107  return dimensioned<Type>::value();
108 }
109 
110 
111 template<class Type>
113 {
115 }
116 
117 
118 template<class Type>
120 (
122 )
123 {
125 }
126 
127 
128 template<class Type>
130 {
131  writeKeyword(os, "dimensions");
132  this->dimensions().write(os) << token::END_STATEMENT << nl;
133  writeEntry(os, "value", this->value());
134  os << nl;
135 
136  return (os.good());
137 }
138 
139 
140 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
141 
142 template<class Type>
144 (
146 )
147 {
149 }
150 
151 
152 template<class Type>
154 (
156 )
157 {
159 }
160 
161 
162 template<class Type>
164 (
165  const dimensioned<Type>& rhs
166 )
167 {
169 }
170 
171 
172 template<class Type>
174 {
175  return this->value();
176 }
177 
178 
179 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
readOption
Enumeration defining the read options.
Definition: IOobject.H:117
readOption readOpt() const
Definition: IOobject.H:357
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Class to add into field types to provide old-time storage and retrieval.
Definition: OldTimeField.H:115
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Dimensioned<Type> registered with the database as a registered IOobject which has the functionality o...
bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
void reset(const UniformDimensionedField< Type > &)
Reset the field values to the given field.
UniformDimensionedField(const IOobject &, const bool read=true)
Construct from IO object.
Type & value()
Return a reference to the value.
virtual ~UniformDimensionedField()
Destructor.
const Type & operator[](const label) const
Access by index.
virtual bool read()
Prevent warning due to read method.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Generic dimensioned Type class.
const Type & value() const
Return const reference to value.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
@ END_STATEMENT
Definition: token.H:109
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
const dimensionSet dimless
const dimensionSet time
static const zero Zero
Definition: zero.H:97
bool read(const char *, int32_t &)
Definition: int32IO.C:85
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
Definition: keyType.C:155
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
label timeIndex
Definition: getTimeIndex.H:4
dictionary dict