Commit 48428e7c authored by Henry Weller's avatar Henry Weller
Browse files

DataEntry: Rationalized IO to ensure consistency between read and write

Removed inconsistent binary output.
Removed unused and IO-inconsistent functions.
Simplified the handling of backward-compatible constant value:
    Removed the unnecessary CompatibilityConstant,
    Updated Constant and DataEntryNew to handle constant value construction.
parent 59ebf74e
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -34,20 +34,13 @@ Foam::Ostream& Foam::operator<<
const CSV<Type>& tbl
)
{
if (os.format() == IOstream::ASCII)
{
os << static_cast<const DataEntry<Type>& >(tbl)
<< token::SPACE << tbl.nHeaderLine_
<< token::SPACE << tbl.timeColumn_
<< token::SPACE << tbl.componentColumns_
<< token::SPACE << tbl.separator_
<< token::SPACE << tbl.mergeSeparators_
<< token::SPACE << tbl.fileName_;
}
else
{
os << static_cast<const DataEntry<Type>& >(tbl);
}
os << static_cast<const DataEntry<Type>& >(tbl)
<< token::SPACE << tbl.nHeaderLine_
<< token::SPACE << tbl.timeColumn_
<< token::SPACE << tbl.componentColumns_
<< token::SPACE << tbl.separator_
<< token::SPACE << tbl.mergeSeparators_
<< token::SPACE << tbl.fileName_;
// Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const CSV<Type>&)");
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "CompatibilityConstant.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::CompatibilityConstant<Type>::CompatibilityConstant
(
const word& entryName,
const dictionary& dict
)
:
DataEntry<Type>(entryName),
value_(pTraits<Type>::zero),
dimensions_(dimless)
{
Istream& is(dict.lookup(entryName));
token firstToken(is);
if (firstToken.isWord())
{
token nextToken(is);
if (nextToken == token::BEGIN_SQR)
{
is.putBack(nextToken);
is >> dimensions_;
is >> value_;
}
}
else
{
is.putBack(firstToken);
is >> value_;
}
}
template<class Type>
Foam::CompatibilityConstant<Type>::CompatibilityConstant
(
const CompatibilityConstant<Type>& cnst
)
:
DataEntry<Type>(cnst),
value_(cnst.value_),
dimensions_(cnst.dimensions_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::CompatibilityConstant<Type>::~CompatibilityConstant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::CompatibilityConstant<Type>::value(const scalar x) const
{
return value_;
}
template<class Type>
Type Foam::CompatibilityConstant<Type>::integrate
(
const scalar x1,
const scalar x2
) const
{
return (x2 - x1)*value_;
}
template<class Type>
Foam::dimensioned<Type> Foam::CompatibilityConstant<Type>::
dimValue(const scalar x) const
{
return dimensioned<Type>("dimensionedValue", dimensions_, value_);
}
template<class Type>
Foam::dimensioned<Type> Foam::CompatibilityConstant<Type>::dimIntegrate
(
const scalar x1, const scalar x2
) const
{
return dimensioned<Type>("dimensionedValue", dimensions_, (x2-x1)*value_);
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "CompatibilityConstantIO.C"
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::CompatibilityConstant
Description
Templated basic entry that holds a constant value for backwards
compatibility (when DataEntry type is not present)
Usage - for entry \<entryName\> having the value <value>:
\verbatim
<entryName> <value>
\endverbatim
SourceFiles
CompatibilityConstant.C
\*---------------------------------------------------------------------------*/
#ifndef CompatibilityConstant_H
#define CompatibilityConstant_H
#include "DataEntry.H"
#include "dimensionSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class CompatibilityConstant;
template<class Type>
Ostream& operator<<(Ostream&, const CompatibilityConstant<Type>&);
/*---------------------------------------------------------------------------*\
Class CompatibilityConstant Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class CompatibilityConstant
:
public DataEntry<Type>
{
// Private data
//- Constant value
Type value_;
//- The dimension set
dimensionSet dimensions_;
// Private Member Functions
//- Disallow default bitwise assignment
void operator=(const CompatibilityConstant<Type>&);
public:
// Runtime type information
TypeName("CompatibilityConstant");
// Constructors
//- Construct from entry name and Istream
CompatibilityConstant(const word& entryName, const dictionary& dict);
//- Copy constructor
CompatibilityConstant(const CompatibilityConstant<Type>& cnst);
//- Construct and return a clone
virtual tmp<DataEntry<Type>> clone() const
{
return tmp<DataEntry<Type>>
(
new CompatibilityConstant<Type>(*this)
);
}
//- Destructor
virtual ~CompatibilityConstant();
// Member Functions
//- Return constant value
Type value(const scalar) const;
//- Integrate between two values
Type integrate(const scalar x1, const scalar x2) const;
//- Return dimensioned constant value
dimensioned<Type> dimValue(const scalar) const;
//- Integrate between two values and return dimensioned type
dimensioned<Type> dimIntegrate
(
const scalar x1,
const scalar x2
) const;
// I/O
//- Ostream Operator
friend Ostream& operator<< <Type>
(
Ostream& os,
const CompatibilityConstant<Type>& cnst
);
//- Write in dictionary format
virtual void writeData(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "CompatibilityConstant.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "DataEntry.H"
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const CompatibilityConstant<Type>& cnst
)
{
if (os.format() == IOstream::ASCII)
{
os << static_cast<const DataEntry<Type>& >(cnst)
<< token::SPACE << cnst.value_;
}
else
{
os << static_cast<const DataEntry<Type>& >(cnst);
os.write
(
reinterpret_cast<const char*>(&cnst.value_),
sizeof(cnst.value_)
);
}
// Check state of Ostream
os.check
(
"Ostream& operator<<(Ostream&, const CompatibilityConstant<Type>&)"
);
return os;
}
template<class Type>
void Foam::CompatibilityConstant<Type>::writeData(Ostream& os) const
{
os.writeKeyword(this->name_) << value_ << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -31,36 +31,27 @@ template<class Type>
Foam::Constant<Type>::Constant(const word& entryName, const dictionary& dict)
:
DataEntry<Type>(entryName),
value_(pTraits<Type>::zero),
dimensions_(dimless)
value_(pTraits<Type>::zero)
{
Istream& is(dict.lookup(entryName));
word entryType(is);
token firstToken(is);
if (firstToken.isWord())
{
token nextToken(is);
if (nextToken == token::BEGIN_SQR)
{
is.putBack(nextToken);
is >> dimensions_;
is >> value_;
}
}
else
{
is.putBack(firstToken);
is >> value_;
}
is >> value_;
}
template<class Type>
Foam::Constant<Type>::Constant(const word& entryName, Istream& is)
:
DataEntry<Type>(entryName),
value_(pTraits<Type>(is))
{}
template<class Type>
Foam::Constant<Type>::Constant(const Constant<Type>& cnst)
:
DataEntry<Type>(cnst),
value_(cnst.value_),
dimensions_(cnst.dimensions_)
value_(cnst.value_)
{}
......@@ -87,26 +78,8 @@ Type Foam::Constant<Type>::integrate(const scalar x1, const scalar x2) const
}
template<class Type>
Foam::dimensioned<Type> Foam::Constant<Type>::dimValue(const scalar x) const
{
return dimensioned<Type>("dimensionedValue", dimensions_, value_);
}
template<class Type>
Foam::dimensioned<Type> Foam::Constant<Type>::dimIntegrate
(
const scalar x1, const scalar x2
) const
{
return dimensioned<Type>("dimensionedValue", dimensions_, (x2-x1)*value_);
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "ConstantIO.C"
// ************************************************************************* //
......@@ -41,18 +41,15 @@ SourceFiles
#define Constant_H
#include "DataEntry.H"
#include "dimensionSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class Constant;
template<class Type>
Ostream& operator<<(Ostream&, const Constant<Type>&);
// Forward declaration of friend functions and operators
template<class Type> class Constant;
template<class Type> Ostream& operator<<(Ostream&, const Constant<Type>&);
/*---------------------------------------------------------------------------*\
Class Constant Declaration
......@@ -68,9 +65,6 @@ class Constant
//- Constant value
Type value_;
//- The dimension set
dimensionSet dimensions_;
// Private Member Functions
......@@ -86,9 +80,14 @@ public:
// Constructors
//- Construct from entry name and Istream
//- Construct from entry name and dictionary
Constant(const word& entryName, const dictionary& dict);
//- Construct from entry name and Istream
// Reads the constant value without the DataEntry type
// for backward compatibility
Constant(const word& entryName, Istream& is);
//- Copy constructor
Constant(const Constant<Type>& cnst);
......@@ -111,16 +110,6 @@ public:
//- Integrate between two values
Type integrate(const scalar x1, const scalar x2) const;
//- Return dimensioned constant value
dimensioned<Type> dimValue(const scalar) const;
//- Integrate between two values and return dimensioned type
dimensioned<Type> dimIntegrate
(
const scalar x1,
const scalar x2
) const;
// I/O
......@@ -144,6 +133,7 @@ public:
#ifdef NoRepository
# include "Constant.C"
# include "DataEntryNew.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -34,20 +34,8 @@ Foam::Ostream& Foam::operator<<
const Constant<Type>& cnst
)
{
if (os.format() == IOstream::ASCII)
{
os << static_cast<const DataEntry<Type>& >(cnst)
<< token::SPACE << cnst.value_;
}
else
{
os << static_cast<const DataEntry<Type>& >(cnst);
os.write
(
reinterpret_cast<const char*>(&cnst.value_),
sizeof(cnst.value_)
);
}
os << static_cast<const DataEntry<Type>& >(cnst)
<< token::SPACE << cnst.value_;
// Check state of Ostream
os.check
......
......@@ -120,79 +120,6 @@ Foam::tmp<Foam::Field<Type>> Foam::DataEntry<Type>::integrate
}
template<class Type>
Foam::dimensioned<Type> Foam::DataEntry<Type>::dimValue(const scalar x) const
{
NotImplemented;
return dimensioned<Type>("zero", dimless, pTraits<Type>::zero);
}