Skip to content
Snippets Groups Projects
Commit 5579f7af authored by henry's avatar henry
Browse files

AverageIOField: Changed the average value to be member data.

parent 3b038c37
No related merge requests found
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -26,42 +26,37 @@ License
#include "AverageIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
AverageIOField<Type>::AverageIOField
Foam::AverageIOField<Type>::AverageIOField
(
const IOobject& io
)
:
regIOobject(io),
pTraits<Type>(readStream(typeName)),
Field<Type>(readStream(typeName))
regIOobject(io)
{
readStream(typeName) >> average_;
readStream(typeName) >> static_cast<Field<Type>&>(*this);
close();
}
template<class Type>
AverageIOField<Type>::AverageIOField
Foam::AverageIOField<Type>::AverageIOField
(
const IOobject& io,
const label size
)
:
regIOobject(io),
pTraits<Type>(pTraits<Type>::zero),
Field<Type>(size)
Field<Type>(size),
average_(0)
{}
template<class Type>
AverageIOField<Type>::AverageIOField
Foam::AverageIOField<Type>::AverageIOField
(
const IOobject& io,
const Type& average,
......@@ -69,21 +64,28 @@ AverageIOField<Type>::AverageIOField
)
:
regIOobject(io),
pTraits<Type>(average),
Field<Type>(f)
Field<Type>(f),
average_(average)
{
if (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
{
readStream(typeName)
>> static_cast<Type&>(*this)
>> average_
>> static_cast<Field<Type>&>(*this);
close();
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
bool Foam::AverageIOField<Type>::writeData(Ostream& os) const
{
os << average_
<< token::NL
<< static_cast<const Field<Type>&>(*this);
return os.good();
}
} // End namespace Foam
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -45,16 +45,20 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class AverageIOField Declaration
Class AverageIOField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class AverageIOField
:
public regIOobject,
public pTraits<Type>,
public Field<Type>
{
// Private data
//- The average of the field
Type average_;
public:
......@@ -87,19 +91,17 @@ public:
// Member functions
const pTraits<Type>& average() const
const Type& average() const
{
return static_cast<const pTraits<Type>&>(*this);
return average_;
}
bool writeData(Ostream& os) const
Type& average()
{
os << static_cast<const Type&>(*this)
<< token::NL
<< static_cast<const Field<Type>&>(*this);
return os.good();
return average_;
}
bool writeData(Ostream& os) const;
};
......
......@@ -22,6 +22,8 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "AverageIOField.H"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment