ENH: Adding dimensioSet to DataEntry and modify MRFZone entry types

This commit is contained in:
sergio
2012-04-13 16:31:07 +01:00
parent 8909ecc8bb
commit 48c70a91df
29 changed files with 488 additions and 92 deletions

View File

@ -163,6 +163,22 @@ public:
return TableBase<Type>::integrate(x1, x2);
}
//- Return dimensioned constant value
virtual dimensioned<Type> dimValue(const scalar x) const
{
return TableBase<Type>::dimValue(x);
}
//- Integrate between two values and return dimensioned type
virtual dimensioned<Type> dimIntegrate
(
const scalar x1,
const scalar x2
) const
{
return TableBase<Type>::dimIntegrate(x1, x2);
}
// I/O

View File

@ -34,9 +34,27 @@ Foam::CompatibilityConstant<Type>::CompatibilityConstant
)
:
DataEntry<Type>(entryName),
value_(pTraits<Type>::zero)
value_(pTraits<Type>::zero),
dimensions_(dimless)
{
dict.lookup(entryName) >> value_;
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_;
}
}
@ -47,10 +65,10 @@ Foam::CompatibilityConstant<Type>::CompatibilityConstant
)
:
DataEntry<Type>(cnst),
value_(cnst.value_)
value_(cnst.value_),
dimensions_(cnst.dimensions_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
@ -78,6 +96,23 @@ Type Foam::CompatibilityConstant<Type>::integrate
}
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"

View File

@ -42,6 +42,7 @@ SourceFiles
#define CompatibilityConstant_H
#include "DataEntry.H"
#include "dimensionSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -68,6 +69,9 @@ class CompatibilityConstant
//- Constant value
Type value_;
//- The dimension set
dimensionSet dimensions_;
// Private Member Functions
@ -111,6 +115,16 @@ 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

View File

@ -31,12 +31,27 @@ template<class Type>
Foam::Constant<Type>::Constant(const word& entryName, const dictionary& dict)
:
DataEntry<Type>(entryName),
value_(pTraits<Type>::zero)
value_(pTraits<Type>::zero),
dimensions_(dimless)
{
Istream& is(dict.lookup(entryName));
word entryType(is);
is >> value_;
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_;
}
}
@ -44,7 +59,8 @@ template<class Type>
Foam::Constant<Type>::Constant(const Constant<Type>& cnst)
:
DataEntry<Type>(cnst),
value_(cnst.value_)
value_(cnst.value_),
dimensions_(cnst.dimensions_)
{}
@ -71,6 +87,22 @@ 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"

View File

@ -41,6 +41,7 @@ SourceFiles
#define Constant_H
#include "DataEntry.H"
#include "dimensionSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -67,6 +68,9 @@ class Constant
//- Constant value
Type value_;
//- The dimension set
dimensionSet dimensions_;
// Private Member Functions
@ -107,6 +111,16 @@ 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

View File

