Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
33template<class Type>
35(
36 const IOobject& io,
37 const dimensioned<Type>& dt
38)
39:
41 dimensioned<Type>(dt)
42{
43 if (dimensioned<Type>::name().empty())
44 {
46 }
48 // Read value
50}
51
52
53template<class Type>
55(
56 const IOobject& io,
57 const dimensionSet& dims,
58 const Type& val
59)
60:
62 dimensioned<Type>(regIOobject::name(), dims, val)
64 // Read value
66}
67
68
69template<class Type>
71(
72 const IOobject& io,
73 const Type& val,
74 const dimensionSet& dims
75)
76:
78 dimensioned<Type>(regIOobject::name(), dims, val)
87(
89)
92 dimensioned<Type>(rhs)
93{}
94
95
96template<class Type>
98(
99 const IOobject& io
100)
101:
104{
105 // For if MUST_READ_IF_MODIFIED
106 addWatch();
107
108 // Read unless NO_READ
110}
111
112
113// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114
115template<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
136template<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
154template<class Type>
156(
159{
161}
162
163
164template<class Type>
166(
168)
169{
171}
172
173
174// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
bool good() const noexcept
True if next operation might succeed.
Definition IOstream.H:281
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Dimensioned<Type> registered with the database as a registered IOobject which has the functionality o...
virtual const word & name() const
Use name from dimensioned<Type>, not from regIOobject.
bool writeData(Ostream &) const
The writeData method required for regIOobject write operation.
UniformDimensionedField(const IOobject &io, const dimensioned< Type > &dt)
Construct from components. Either reads or uses supplied value.
virtual bool readData(Istream &)
The readData method required for regIOobject read operation.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Generic dimensioned Type class.
dimensioned()
A dimensionless Zero, named "0".
const dimensionSet & dimensions() const noexcept
Return const reference to dimensions.
const word & name() const noexcept
Return const reference to name.
const Type & value() const noexcept
Return const reference to value.
@ LITERAL
String literal.
Definition keyType.H:82
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED).
bool readHeaderOk(const IOstreamOption::streamFormat fmt, const word &typeName)
Helper: check readOpt flags and read if necessary.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
OBJstream os(runTime.globalPath()/outputName)
const auto & io
Namespace for OpenFOAM.
const dimensionSet dimless
Dimensionless.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict