STYLE: rename Polynomial method evaluate() to value() for consistency with DataEntry

STYLE: move DataEntry to OpenFOAM/primitives/functions
This commit is contained in:
Mark Olesen
2011-01-28 16:32:08 +01:00
parent a2fe746899
commit 08680b8b35
24 changed files with 43 additions and 43 deletions

View File

@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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 "Constant.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Constant<Type>::Constant(const word& entryName, Istream& is)
:
DataEntry<Type>(entryName),
value_(pTraits<Type>::zero)
{
is >> value_;
}
template<class Type>
Foam::Constant<Type>::Constant(const Constant<Type>& cnst)
:
DataEntry<Type>(cnst),
value_(cnst.value_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Constant<Type>::~Constant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::Constant<Type>::value(const scalar x) const
{
return value_;
}
template<class Type>
Type Foam::Constant<Type>::integrate(const scalar x1, const scalar x2) const
{
return (x2 - x1)*value_;
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "ConstantIO.C"
// ************************************************************************* //

View File

@ -0,0 +1,130 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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::Constant
Description
Templated basic entry that holds a constant value.
Usage - for entry <entryName> having the value <value>:
@verbatim
<entryName> constant <value>
@endverbatim
SourceFiles
Constant.C
\*---------------------------------------------------------------------------*/
#ifndef Constant_H
#define Constant_H
#include "DataEntry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class Constant;
template<class Type>
Ostream& operator<<(Ostream&, const Constant<Type>&);
/*---------------------------------------------------------------------------*\
Class Constant Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Constant
:
public DataEntry<Type>
{
// Private data
//- Constant value
Type value_;
// Private Member Functions
//- Disallow default bitwise assignment
void operator=(const Constant<Type>&);
public:
// Runtime type information
TypeName("constant");
// Constructors
//- Construct from entry name and Istream
Constant(const word& entryName, Istream& is);
//- Copy constructor
Constant(const Constant<Type>& cnst);
//- Construct and return a clone
virtual tmp<DataEntry<Type> > clone() const
{
return tmp<DataEntry<Type> >(new Constant<Type>(*this));
}
//- Destructor
virtual ~Constant();
// Member Functions
//- Return constant value
Type value(const scalar) const;
//- Integrate between two values
Type integrate(const scalar x1, const scalar x2) const;
//- Ostream Operator
friend Ostream& operator<< <Type>(Ostream&, const Constant<Type>&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "Constant.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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 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_)
);
}
// Check state of Ostream
os.check
(
"Ostream& operator<<(Ostream&, const Constant<Type>&)"
);
return os;
}
// ************************************************************************* //

View File

@ -0,0 +1,92 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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"
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::DataEntry<Type>::DataEntry(const word& entryName)
:
refCount(),
name_(entryName)
{}
template<class Type>
Foam::DataEntry<Type>::DataEntry(const DataEntry<Type>& de)
:
refCount(),
name_(de.name_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::DataEntry<Type>::~DataEntry()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const Foam::word& Foam::DataEntry<Type>::name() const
{
return name_;
}
template<class Type>
Type Foam::DataEntry<Type>::value(const scalar x) const
{
notImplemented("Type Foam::DataEntry<Type>::value(const scalar) const");
return pTraits<Type>::zero;
}
template<class Type>
Type Foam::DataEntry<Type>::integrate(const scalar x1, const scalar x2) const
{
notImplemented
(
"Type Foam::DataEntry<Type>::integrate"
"("
"const scalar, "
"const scalar"
") const"
);
return pTraits<Type>::zero;
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "DataEntryIO.C"
// ************************************************************************* //

View File

@ -0,0 +1,190 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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::DataEntry
Description
Top level data entry class for use in dictionaries. Provides a mechanism
to specify a variable as a certain type, e.g. constant or table, and
provide functions to return the (interpolated) value, and integral between
limits.
SourceFiles
DataEntry.C
DataEntryNew.C
\*---------------------------------------------------------------------------*/
#ifndef DataEntry_H
#define DataEntry_H
#include "dictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class DataEntry;
template<class Type>
Ostream& operator<<
(
Ostream&,
const DataEntry<Type>&
);
/*---------------------------------------------------------------------------*\
Class DataEntry Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class DataEntry
:
public refCount
{
// Private Member Functions
//- Disallow default bitwise assignment
void operator=(const DataEntry<Type>&);
protected:
// Protected data
//- Name of entry
const word name_;
public:
//- Runtime type information
TypeName("DataEntry")
//- Declare runtime constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
DataEntry,
dictionary,
(
const word& entryName,
Istream& is
),
(entryName, is)
);
// Constructor
//- Construct from entry name
DataEntry(const word& entryName);
//- Copy constructor
DataEntry(const DataEntry<Type>& de);
//- Construct and return a clone
virtual tmp<DataEntry<Type> > clone() const
{
return tmp<DataEntry<Type> >(new DataEntry<Type>(*this));
}
//- Selector
static autoPtr<DataEntry<Type> > New
(
const word& entryName,
const dictionary& dict
);
//- Destructor
virtual ~DataEntry();
// Member Functions
// Access
//- Return the name of the entry
const word& name() const;
// Evaluation
//- Return value as a function of (scalar) independent variable
virtual Type value(const scalar x) const;
//- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Ostream Operator
friend Ostream& operator<< <Type>
(
Ostream&,
const DataEntry<Type>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define makeDataEntry(Type) \
\
defineNamedTemplateTypeNameAndDebug(DataEntry<Type>, 0); \
\
defineTemplateRunTimeSelectionTable \
( \
DataEntry<Type>, \
dictionary \
);
#define makeDataEntryType(SS, Type) \
\
defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \
\
DataEntry<Type>::adddictionaryConstructorToTable<SS<Type> > \
add##SS##Type##ConstructorToTable_;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "DataEntry.C"
# include "DataEntryNew.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,47 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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 DataEntry<Type>&
)
{
// Check state of Ostream
os.check
(
"Ostream& operator<<(Ostream&, const DataEntry<Type>&)"
);
return os;
}
// ************************************************************************* //

View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::DataEntry<Type> > Foam::DataEntry<Type>::New
(
const word& entryName,
const dictionary& dict
)
{
Istream& is(dict.lookup(entryName));
word DataEntryType(is);
typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(DataEntryType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorIn
(
"DataEntry<Type>::New(Istream&)"
) << "Unknown DataEntry type "
<< DataEntryType << " for DataEntry "
<< entryName << nl << nl
<< "Valid DataEntry types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalError);
}
return autoPtr<DataEntry<Type> >(cstrIter()(entryName, is));
}
// ************************************************************************* //

View File

@ -0,0 +1,157 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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 "Table.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Table<Type>::Table(const word& entryName, Istream& is)
:
DataEntry<Type>(entryName),
table_(is)
{
if (!table_.size())
{
FatalErrorIn("Foam::Table<Type>::Table(const Istream&)")
<< "Table for entry " << this->name_ << " is invalid (empty)"
<< nl << exit(FatalError);
}
}
template<class Type>
Foam::Table<Type>::Table(const Table<Type>& tbl)
:
DataEntry<Type>(tbl),
table_(tbl.table_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Table<Type>::~Table()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::Table<Type>::value(const scalar x) const
{
// Return zero if out of bounds
if (x < table_[0].first() || x > table_.last().first())
{
return pTraits<Type>::zero;
}
// Find i such that x(i) < x < x(i+1)
label i = 0;
while ((table_[i+1].first() < x) && (i+1 < table_.size()))
{
i++;
}
// Linear interpolation to find value. Note constructor needed for
// Table<label> to convert intermediate scalar back to label.
return Type
(
(x - table_[i].first())/(table_[i+1].first() - table_[i].first())
* (table_[i+1].second() - table_[i].second())
+ table_[i].second()
);
}
template<class Type>
Type Foam::Table<Type>::integrate(const scalar x1, const scalar x2) const
{
// Initialise return value
Type sum = pTraits<Type>::zero;
// Return zero if out of bounds
if ((x1 > table_.last().first()) || (x2 < table_[0].first()))
{
return sum;
}
// Find next index greater than x1
label id1 = 0;
while ((table_[id1].first() < x1) && (id1 < table_.size()))
{
id1++;
}
// Find next index less than x2
label id2 = table_.size() - 1;
while ((table_[id2].first() > x2) && (id2 >= 1))
{
id2--;
}
if ((id1 - id2) == 1)
{
// x1 and x2 lie within 1 interval
sum = 0.5*(value(x1) + value(x2))*(x2 - x1);
}
else
{
// x1 and x2 cross multiple intervals
// Integrate table body
for (label i=id1; i<id2; i++)
{
sum +=
(table_[i].second() + table_[i+1].second())
* (table_[i+1].first() - table_[i].first());
}
sum *= 0.5;
// Add table ends (partial segments)
if (id1 > 0)
{
sum += 0.5
* (value(x1) + table_[id1].second())
* (table_[id1].first() - x1);
}
if (id2 < table_.size() - 1)
{
sum += 0.5
* (table_[id2].second() + value(x2))
* (x2 - table_[id2].first());
}
}
return sum;
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "TableIO.C"
// ************************************************************************* //

View File

@ -0,0 +1,144 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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::Table
Description
Templated table container data entry. Items are stored in a list of
Tuple2's. First column is always stored as scalar entries. Data is read
in the form, e.g. for an entry <entryName> that is (scalar, vector):
@verbatim
<entryName> table
(
0.0 (1 2 3)
1.0 (4 5 6)
);
@endverbatim
SourceFiles
Table.C
\*---------------------------------------------------------------------------*/
#ifndef Table_H
#define Table_H
#include "DataEntry.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class Table;
template<class Type>
Ostream& operator<<
(
Ostream&,
const Table<Type>&
);
/*---------------------------------------------------------------------------*\
Class Table Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Table
:
public DataEntry<Type>
{
// Private data
//- Table data
List<Tuple2<scalar, Type> > table_;
// Private Member Functions
//- Disallow default bitwise assignment
void operator=(const Table<Type>&);
public:
//- Runtime type information
TypeName("table");
// Constructors
//- Construct from entry name and Istream
Table(const word& entryName, Istream& is);
//- Copy constructor
Table(const Table<Type>& tbl);
//- Construct and return a clone
virtual tmp<DataEntry<Type> > clone() const
{
return tmp<DataEntry<Type> >(new Table<Type>(*this));
}
//- Destructor
virtual ~Table();
// Member Functions
//- Return Table value
Type value(const scalar x) const;
//- Integrate between two (scalar) values
Type integrate(const scalar x1, const scalar x2) const;
//- Ostream Operator
friend Ostream& operator<< <Type>
(
Ostream&,
const Table<Type>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "Table.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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 Table<Type>& tbl
)
{
if (os.format() == IOstream::ASCII)
{
os << static_cast<const DataEntry<Type>& >(tbl)
<< token::SPACE << tbl.table_;
}
else
{
os << static_cast<const DataEntry<Type>& >(tbl);
os.write
(
reinterpret_cast<const char*>(&tbl.table_),
sizeof(tbl.table_)
);
}
// Check state of Ostream
os.check
(
"Ostream& operator<<(Ostream&, const Table<Type>&)"
);
return os;
}
// ************************************************************************* //

View File

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ 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"
#include "Constant.H"
#include "Table.H"
#include "label.H"
#include "scalar.H"
#include "vector.H"
namespace Foam
{
makeDataEntry(label);
makeDataEntryType(Constant, label);
makeDataEntryType(Table, label);
makeDataEntry(scalar);
makeDataEntryType(Constant, scalar);
makeDataEntryType(Table, scalar);
makeDataEntry(vector);
makeDataEntryType(Constant, vector);
makeDataEntryType(Table, vector);
}
// ************************************************************************* //

View File

@ -0,0 +1,99 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\/ 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 "polynomial.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(polynomial, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::polynomial::polynomial(const word& entryName, Istream& is)
:
DataEntry<scalar>(entryName),
coeffs_(is)
{
if (!coeffs_.size())
{
FatalErrorIn("Foam::polynomial::polynomial(const word&, Istream&)")
<< "polynomial coefficients for entry " << this->name_
<< " is invalid (empty)" << nl << exit(FatalError);
}
}
Foam::polynomial::polynomial(const polynomial& poly)
:
DataEntry<scalar>(poly),
coeffs_(poly.coeffs_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::polynomial::~polynomial()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::polynomial::value(const scalar x) const
{
scalar y = coeffs_[0].first();
scalar powX = x;
for (label i = 1; i < coeffs_.size(); i++)
{
y += coeffs_[i].first()*powX;
powX *= x;
}
return y;
}
Foam::scalar Foam::polynomial::integrate(const scalar x1, const scalar x2) const
{
scalar intx = 0.0;
forAll(coeffs_, i)
{
intx +=
coeffs_[i].first()/(coeffs_[i].second() + 1)
*(
pow(x2, coeffs_[i].second() + 1)
- pow(x1, coeffs_[i].second() + 1)
);
}
return intx;
}
// ************************************************************************* //

View File

@ -0,0 +1,132 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\/ 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::polynomial
Description
Polynomial container data entry for scalars. Items are stored in a list of
Tuple2's. Data is input in the form, e.g. for an entry <entryName> that
describes y = x^2 + 2x^3
@verbatim
<entryName> polynomial
(
(1 2)
(2 3)
);
@endverbatim
SourceFiles
polynomial.C
\*---------------------------------------------------------------------------*/
#ifndef polynomial_H
#define polynomial_H
#include "DataEntry.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class polynomial;
// Forward declaration of friend functions
Ostream& operator<<
(
Ostream&,
const polynomial&
);
/*---------------------------------------------------------------------------*\
Class polynomial Declaration
\*---------------------------------------------------------------------------*/
class polynomial
:
public DataEntry<scalar>
{
// Private data
//- Polynomial coefficients - list of prefactor, exponent
List<Tuple2<scalar, scalar> > coeffs_;
// Private Member Functions
//- Disallow default bitwise assignment
void operator=(const polynomial&);
public:
//- Runtime type information
TypeName("polynomial");
// Constructors
polynomial(const word& entryName, Istream& is);
//- Copy constructor
polynomial(const polynomial& poly);
//- Construct and return a clone
virtual tmp<DataEntry<scalar> > clone() const
{
return tmp<DataEntry<scalar> >(new polynomial(*this));
}
//- Destructor
virtual ~polynomial();
// Member Functions
//- Return polynomial value
scalar value(const scalar x) const;
//- Integrate between two (scalar) values
scalar integrate(const scalar x1, const scalar x2) const;
//- Ostream Operator
friend Ostream& operator<<(Ostream&, const polynomial&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\/ 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 "polynomial.H"
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const polynomial& poly
)
{
if (os.format() == IOstream::ASCII)
{
os << static_cast<const DataEntry<scalar>& >(poly)
<< token::SPACE << poly.coeffs_;
}
else
{
os << static_cast<const DataEntry<scalar>& >(poly);
os.write
(
reinterpret_cast<const char*>(&poly.coeffs_),
sizeof(poly.coeffs_)
);
}
// Check state of Ostream
os.check
(
"Ostream& operator<<(Ostream&, const polynomial&)"
);
return os;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -149,7 +149,7 @@ Foam::scalar& Foam::Polynomial<PolySize>::logCoeff()
template<int PolySize>
Foam::scalar Foam::Polynomial<PolySize>::evaluate(const scalar x) const
Foam::scalar Foam::Polynomial<PolySize>::value(const scalar x) const
{
scalar y = this->v_[0];
@ -192,7 +192,7 @@ Foam::scalar Foam::Polynomial<PolySize>::integrateLimits
intPolyType poly = this->integrate();
return poly.evaluate(x2) - poly.evaluate(x1);
return poly.value(x2) - poly.value(x1);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -32,7 +32,7 @@ Description
where 0 \<= i \<= n
- integer powers, starting at zero
- evaluate(x) to evaluate the poly for a given value
- value(x) to evaluate the poly for a given value
- integrate(x1, x2) between two scalar values
- integrate() to return a new, intergated coeff polynomial
- increases the size (order)
@ -134,7 +134,7 @@ public:
// Evaluation
//- Return polynomial value
scalar evaluate(const scalar x) const;
scalar value(const scalar x) const;
//- Return integrated polynomial coefficients
// argument becomes zeroth element (constant of integration)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License