Commit 100ba9c0 authored by mattijs's avatar mattijs
Browse files

BUG: DataEntry: corrected external, file based tables

parent d3820e25
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -74,7 +74,15 @@ namespace Foam
template<class Type>
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;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -29,13 +29,14 @@ Description
e.g. time
\verbatim
<entryName> csvFile
<entryName> csvFile;
csvFileCoeffs
{
hasHeaderLine true;
refColumn 0; // reference column index
componentColumns (0 1 2); // component column indices
componentColumns (1 2 3); // component column indices
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
}
\endverbatim
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -62,11 +62,16 @@ template<class Type>
void Foam::CSV<Type>::writeData(Ostream& os) const
{
DataEntry<Type>::writeData(os);
os << token::END_STATEMENT << nl;
os << indent << word(type() + "Coeffs") << 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("componentColumns") << componentColumns_
<< token::END_STATEMENT << nl;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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>
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 * * * * * * * * * * * * * //
#include "DataEntryIO.C"
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -40,6 +40,7 @@ SourceFiles
#define DataEntry_H
#include "dictionary.H"
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -138,9 +139,19 @@ 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;
//- 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;
// I/O
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -145,8 +145,12 @@ public:
const TableBase<Type>& tbl
);
//- Write in dictionary format
//- Write all table data in dictionary format
virtual void writeData(Ostream& os) const;
//- Write keywords only in dictionary format. Used for non-inline
// table types
virtual void writeEntries(Ostream& os) const;
};
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -61,6 +61,18 @@ template<class Type>
void Foam::TableBase<Type>::writeData(Ostream& os) const
{
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;
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -37,7 +37,8 @@ Foam::TableFile<Type>::TableFile(const word& entryName, const dictionary& dict)
const dictionary coeffs(dict.subDict(type() + "Coeffs"));
coeffs.lookup("fileName") >> fName_;
IFstream is(fName_.expand());
fileName expandedFile(fName_);
IFstream is(expandedFile.expand());
is >> this->table_;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -55,6 +55,11 @@ void Foam::TableFile<Type>::writeData(Ostream& os) const
os << token::END_STATEMENT << nl
<< indent << word(type() + "Coeffs") << nl
<< 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 << decrIndent << indent << token::END_BLOCK << endl;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment