From 100ba9c0c417b521e911cc3272a4ea4091d9569a Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Fri, 3 Feb 2012 12:39:48 +0000 Subject: [PATCH] BUG: DataEntry: corrected external, file based tables --- .../primitives/functions/DataEntry/CSV/CSV.C | 12 +++++- .../primitives/functions/DataEntry/CSV/CSV.H | 9 +++-- .../functions/DataEntry/CSV/CSVIO.C | 11 ++++-- .../functions/DataEntry/DataEntry/DataEntry.C | 37 ++++++++++++++++++- .../functions/DataEntry/DataEntry/DataEntry.H | 13 ++++++- .../functions/DataEntry/Table/TableBase.H | 8 +++- .../functions/DataEntry/Table/TableBaseIO.C | 14 ++++++- .../functions/DataEntry/TableFile/TableFile.C | 5 ++- .../DataEntry/TableFile/TableFileIO.C | 7 +++- 9 files changed, 99 insertions(+), 17 deletions(-) diff --git a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C index 3fe17d24a01..4719be11452 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C +++ b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.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 @@ -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; diff --git a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.H b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.H index c95406350b3..99fcbb36066 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.H +++ b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSVIO.C b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSVIO.C index d16ca23ab89..b5bfad8b3af 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSVIO.C +++ b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSVIO.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 @@ -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; diff --git a/src/OpenFOAM/primitives/functions/DataEntry/DataEntry/DataEntry.C b/src/OpenFOAM/primitives/functions/DataEntry/DataEntry/DataEntry.C index cb46155840a..f85ab33d824 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/DataEntry/DataEntry.C +++ b/src/OpenFOAM/primitives/functions/DataEntry/DataEntry/DataEntry.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 @@ -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" diff --git a/src/OpenFOAM/primitives/functions/DataEntry/DataEntry/DataEntry.H b/src/OpenFOAM/primitives/functions/DataEntry/DataEntry/DataEntry.H index 5b3e7831016..00c0b0c8e13 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/DataEntry/DataEntry.H +++ b/src/OpenFOAM/primitives/functions/DataEntry/DataEntry/DataEntry.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/DataEntry/Table/TableBase.H b/src/OpenFOAM/primitives/functions/DataEntry/Table/TableBase.H index f4d20028bcc..ef0cdd2d405 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/Table/TableBase.H +++ b/src/OpenFOAM/primitives/functions/DataEntry/Table/TableBase.H @@ -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; }; diff --git a/src/OpenFOAM/primitives/functions/DataEntry/Table/TableBaseIO.C b/src/OpenFOAM/primitives/functions/DataEntry/Table/TableBaseIO.C index 438c657a8f1..667ac72be23 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/Table/TableBaseIO.C +++ b/src/OpenFOAM/primitives/functions/DataEntry/Table/TableBaseIO.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 @@ -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; + } } diff --git a/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFile.C b/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFile.C index 9c34b0cd1c2..c2553ee03d9 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFile.C +++ b/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFile.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 @@ -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_; diff --git a/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFileIO.C b/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFileIO.C index 6e2c4d339b2..b213ad8b139 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFileIO.C +++ b/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFileIO.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 @@ -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; } -- GitLab