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 
53  // The primitive field
54  auto& fld = static_cast<Field<Type>&>(*this);
55 
56  fld.resize_nocopy(GeoMesh::size(mesh_));
57  fld.assign(fieldDictEntry, fieldDict, fld.size());
58 }
59 
60 
61 template<class Type, class GeoMesh>
63 (
64  const word& fieldDictEntry
65 )
66 {
67  if (this->isReadRequired() || (this->isReadOptional() && this->headerOk()))
68  {
69  readField(dictionary(readStream(typeName)), fieldDictEntry);
70  }
71 }
72 
73 
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 
76 template<class Type, class GeoMesh>
78 (
79  const IOobject& io,
80  const Mesh& mesh,
81  const word& fieldDictEntry
82 )
83 :
84  regIOobject(io),
85  Field<Type>(),
86  mesh_(mesh),
87  dimensions_(dimless),
88  oriented_()
89 {
90  readField(dictionary(readStream(typeName)), fieldDictEntry);
91 }
92 
93 
94 template<class Type, class GeoMesh>
96 (
97  const IOobject& io,
98  const Mesh& mesh,
99  const dictionary& fieldDict,
100  const word& fieldDictEntry
101 )
102 :
103  regIOobject(io),
104  Field<Type>(),
105  mesh_(mesh),
106  dimensions_(dimless),
107  oriented_()
108 {
109  readField(fieldDict, fieldDictEntry);
110 }
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
115 template<class Type, class GeoMesh>
117 (
118  Ostream& os,
119  const word& fieldDictEntry
120 ) const
121 {
122  os.writeEntry("dimensions", dimensions());
123  os << nl;
124 
125  if (oriented_.writeEntry(os))
126  {
127  os << nl;
128  }
129 
130  Field<Type>::writeEntry(fieldDictEntry, os);
132  os.check(FUNCTION_NAME);
133  return os.good();
134 }
135 
136 
137 template<class Type, class GeoMesh>
139 {
140  return writeData(os, "value");
141 }
142 
143 
144 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
145 
146 template<class Type, class GeoMesh>
147 Foam::Ostream& Foam::operator<<
148 (
149  Ostream& os,
150  const DimensionedField<Type, GeoMesh>& df
151 )
152 {
153  df.writeData(os);
154 
155  return os;
156 }
157 
158 
159 template<class Type, class GeoMesh>
160 Foam::Ostream& Foam::operator<<
161 (
162  Ostream& os,
163  const tmp<DimensionedField<Type, GeoMesh>>& tdf
164 )
165 {
166  tdf().writeData(os);
167  tdf.clear();
168 
169  return os;
170 }
171 
172 
173 // ************************************************************************* //
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...
dynamicFvMesh & mesh
Generic templated field type.
Definition: Field.H:62
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
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
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:65
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:171