mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Added CompatibilityConstant DataEntry for backwards comapatibility
This commit is contained in:
@ -0,0 +1,86 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "CompatibilityConstant.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::CompatibilityConstant<Type>::CompatibilityConstant
|
||||
(
|
||||
const word& entryName, const dictionary& dict
|
||||
)
|
||||
:
|
||||
DataEntry<Type>(entryName),
|
||||
value_(pTraits<Type>::zero)
|
||||
{
|
||||
dict.lookup(entryName) >> value_;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::CompatibilityConstant<Type>::CompatibilityConstant
|
||||
(
|
||||
const CompatibilityConstant<Type>& cnst
|
||||
)
|
||||
:
|
||||
DataEntry<Type>(cnst),
|
||||
value_(cnst.value_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * 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_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
|
||||
|
||||
#include "CompatibilityConstantIO.C"
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,143 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
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"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
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_;
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
// 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
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,69 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -35,17 +35,29 @@ Foam::autoPtr<Foam::DataEntry<Type> > Foam::DataEntry<Type>::New
|
||||
)
|
||||
{
|
||||
Istream& is(dict.lookup(entryName));
|
||||
word DataEntryType(is);
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
word DataEntryType;
|
||||
if (firstToken.isWord())
|
||||
{
|
||||
DataEntryType = firstToken.wordToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
is.putBack(firstToken);
|
||||
// DataEntryType = CompatibilityConstant<Type>::typeName;
|
||||
DataEntryType = "CompatibilityConstant";
|
||||
}
|
||||
|
||||
|
||||
typename dictionaryConstructorTable::iterator cstrIter =
|
||||
dictionaryConstructorTablePtr_->find(DataEntryType);
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"DataEntry<Type>::New(Istream&)"
|
||||
) << "Unknown DataEntry type "
|
||||
FatalErrorIn("DataEntry<Type>::New(const word&, const dictionary&)")
|
||||
<< "Unknown DataEntry type "
|
||||
<< DataEntryType << " for DataEntry "
|
||||
<< entryName << nl << nl
|
||||
<< "Valid DataEntry types are:" << nl
|
||||
|
||||
@ -23,6 +23,7 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "CompatibilityConstant.H"
|
||||
#include "Constant.H"
|
||||
#include "CSV.H"
|
||||
#include "DataEntry.H"
|
||||
@ -39,36 +40,42 @@ License
|
||||
namespace Foam
|
||||
{
|
||||
makeDataEntry(label);
|
||||
makeDataEntryType(CompatibilityConstant, label);
|
||||
makeDataEntryType(Constant, label);
|
||||
// makeDataEntryType(CSV, label);
|
||||
makeDataEntryType(Table, label);
|
||||
makeDataEntryType(TableFile, label);
|
||||
|
||||
makeDataEntry(scalar);
|
||||
makeDataEntryType(CompatibilityConstant, scalar);
|
||||
makeDataEntryType(Constant, scalar);
|
||||
makeDataEntryType(CSV, scalar);
|
||||
makeDataEntryType(Table, scalar);
|
||||
makeDataEntryType(TableFile, scalar);
|
||||
|
||||
makeDataEntry(vector);
|
||||
makeDataEntryType(CompatibilityConstant, vector);
|
||||
makeDataEntryType(Constant, vector);
|
||||
makeDataEntryType(CSV, vector);
|
||||
makeDataEntryType(Table, vector);
|
||||
makeDataEntryType(TableFile, vector);
|
||||
|
||||
makeDataEntry(sphericalTensor);
|
||||
makeDataEntryType(CompatibilityConstant, sphericalTensor);
|
||||
makeDataEntryType(Constant, sphericalTensor);
|
||||
makeDataEntryType(CSV, sphericalTensor);
|
||||
makeDataEntryType(Table, sphericalTensor);
|
||||
makeDataEntryType(TableFile, sphericalTensor);
|
||||
|
||||
makeDataEntry(symmTensor);
|
||||
makeDataEntryType(CompatibilityConstant, symmTensor);
|
||||
makeDataEntryType(Constant, symmTensor);
|
||||
makeDataEntryType(CSV, symmTensor);
|
||||
makeDataEntryType(Table, symmTensor);
|
||||
makeDataEntryType(TableFile, symmTensor);
|
||||
|
||||
makeDataEntry(tensor);
|
||||
makeDataEntryType(CompatibilityConstant, tensor);
|
||||
makeDataEntryType(Constant, tensor);
|
||||
makeDataEntryType(CSV, tensor);
|
||||
makeDataEntryType(Table, tensor);
|
||||
|
||||
Reference in New Issue
Block a user