diff --git a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C index 3fe17d24a01e1cbf6c973d3ce7e9ca448d171059..4719be11452ff760d4808066876f249dd9157f76 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 c95406350b3b461546266e6cad4ee0badb3dffb4..99fcbb36066d979f76fbf94d54fec9cdf6594138 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 d16ca23ab89696b9a8a5169962c0c649bc180c61..b5bfad8b3af813f7bc72cbcd52cf3dbecb289586 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 cb46155840ae876ae7aab31ae5061e82eaefb508..f85ab33d82485c55e9b3b32fe7ffe02c998929b3 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 5b3e7831016a61333bdc38ddfd09cd69eb25d454..00c0b0c8e13139804c0eb25e55148a671b78918e 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 f4d20028bcc0616cecb5d26ed9b2dab7d992cf60..ef0cdd2d405de748b3051c3443adb2a15b026ae9 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 438c657a8f19e22acd142f423e69328d623bea94..667ac72be23b8cab68a69f3df477e78e3d525ece 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 9c34b0cd1c2bf38ac75213b2704bb22288e0454d..c2553ee03d916b38cd2a6b69cb51f9bc8eaaec89 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 6e2c4d339b2bf38b4b3ce6e5c04af9bb2780733c..b213ad8b139515187911e9fea20a731c830e347b 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; }