DimensionedFieldIO.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) 2017-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 #include "IOstreams.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class Type, class GeoMesh>
36 (
37  const dictionary& fieldDict,
38  const word& fieldDictEntry
39 )
40 {
41  dimensions_.readEntry("dimensions", fieldDict);
42 
43  // Note: oriented state may have already been set on construction
44  // - if so - do not reset by re-reading
45  // - required for backwards compatibility in case of restarting from
46  // an old run where the oriented state may not have been set
47  if (oriented_.oriented() != orientedType::ORIENTED)
48  {
49  oriented_.read(fieldDict);
50  }
51 
52  Field<Type> f(fieldDictEntry, fieldDict, GeoMesh::size(mesh_));
53  this->transfer(f);
54 }
55 
56 
57 template<class Type, class GeoMesh>
59 (
60  const word& fieldDictEntry
61 )
62 {
63  if (this->isReadRequired() || (this->isReadOptional() && this->headerOk()))
64  {
65  readField(dictionary(readStream(typeName)), fieldDictEntry);
66  }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
72 template<class Type, class GeoMesh>
74 (
75  const IOobject& io,
76  const Mesh& mesh,
77  const word& fieldDictEntry
78 )
79 :
80  regIOobject(io),
81  Field<Type>(),
82  mesh_(mesh),
83  dimensions_(dimless),
84  oriented_()
85 {
86  readField(dictionary(readStream(typeName)), fieldDictEntry);
87 }
88 
89 
90 template<class Type, class GeoMesh>
92 (
93  const IOobject& io,
94  const Mesh& mesh,
95  const dictionary& fieldDict,
96  const word& fieldDictEntry
97 )
98 :
99  regIOobject(io),
100  Field<Type>(),
101  mesh_(mesh),
102  dimensions_(dimless),
103  oriented_()
104 {
105  readField(fieldDict, fieldDictEntry);
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
111 template<class Type, class GeoMesh>
113 (
114  Ostream& os,
115  const word& fieldDictEntry
116 ) const
117 {
118  os.writeEntry("dimensions", dimensions());
119  os << nl;
120 
121  if (oriented_.writeEntry(os))
122  {
123  os << nl;
124  }
125 
126  Field<Type>::writeEntry(fieldDictEntry, os);
128  os.check(FUNCTION_NAME);
129  return os.good();
130 }
131 
132 
133 template<class Type, class GeoMesh>
135 {
136  return writeData(os, "value");
137 }
138 
139 
140 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
141 
142 template<class Type, class GeoMesh>
143 Foam::Ostream& Foam::operator<<
144 (
145  Ostream& os,
146  const DimensionedField<Type, GeoMesh>& df
147 )
148 {
149  df.writeData(os);
150 
151  return os;
152 }
153 
154 
155 template<class Type, class GeoMesh>
156 Foam::Ostream& Foam::operator<<
157 (
158  Ostream& os,
159  const tmp<DimensionedField<Type, GeoMesh>>& tdf
160 )
161 {
162  tdf().writeData(os);
163  tdf.clear();
164 
165  return os;
166 }
167 
168 
169 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
DimensionedField(const IOobject &io, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &field)
Construct from components, copy initial field content.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
const dimensionSet dimless
Dimensionless.
const bool writeData(pdfDictionary.get< bool >("writeData"))
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
dynamicFvMesh & mesh
Generic templated field type.
Definition: Field.H:61
bool writeData(Ostream &os, const word &fieldDictEntry) const
A class for handling words, derived from Foam::string.
Definition: word.H:63
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
labelList f(nPoints)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
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