@ -76,6 +76,22 @@ Type Foam::DataEntry<Type>::value(const scalar x) const
}
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;
}
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::DataEntry<Type>::value
(
@ -93,22 +109,6 @@ Foam::tmp<Foam::Field<Type> > Foam::DataEntry<Type>::value
}
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;
}
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::DataEntry<Type>::integrate
(
@ -127,6 +127,90 @@ Foam::tmp<Foam::Field<Type> > Foam::DataEntry<Type>::integrate
}
template<class Type>
Foam::dimensioned<Type> Foam::DataEntry<Type>::dimValue(const scalar x) const
{
notImplemented
(
"dimensioned<Type> Foam::DataEntry<dimensioned<Type> >::dimValue"
"(const scalar) const"
);
return dimensioned<Type>("zero", dimless, pTraits<Type>::zero);
}
template<class Type>
Foam::dimensioned<Type> Foam::DataEntry<Type>::dimIntegrate
(
const scalar x1,
const scalar x2
) const
{
notImplemented
(
"dimensioned<Type> Foam::DataEntry<Type>::dimIntegrate"
"("
"const scalar, "
"const scalar"
") const"
);
return dimensioned<Type>("zero", dimless, pTraits<Type>::zero);
}
template<class Type>
Foam::tmp<Foam::Field<Foam::dimensioned<Type> > >
Foam::DataEntry<Type>::dimValue
(
const scalarField& x
) const
{
tmp<Field<dimensioned<Type> > > tfld
(
new Field<dimensioned<Type> >
(
x.size(),
dimensioned<Type>("zero", dimless, pTraits<Type>::zero)
)
);
Field<dimensioned<Type> >& fld = tfld();
forAll(x, i)
{
fld[i] = this->dimValue(x[i]);
}
return tfld;
}
template<class Type>
Foam::tmp<Foam::Field<Foam::dimensioned<Type> > >
Foam::DataEntry<Type>::dimIntegrate
(
const scalarField& x1,
const scalarField& x2
) const
{
tmp<Field<dimensioned<Type> > > tfld
(
new Field<dimensioned<Type> >(x1.size())
);
Field<dimensioned<Type> >& fld = tfld();
forAll(x1, i)
{
fld[i] = this->dimIntegrate(x1[i], x2[i]);
}
return tfld;
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "DataEntryIO.C"

View File

@ -41,6 +41,7 @@ SourceFiles
#include "dictionary.H"
#include "Field.H"
#include "dimensionedType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -141,23 +142,49 @@ public:
virtual void convertTimeBase(const Time& t);
// Evaluation
public:
//- Return value as a function of (scalar) independent variable
virtual Type value(const scalar x) const;
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type> > value(const scalarField& x) const;
// Evaluation
//- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Return value as a function of (scalar) independent variable
virtual Type value(const scalar x) const;
//- Integrate between two (scalar) values
virtual tmp<Field<Type> > integrate
(
const scalarField& x1,
const scalarField& x2
) const;
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type> > value(const scalarField& x) const;
//- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Integrate between two (scalar) values
virtual tmp<Field<Type> > integrate
(
const scalarField& x1,
const scalarField& x2
) const;
//- Return dimensioned type
virtual dimensioned<Type> dimValue(const scalar x) const;
//- Return dimensioned type as a function of (scalar)
virtual tmp<Field<dimensioned<Type> > > dimValue
(
const scalarField& x
) const;
//- Integrate between two scalars and returns a dimensioned type
virtual dimensioned<Type> dimIntegrate
(
const scalar x1,
const scalar x2
) const;
//- Integrate between two scalars and returns list of dimensioned type
virtual tmp<Field<dimensioned<Type> > > dimIntegrate
(
const scalarField& x1,
const scalarField& x2
) const;
// I/O

View File

@ -41,7 +41,15 @@ Foam::autoPtr<Foam::DataEntry<Type> > Foam::DataEntry<Type>::New
word DataEntryType;
if (firstToken.isWord())
{
DataEntryType = firstToken.wordToken();
// Dimensioned type default compatibility
if (firstToken.wordToken() == entryName)
{
DataEntryType = "CompatibilityConstant";
}
else
{
DataEntryType = firstToken.wordToken();
}
}
else
{

View File

@ -36,6 +36,12 @@ Foam::Table<Type>::Table(const word& entryName, const dictionary& dict)
Istream& is(dict.lookup(entryName));
word entryType(is);
token firstToken(is);
is.putBack(firstToken);
if (firstToken == token::BEGIN_SQR)
{
is >> this->dimensions_;
}
is >> this->table_;
TableBase<Type>::check();

View File

@ -30,7 +30,7 @@ Description
in the form, e.g. for an entry \<entryName\> that is (scalar, vector):
\verbatim
<entryName> table
<entryName> table [0 1 0 0 0] //dimension set optional
(
0.0 (1 2 3)
1.0 (4 5 6)
@ -129,6 +129,22 @@ public:
return TableBase<Type>::integrate(x1, x2);
}
//- Return dimensioned constant value
virtual dimensioned<Type> dimValue(const scalar x) const
{
return TableBase<Type>::dimValue(x);
}
//- Integrate between two values and return dimensioned type
virtual dimensioned<Type> dimIntegrate
(
const scalar x1,
const scalar x2
)
{
return TableBase<Type>::dimIntegrate(x1, x2);
}
// I/O

View File

@ -39,7 +39,8 @@ Foam::TableBase<Type>::TableBase(const word& name, const dictionary& dict)
dict.lookupOrDefault<word>("outOfBounds", "clamp")
)
),
table_()
table_(),
dimensions_(dimless)
{}
@ -48,7 +49,8 @@ Foam::TableBase<Type>::TableBase(const TableBase<Type>& tbl)
:
name_(tbl.name_),
boundsHandling_(tbl.boundsHandling_),
table_(tbl.table_)
table_(tbl.table_),
dimensions_(tbl.dimensions_)
{}
@ -330,6 +332,11 @@ Type Foam::TableBase<Type>::value(const scalar x) const
i++;
}
Info <<
(xDash - table_[i].first())/(table_[i+1].first() - table_[i].first())
* (table_[i+1].second() - table_[i].second())
+ table_[i].second() << endl;
// Linear interpolation to find value
return Type
(
@ -403,6 +410,28 @@ Type Foam::TableBase<Type>::integrate(const scalar x1, const scalar x2) const
}
template<class Type>
Foam::dimensioned<Type> Foam::TableBase<Type>::
dimValue(const scalar x) const
{
return dimensioned<Type>("dimensionedValue", dimensions_, this->value(x));
}
template<class Type>
Foam::dimensioned<Type> Foam::TableBase<Type>::dimIntegrate
(
const scalar x1, const scalar x2
) const
{
return dimensioned<Type>
(
"dimensionedValue",
dimensions_,
this->integrate(x2, x1)
);
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "TableBaseIO.C"

View File

@ -37,6 +37,7 @@ SourceFiles
#include "DataEntry.H"
#include "Tuple2.H"
#include "dimensionSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -87,6 +88,9 @@ protected:
//- Table data
List<Tuple2<scalar, Type> > table_;
//- The dimension set
dimensionSet dimensions_;
// Protected Member Functions
@ -138,6 +142,16 @@ public:
//- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const;
//- Return dimensioned constant value
virtual dimensioned<Type> dimValue(const scalar x) const;
//- Integrate between two values and return dimensioned type
virtual dimensioned<Type> dimIntegrate
(
const scalar x1,
const scalar x2
) const;
// I/O

View File

@ -37,6 +37,11 @@ Foam::TableFile<Type>::TableFile(const word& entryName, const dictionary& dict)
const dictionary coeffs(dict.subDict(type() + "Coeffs"));
coeffs.lookup("fileName") >> fName_;
if (coeffs.found("dimensions"))
{
coeffs.lookup("dimensions") >> this->dimensions_;
}
fileName expandedFile(fName_);
IFstream is(expandedFile.expand());

View File

@ -31,8 +31,9 @@ Description
<entryName> tableFile;
tableFileCoeffs
{
fileName dataFile; // name of data file
outOfBounds clamp; // optional out-of-bounds handling
dimensions [0 0 1 0 0]; // optional dimensions
fileName dataFile; // name of data file
outOfBounds clamp; // optional out-of-bounds handling
}
\endverbatim
@ -145,6 +146,22 @@ public:
return TableBase<Type>::integrate(x1, x2);
}
//- Return dimensioned constant value
virtual dimensioned<Type> dimValue(const scalar x) const
{
return TableBase<Type>::dimValue(x);
}
//- Integrate between two values and return dimensioned type
virtual dimensioned<Type> dimIntegrate
(
const scalar x1,
const scalar x2
)
{
return TableBase<Type>::dimIntegrate(x1, x2);
}
// I/O

