BUG: DataEntry: corrected external, file based tables

This commit is contained in:
mattijs
2012-02-03 12:39:48 +00:00
parent d3820e2595
commit 100ba9c0c4
9 changed files with 99 additions and 17 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -74,7 +74,15 @@ namespace Foam
template<class Type> template<class Type>
void Foam::CSV<Type>::read() void Foam::CSV<Type>::read()
{ {
IFstream is(fName_.expand()); fileName expandedFile(fName_);
IFstream is(expandedFile.expand());
if (!is.good())
{
FatalIOErrorIn("CSV<Type>::read()", is)
<< "Cannot open CSV file for reading."
<< exit(FatalIOError);
}
DynamicList<Tuple2<scalar, Type> > values; DynamicList<Tuple2<scalar, Type> > values;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -29,13 +29,14 @@ Description
e.g. time e.g. time
\verbatim \verbatim
<entryName> csvFile <entryName> csvFile;
csvFileCoeffs
{ {
hasHeaderLine true; hasHeaderLine true;
refColumn 0; // reference column index refColumn 0; // reference column index
componentColumns (0 1 2); // component column indices componentColumns (1 2 3); // component column indices
separator ","; // optional (defaults to ",") separator ","; // optional (defaults to ",")
fileName fileXYZ; // name of csv data file fileName "fileXYZ"; // name of csv data file
outOfBounds clamp; // optional out-of-bounds handling outOfBounds clamp; // optional out-of-bounds handling
} }
\endverbatim \endverbatim

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -62,11 +62,16 @@ template<class Type>
void Foam::CSV<Type>::writeData(Ostream& os) const void Foam::CSV<Type>::writeData(Ostream& os) const
{ {
DataEntry<Type>::writeData(os); DataEntry<Type>::writeData(os);
os << token::END_STATEMENT << nl; os << token::END_STATEMENT << nl;
os << indent << word(type() + "Coeffs") << nl; os << indent << word(type() + "Coeffs") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl; os << indent << token::BEGIN_BLOCK << incrIndent << nl;
os.writeKeyword("headerLine") << headerLine_ << token::END_STATEMENT << nl;
// Note: for TableBase write the dictionary entries it needs but not
// the values themselves
TableBase<Type>::writeEntries(os);
os.writeKeyword("hasHeaderLine") << headerLine_ << token::END_STATEMENT
<< nl;
os.writeKeyword("refColumn") << refColumn_ << token::END_STATEMENT << nl; os.writeKeyword("refColumn") << refColumn_ << token::END_STATEMENT << nl;
os.writeKeyword("componentColumns") << componentColumns_ os.writeKeyword("componentColumns") << componentColumns_
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -68,6 +68,23 @@ Type Foam::DataEntry<Type>::value(const scalar x) const
} }
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::DataEntry<Type>::value
(
const scalarField& x
) const
{
tmp<Field<Type> > tfld(new Field<Type>(x.size()));
Field<Type>& fld = tfld();
forAll(x, i)
{
fld[i] = this->value(x[i]);
}
return tfld;
}
template<class Type> template<class Type>
Type Foam::DataEntry<Type>::integrate(const scalar x1, const scalar x2) const Type Foam::DataEntry<Type>::integrate(const scalar x1, const scalar x2) const
{ {
@ -84,6 +101,24 @@ Type Foam::DataEntry<Type>::integrate(const scalar x1, const scalar x2) const
} }
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::DataEntry<Type>::integrate
(
const scalarField& x1,
const scalarField& x2
) const
{
tmp<Field<Type> > tfld(new Field<Type>(x1.size()));
Field<Type>& fld = tfld();
forAll(x1, i)
{
fld[i] = this->integrate(x1[i], x2[i]);
}
return tfld;
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "DataEntryIO.C" #include "DataEntryIO.C"

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -40,6 +40,7 @@ SourceFiles
#define DataEntry_H #define DataEntry_H
#include "dictionary.H" #include "dictionary.H"
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -138,9 +139,19 @@ public:
//- Return value as a function of (scalar) independent variable //- Return value as a function of (scalar) independent variable
virtual Type value(const scalar x) const; 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;
//- Integrate between two (scalar) values //- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const; 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;
// I/O // I/O

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -145,8 +145,12 @@ public:
const TableBase<Type>& tbl const TableBase<Type>& tbl
); );
//- Write in dictionary format //- Write all table data in dictionary format
virtual void writeData(Ostream& os) const; virtual void writeData(Ostream& os) const;
//- Write keywords only in dictionary format. Used for non-inline
// table types
virtual void writeEntries(Ostream& os) const;
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -61,6 +61,18 @@ template<class Type>
void Foam::TableBase<Type>::writeData(Ostream& os) const void Foam::TableBase<Type>::writeData(Ostream& os) const
{ {
os << nl << indent << table_ << token::END_STATEMENT << nl; os << nl << indent << table_ << token::END_STATEMENT << nl;
writeEntries(os);
}
template<class Type>
void Foam::TableBase<Type>::writeEntries(Ostream& os) const
{
if (boundsHandling_ != CLAMP)
{
os.writeKeyword("outOfBounds") << boundsHandlingToWord(boundsHandling_)
<< token::END_STATEMENT << nl;
}
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -37,7 +37,8 @@ Foam::TableFile<Type>::TableFile(const word& entryName, const dictionary& dict)
const dictionary coeffs(dict.subDict(type() + "Coeffs")); const dictionary coeffs(dict.subDict(type() + "Coeffs"));
coeffs.lookup("fileName") >> fName_; coeffs.lookup("fileName") >> fName_;
IFstream is(fName_.expand()); fileName expandedFile(fName_);
IFstream is(expandedFile.expand());
is >> this->table_; is >> this->table_;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -55,6 +55,11 @@ void Foam::TableFile<Type>::writeData(Ostream& os) const
os << token::END_STATEMENT << nl os << token::END_STATEMENT << nl
<< indent << word(type() + "Coeffs") << nl << indent << word(type() + "Coeffs") << nl
<< indent << token::BEGIN_BLOCK << nl << incrIndent; << indent << token::BEGIN_BLOCK << nl << incrIndent;
// Note: for TableBase write the dictionary entries it needs but not
// the values themselves
TableBase<Type>::writeEntries(os);
os.writeKeyword("fileName")<< fName_ << token::END_STATEMENT << nl; os.writeKeyword("fileName")<< fName_ << token::END_STATEMENT << nl;
os << decrIndent << indent << token::END_BLOCK << endl; os << decrIndent << indent << token::END_BLOCK << endl;
} }