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 | Copyright (C) 2011-2014 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  os.writeKeyword("dimensions") << dimensions() << token::END_STATEMENT
111  << nl << nl;
112 
113  Field<Type>::writeEntry(fieldDictEntry, os);
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,
139  const DimensionedField<Type, GeoMesh>& df
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,
152  const tmp<DimensionedField<Type, GeoMesh> >& tdf
153 )
154 {
155  tdf().writeData(os);
156  tdf.clear();
157 
158  return os;
159 }
160 
161 
162 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::DimensionedField::readField
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
Definition: DimensionedFieldIO.C:34
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
readField
void readField(const IOobject &io, const fvMesh &mesh, const label i, PtrList< GeoField > &fields)
Definition: redistributePar.C:557
DimensionedField.H
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::DimensionedField::readIfPresent
void readIfPresent(const word &fieldDictEntry="value")
Definition: DimensionedFieldIO.C:48
Foam::DimensionedField::DimensionedField
DimensionedField(const IOobject &, const Mesh &mesh, const dimensionSet &, const Field< Type > &)
Construct from components.
Foam::Field< Type >
Foam::nl
static const char nl
Definition: Ostream.H:260
writeData
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::DimensionedField::writeData
bool writeData(Ostream &, const word &fieldDictEntry) const
Foam::Field< Type >::writeEntry
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:700
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
f
labelList f(nPoints)
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53