View File

@ -42,11 +42,19 @@ Foam::polynomial::polynomial(const word& entryName, const dictionary& dict)
:
DataEntry<scalar>(entryName),
coeffs_(),
canIntegrate_(true)
canIntegrate_(true),
dimensions_(dimless)
{
Istream& is(dict.lookup(entryName));
word entryType(is);
token firstToken(is);
is.putBack(firstToken);
if (firstToken == token::BEGIN_SQR)
{
is >> this->dimensions_;
}
is >> coeffs_;
if (!coeffs_.size())
@ -85,7 +93,8 @@ Foam::polynomial::polynomial
:
DataEntry<scalar>(entryName),
coeffs_(coeffs),
canIntegrate_(true)
canIntegrate_(true),
dimensions_(dimless)
{
if (!coeffs_.size())
{
@ -125,7 +134,8 @@ Foam::polynomial::polynomial(const polynomial& poly)
:
DataEntry<scalar>(poly),
coeffs_(poly.coeffs_),
canIntegrate_(poly.canIntegrate_)
canIntegrate_(poly.canIntegrate_),
dimensions_(poly.dimensions_)
{}
@ -180,4 +190,26 @@ Foam::scalar Foam::polynomial::integrate(const scalar x1, const scalar x2) const
}
Foam::dimensioned<Foam::scalar> Foam::polynomial::dimValue
(
const scalar x
) const
{
return dimensioned<scalar>("dimensionedValue", dimensions_, value(x));
}
Foam::dimensioned<Foam::scalar> Foam::polynomial::dimIntegrate
(
const scalar x1, const scalar x2
) const
{
return dimensioned<scalar>
(
"dimensionedValue",
dimensions_,
integrate(x1, x2)
);
}
// ************************************************************************* //

View File

@ -30,7 +30,7 @@ Description
describes y = x^2 + 2x^3
\verbatim
<entryName> polynomial
<entryName> polynomial [0 0 1 0 0] // optional dimensions
(
(1 2)
(2 3)
@ -47,6 +47,7 @@ SourceFiles
#include "DataEntry.H"
#include "Tuple2.H"
#include "dimensionSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -79,6 +80,9 @@ class polynomial
//- Flag to indicate whether poly can be integrated
bool canIntegrate_;
//- The dimension set
dimensionSet dimensions_;
// Private Member Functions
@ -129,6 +133,16 @@ public:
//- Integrate between two (scalar) values
scalar integrate(const scalar x1, const scalar x2) const;
//- Return dimensioned constant value
dimensioned<scalar> dimValue(const scalar) const;
//- Integrate between two values and return dimensioned type
dimensioned<scalar> dimIntegrate
(
const scalar x1,
const scalar x2
) const;
// I/O