DimensionedFieldIO.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-2019 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 
26 #include "DimensionedField.H"
27 #include "IOstreams.H"
28 
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type, class GeoMesh>
34 (
35  const dictionary& fieldDict,
36  const word& fieldDictEntry
37 )
38 {
39  dimensions_.reset(dimensionSet(fieldDict.lookup("dimensions")));
40 
41  Field<Type> f(fieldDictEntry, fieldDict, GeoMesh::size(mesh_));
42  this->transfer(f);
43 }
44 
45 
46 template<class Type, class GeoMesh>
48 (
49  const word& fieldDictEntry
50 )
51 {
52  if
53  (
54  (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
55  || this->readOpt() == IOobject::MUST_READ
56  || this->readOpt() == IOobject::MUST_READ_IF_MODIFIED
57  )
58  {
59  readField(dictionary(readStream(typeName)), fieldDictEntry);
60  }
61 }
62 
63 
64 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65 
66 template<class Type, class GeoMesh>
68 (
69  const IOobject& io,
70  const Mesh& mesh,
71  const word& fieldDictEntry
72 )
73 :
74  regIOobject(io),
75  Field<Type>(0),
76  mesh_(mesh),
77  dimensions_(dimless)
78 {
79  readField(dictionary(readStream(typeName)), fieldDictEntry);
80 }
81 
82 
83 template<class Type, class GeoMesh>
85 (
86  const IOobject& io,
87  const Mesh& mesh,
88  const dictionary& fieldDict,
89  const word& fieldDictEntry
90 )
91 :
92  regIOobject(io),
93  Field<Type>(0),
94  mesh_(mesh),
95  dimensions_(dimless)
96 {
97  readField(fieldDict, fieldDictEntry);
98 }
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
103 template<class Type, class GeoMesh>
105 (
106  Ostream& os,
107  const word& fieldDictEntry
108 ) const
109 {
110  writeEntry(os, "dimensions", dimensions());
111  os << nl;
112 
113  writeEntry(os, fieldDictEntry, static_cast<const Field<Type>&>(*this));
114 
115  // Check state of Ostream
116  os.check
117  (
118  "bool DimensionedField<Type, GeoMesh>::writeData"
119  "(Ostream& os, const word& fieldDictEntry) const"
120  );
121 
122  return (os.good());
123 }
124 
125 
126 template<class Type, class GeoMesh>
128 {
129  return writeData(os, "value");
130 }
131 
132 
133 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
134 
135 template<class Type, class GeoMesh>
136 Foam::Ostream& Foam::operator<<
137 (
138  Ostream& os,
140 )
141 {
142  df.writeData(os);
143 
144  return os;
145 }
146 
147 
148 template<class Type, class GeoMesh>
149 Foam::Ostream& Foam::operator<<
150 (
151  Ostream& os,
153 )
154 {
155  tdf().writeData(os);
156  tdf.clear();
157 
158  return os;
159 }
160 
161 
162 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
const dimensionSet dimless
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
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...
Dimension set for the base types.
Definition: dimensionSet.H:120
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
Foam::pointMesh ::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
bool writeData(Ostream &, const word &fieldDictEntry) const
static const char nl
Definition: Ostream.H:260
DimensionedField(const IOobject &, const Mesh &mesh, const dimensionSet &, const Field< Type > &)
Construct from components.
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
labelList f(nPoints)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844