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  const IOobject& io,
34  const dimensionSet& dims,
35  const bool
36 )
37 :
38  regIOobject(io),
39  dimensioned<Type>(regIOobject::name(), dims, Zero),
41 {}
42 
43 
44 template<class Type>
46 (
47  const IOobject& io,
48  const dimensioned<Type>& defaultDt,
49  const bool
50 )
51 :
52  regIOobject(io),
53  dimensioned<Type>(defaultDt),
55 {}
56 
57 
58 template<class Type>
60 (
61  const IOobject::readOption& ro,
62  const dimensionSet& dims
63 )
64 {
65  if
66  (
69  || (ro == IOobject::READ_IF_PRESENT && headerOk())
70  )
71  {
72  const dictionary dict(readStream(type()));
73 
74  this->dimensions().read(dict.lookup("dimensions"));
75  this->value() = dict.lookup<Type>("value", this->dimensions());
76 
77  if (this->dimensions() != dims)
78  {
80  << "Inconsistent dimensions specified for " << this->name()
81  << " " << this->dimensions()
82  << ", required dimensions are " << dims
83  << exit(FatalIOError);
84  }
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
91 template<class Type>
93 (
94  const IOobject& io
95 )
96 :
97  UniformDimensionedField(io, dimensions::invalid, false)
98 {
99  const dictionary dict(readStream(type()));
100  this->dimensions().read(dict.lookup("dimensions"));
101  this->value() = dict.lookup<Type>("value", this->dimensions());
102 }
103 
104 
105 template<class Type>
107 (
108  const IOobject& io,
109  const dimensionSet& dims
110 )
111 :
112  UniformDimensionedField(io, dims, false)
113 {
114  this->read(IOobject::MUST_READ, dims);
115 }
116 
117 
118 template<class Type>
120 (
121  const IOobject& io,
122  const dimensioned<Type>& defaultDt
123 )
124 :
125  UniformDimensionedField(io, defaultDt, false)
126 {
127  this->read(io.readOpt(), defaultDt.dimensions());
128 }
129 
130 
131 template<class Type>
133 (
135 )
136 :
138  dimensioned<Type>(udt),
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
144 
145 template<class Type>
147 {}
148 
149 
150 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
151 
152 template<class Type>
154 {
155  this->storeOldTimes();
157 }
158 
159 
160 template<class Type>
162 {
164 }
165 
166 
167 template<class Type>
169 (
171 )
172 {
174 }
175 
176 
177 template<class Type>
179 {
180  writeKeyword(os, "dimensions");
181  this->dimensions().write(os) << token::END_STATEMENT << nl;
182  writeEntry(os, "value", this->value());
183  os << nl;
184 
185  return (os.good());
186 }
187 
188 
189 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
190 
191 template<class Type>
193 (
195 )
196 {
198 }
199 
200 
201 template<class Type>
203 (
205 )
206 {
208 }
209 
210 
211 template<class Type>
213 (
214  const dimensioned<Type>& rhs
215 )
216 {
218 }
219 
220 
221 template<class Type>
223 {
224  return this->value();
225 }
226 
227 
228 // ************************************************************************* //
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
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:119
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...
UniformDimensionedField(const IOobject &, const dimensionSet &dims, const bool)
Construct from IOobject and dimensions without reading.
bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
void reset(const UniformDimensionedField< Type > &)
Reset the field values to the given field.
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
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
Dimension set for the base types.
Definition: dimensionSet.H:125
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
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
const dimensionSet time
const dimensionSet invalid
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
IOerror FatalIOError
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