AverageIOField.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 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 "AverageIOField.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const IOobject& io
34 )
35 :
36  regIOobject(io)
37 {
38  readStream(typeName) >> average_;
39  readStream(typeName) >> static_cast<Field<Type>&>(*this);
40  close();
41 }
42 
43 
44 template<class Type>
46 (
47  const IOobject& io,
48  const label size
49 )
50 :
51  regIOobject(io),
52  Field<Type>(size),
53  average_(pTraits<Type>::zero)
54 {}
55 
56 
57 template<class Type>
59 (
60  const IOobject& io,
61  const Type& average,
62  const Field<Type>& f
63 )
64 :
65  regIOobject(io),
66  Field<Type>(f),
67  average_(average)
68 {
69  if (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
70  {
71  readStream(typeName)
72  >> average_
73  >> static_cast<Field<Type>&>(*this);
74  close();
75  }
76 }
77 
78 
79 template<class Type>
81 {
82  os << average_
83  << token::NL
84  << static_cast<const Field<Type>&>(*this);
85 
86  return os.good();
87 }
88 
89 
90 // ************************************************************************* //
AverageIOField(const IOobject &)
Construct from IOobject.
readOption readOpt() const
Definition: IOobject.H:304
labelList f(nPoints)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool writeData(Ostream &os) const
Pure virtual writaData function.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Pre-declare SubField and related Field type.
Definition: Field.H:57
Traits class for primitives.
Definition: pTraits.H:50
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53