diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 432f6ccc0e23a24262ba36924f1cde81997a76e2..52de21702b5abea64dc1e5780b974c74bb5c6440 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -571,6 +571,10 @@ interpolations = interpolations interpolation = $(interpolations)/interpolation $(interpolations)/patchToPatchInterpolation/PatchToPatchInterpolationName.C +$(interpolations)/interpolationTable/tableReaders/tableReaders.C +$(interpolations)/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C +$(interpolations)/interpolationTable/tableReaders/csv/csvTableReaders.C + algorithms/MeshWave/MeshWaveName.C algorithms/MeshWave/FaceCellWaveName.C diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C index c881af33f56a413f0b87ec8f1a8c810a1a910941..95f4701730339a5946951a17ba64bebab3b8e6f1 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ License #include "interpolationTable.H" #include "IFstream.H" +#include "openFoamTableReader.H" // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // @@ -38,19 +39,19 @@ void Foam::interpolationTable<Type>::readTable() fName.expand(); // Read data from file - IFstream(fName)() >> *this; - - // Check that the data are okay - check(); + reader_()(fName, *this); if (this->empty()) { FatalErrorIn ( "Foam::interpolationTable<Type>::readTable()" - ) << "table is empty" << nl + ) << "table read from " << fName << " is empty" << nl << exit(FatalError); } + + // Check that the data are okay + check(); } @@ -61,7 +62,8 @@ Foam::interpolationTable<Type>::interpolationTable() : List<Tuple2<scalar, Type> >(), boundsHandling_(interpolationTable::WARN), - fileName_("fileNameIsUndefined") + fileName_("fileNameIsUndefined"), + reader_(NULL) {} @@ -75,7 +77,8 @@ Foam::interpolationTable<Type>::interpolationTable : List<Tuple2<scalar, Type> >(values), boundsHandling_(bounds), - fileName_(fName) + fileName_(fName), + reader_(NULL) {} @@ -84,7 +87,8 @@ Foam::interpolationTable<Type>::interpolationTable(const fileName& fName) : List<Tuple2<scalar, Type> >(), boundsHandling_(interpolationTable::WARN), - fileName_(fName) + fileName_(fName), + reader_(new openFoamTableReader<Type>()) { readTable(); } @@ -95,7 +99,8 @@ Foam::interpolationTable<Type>::interpolationTable(const dictionary& dict) : List<Tuple2<scalar, Type> >(), boundsHandling_(wordToBoundsHandling(dict.lookup("outOfBounds"))), - fileName_(dict.lookup("fileName")) + fileName_(dict.lookup("fileName")), + reader_(tableReader<Type>::New(dict)) { readTable(); } @@ -109,7 +114,8 @@ Foam::interpolationTable<Type>::interpolationTable : List<Tuple2<scalar, Type> >(interpTable), boundsHandling_(interpTable.boundsHandling_), - fileName_(interpTable.fileName_) + fileName_(interpTable.fileName_), + reader_(interpTable.reader_) // note: steals reader. Used in write(). {} @@ -233,6 +239,10 @@ void Foam::interpolationTable<Type>::write(Ostream& os) const << fileName_ << token::END_STATEMENT << nl; os.writeKeyword("outOfBounds") << boundsHandlingToWord(boundsHandling_) << token::END_STATEMENT << nl; + if (reader_.valid()) + { + reader_->write(os); + } } diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H index a7f62c1748064472e226ec4a7b4a73302ade61bc..4395269dfa6d6e1994f2aa73949f63f22d191303 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H @@ -34,6 +34,19 @@ Description If \a REPEAT is chosen for the out-of-bounds handling, the final time value is treated as being equivalent to time=0 for the following periods. + + The construct from dictionary reads a filename from a dictionary and + has an optional readerType. Default is to read OpenFOAM format. The only + other format is csv (comma separated values): + + Read csv format: + readerType csv; + fileName "$FOAM_CASE/constant/p0vsTime.csv"; + hasHeaderLine true; // skip first line + timeColumn 0; // time is in column 0 + valueColumns (1); // value starts in column 1 + + Note - Accessing an empty list results in an error. - Accessing a list with a single element always returns the same value. @@ -49,6 +62,9 @@ SourceFiles #include "List.H" #include "Tuple2.H" +#include "tableReader.H" +#include "autoPtr.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -87,6 +103,8 @@ private: //- File name fileName fileName_; + //- the actual reader + autoPtr<tableReader<Type> > reader_; // Private Member Functions diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C new file mode 100644 index 0000000000000000000000000000000000000000..3e8618c17fa73f767f2c9fcd4f378802ea7a51f1 --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C @@ -0,0 +1,181 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "csvTableReader.H" +#include "IFstream.H" +#include "DynamicList.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Type> +Foam::csvTableReader<Type>::csvTableReader(const dictionary& dict) +: + tableReader<Type>(dict), + headerLine_(readBool(dict.lookup("hasHeaderLine"))), + timeColumn_(readLabel(dict.lookup("timeColumn"))), + componentColumns_(dict.lookup("valueColumns")), + separator_(dict.lookupOrDefault<string>("separator", string(","))[0]) +{ + if (componentColumns_.size() != pTraits<Type>::nComponents) + { + FatalErrorIn("csvTableReader<Type>::csvTableReader(const dictionary&)") + << componentColumns_ << " does not have the expected length " + << pTraits<Type>::nComponents << endl + << exit(FatalError); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template<class Type> +Foam::csvTableReader<Type>::~csvTableReader() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +namespace Foam +{ + // doesn't recognize specialization otherwise + template<> + scalar csvTableReader<scalar>::readValue(const List<string>& splitted) + { + if (componentColumns_[0] >= splitted.size()) + { + FatalErrorIn + ( + "csvTableReader<scalar>::readValue(const List<string>&)" + ) << "No column " << componentColumns_[0] << " in " + << splitted << endl + << exit(FatalError); + } + + return readScalar(IStringStream(splitted[componentColumns_[0]])()); + } + + + template<class Type> + Type csvTableReader<Type>::readValue(const List<string>& splitted) + { + Type result; + + for(label i = 0;i < pTraits<Type>::nComponents; i++) + { + if (componentColumns_[i] >= splitted.size()) + { + FatalErrorIn + ( + "csvTableReader<Type>::readValue(const List<string>&)" + ) << "No column " << componentColumns_[i] << " in " + << splitted << endl + << exit(FatalError); + } + + result[i] = readScalar + ( + IStringStream(splitted[componentColumns_[i]])() + ); + } + + return result; + } +} + + +template<class Type> +void Foam::csvTableReader<Type>::operator() +( + const fileName& fName, + List<Tuple2<scalar, Type> >& data +) +{ + IFstream in(fName); + + DynamicList<Tuple2<scalar, Type> > values; + + // Skip header + if (headerLine_) + { + string line; + in.getLine(line); + } + + while (in.good()) + { + string line; + in.getLine(line); + + DynamicList<string> splitted; + + std::size_t pos = 0; + while (pos != std::string::npos) + { + std::size_t nPos = line.find(separator_, pos); + + if (nPos == std::string::npos) + { + splitted.append(line.substr(pos)); + pos=nPos; + } + else + { + splitted.append(line.substr(pos, nPos-pos)); + pos=nPos+1; + } + } + + if (splitted.size() <= 1) + { + break; + } + + scalar time = readScalar(IStringStream(splitted[timeColumn_])()); + Type value = readValue(splitted); + + values.append(Tuple2<scalar,Type>(time, value)); + } + + data.transfer(values); +} + + +template<class Type> +void Foam::csvTableReader<Type>::write(Ostream& os) const +{ + tableReader<Type>::write(os); + + os.writeKeyword("hasHeaderLine") + << headerLine_ << token::END_STATEMENT << nl; + os.writeKeyword("timeColumn") + << timeColumn_ << token::END_STATEMENT << nl; + os.writeKeyword("valueColumns") + << componentColumns_ << token::END_STATEMENT << nl; + os.writeKeyword("separator") + << string(separator_) << token::END_STATEMENT << nl; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.H b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.H new file mode 100644 index 0000000000000000000000000000000000000000..3c823f2e194930a3d956fd5ca5c95de90c215d24 --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.H @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::tableReader + +Description + Reads an interpolation table from a file - CSV-format + +SourceFiles + tableReader.C + +\*---------------------------------------------------------------------------*/ + +#ifndef csvTableReader_H +#define csvTableReader_H + +#include "tableReader.H" +#include "labelList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class csvTableReader Declaration +\*---------------------------------------------------------------------------*/ + +template<class Type> +class csvTableReader +: + public tableReader<Type> +{ + //- does the file have a header line? + const bool headerLine_; + + //- column of the time + const label timeColumn_; + + //- labels of the components + const labelList componentColumns_; + + //- read the next value from the splitted string + Type readValue(const List<string>&); + + //- separator character + const char separator_; + +public: + + //- Runtime type information + TypeName("csv"); + + // Constructors + + //- Construct from dictionary + csvTableReader(const dictionary& dict); + + //- Construct and return a copy + virtual autoPtr<tableReader<Type> > clone() const + { + return autoPtr<tableReader<Type> > + ( + new csvTableReader<Type> + ( + *this + ) + ); + } + + + //- Destructor + + virtual ~csvTableReader(); + + + // Member Functions + + //- Read the table + virtual void operator()(const fileName&, List<Tuple2<scalar, Type> >&); + + //- write the remaining parameters + virtual void write(Ostream& os) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "csvTableReader.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReaders.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReaders.C new file mode 100644 index 0000000000000000000000000000000000000000..5893436dd9de51c2900c85c3f02bcfe49dd4bea0 --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReaders.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "csvTableReader.H" +#include "tableReaders.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeTableReaders(csvTableReader); +} + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.C new file mode 100644 index 0000000000000000000000000000000000000000..3ad1a87510e4dcd5a9a4ed4ddd43957125ed8b08 --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.C @@ -0,0 +1,59 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "openFoamTableReader.H" +#include "IFstream.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Type> +Foam::openFoamTableReader<Type>::openFoamTableReader(const dictionary& dict) +: + tableReader<Type>(dict) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template<class Type> +Foam::openFoamTableReader<Type>::~openFoamTableReader() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +void Foam::openFoamTableReader<Type>::operator() +( + const fileName& fName, + List<Tuple2<scalar, Type> >& data +) +{ + // Read data from file + IFstream(fName)() >> data; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.H b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.H new file mode 100644 index 0000000000000000000000000000000000000000..dd04df78d6a6c3f3a9aeb50d82355cf337fce408 --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReader.H @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::tableReader + +Description + Reads an interpolation table from a file - OpenFOAM-format + +SourceFiles + tableReader.C + +\*---------------------------------------------------------------------------*/ + +#ifndef openFoamTableReader_H +#define openFoamTableReader_H + +#include "tableReader.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class openFoamTableReader Declaration +\*---------------------------------------------------------------------------*/ + +template<class Type> +class openFoamTableReader +: + public tableReader<Type> +{ + +public: + + //- Runtime type information + TypeName("openFoam"); + + // Constructors + + //- Construct from dictionary + openFoamTableReader(const dictionary &dict); + + //- Construct and return a copy + virtual autoPtr<tableReader<Type> > clone() const + { + return autoPtr<tableReader<Type> > + ( + new openFoamTableReader<Type> + ( + *this + ) + ); + } + + + //- Destructor + + virtual ~openFoamTableReader(); + + + // Member functions + + //- Read the table + virtual void operator()(const fileName&, List<Tuple2<scalar, Type> > &); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "openFoamTableReader.C" +#endif + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C new file mode 100644 index 0000000000000000000000000000000000000000..8dd7db0a9f9a4054394099b2bad1b53f93bfa8ec --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "openFoamTableReader.H" +#include "tableReaders.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeTableReaders(openFoamTableReader); +} + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.C new file mode 100644 index 0000000000000000000000000000000000000000..bcad2aa965e3ce19773eb657aa1a67b2d77597e8 --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.C @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "tableReader.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +template<class Type> +Foam::autoPtr<Foam::tableReader<Type> > Foam::tableReader<Type>::New +( + const dictionary& spec +) +{ + const word readerType = spec.lookupOrDefault<word> + ( + "readerType", + "openFoam" + ); + + typename dictionaryConstructorTable::iterator cstrIter = + dictionaryConstructorTablePtr_ + ->find(readerType); + + if (cstrIter == dictionaryConstructorTablePtr_->end()) + { + FatalErrorIn + ( + "tableReader::New(const dictionary&)" + ) << "Unknown reader type " << readerType + << nl << nl + << "Valid reader types : " << nl + << dictionaryConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr<tableReader<Type> >(cstrIter()(spec)); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Type> +Foam::tableReader<Type>::tableReader(const dictionary&) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template<class Type> +Foam::tableReader<Type>::~tableReader() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +void Foam::tableReader<Type>::write(Ostream& os) const +{ + if (this->type() != "openFoam") + { + os.writeKeyword("readerType") + << this->type() << token::END_STATEMENT << nl; + } +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.H b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.H new file mode 100644 index 0000000000000000000000000000000000000000..b85af66c101243c0cc9446f14154ee6326798924 --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReader.H @@ -0,0 +1,128 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::tableReader + +Description + Base class to read table data for the interpolationTable + +SourceFiles + tableReader.C + +\*---------------------------------------------------------------------------*/ + +#ifndef tableReader_H +#define tableReader_H + +#include "fileName.H" +#include "wordList.H" +#include "vector.H" +#include "tensor.H" +#include "typeInfo.H" +#include "runTimeSelectionTables.H" +#include "autoPtr.H" +#include "dictionary.H" +#include "Tuple2.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class tableReader Declaration +\*---------------------------------------------------------------------------*/ + +template<class Type> +class tableReader +{ + +public: + + //- Runtime type information + TypeName("tableReader"); + + // Declare run-time constructor selection table + + declareRunTimeSelectionTable + ( + autoPtr, + tableReader, + dictionary, + (const dictionary& dict), + (dict) + ); + + + // Constructors + + //- Construct from dictionary + tableReader(const dictionary& dict); + + //- Construct and return a clone + virtual autoPtr<tableReader<Type> > clone() const = 0; + + + // Selectors + + //- Return a reference to the selected tableReader + static autoPtr<tableReader> New(const dictionary& spec); + + + //- Destructor + + virtual ~tableReader(); + + + // Member functions + + //- Read the table + virtual void operator() + ( + const fileName&, + List<Tuple2<scalar, Type> >& + ) = 0; + + //- Write additional information + virtual void write(Ostream& os) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "tableReader.C" +#endif + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.C new file mode 100644 index 0000000000000000000000000000000000000000..a28c83218f3b8cd722b8e7ae418f75075385cd54 --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.C @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "tableReaders.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +#define defineTableReaderType(dataType) \ + defineNamedTemplateTypeNameAndDebug(tableReader<dataType >, 0); \ + defineTemplatedRunTimeSelectionTable(tableReader, dictionary, dataType); + +defineTableReaderType(scalar); +defineTableReaderType(vector); +defineTableReaderType(sphericalTensor); +defineTableReaderType(symmTensor); +defineTableReaderType(tensor); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.H b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.H new file mode 100644 index 0000000000000000000000000000000000000000..9507ac2bfb5ab9fbdd8b030515cc3257dd33d65f --- /dev/null +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/tableReaders.H @@ -0,0 +1,78 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::tableReader + +SourceFiles + tableReaders.C + +\*---------------------------------------------------------------------------*/ + +#ifndef tableReaders_H +#define tableReaders_H + +#include "tableReader.H" +#include "fieldTypes.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Only used internally +#define makeTypeTableReadersTypeName(typeTableReader, dataType) \ + \ + defineNamedTemplateTypeNameAndDebug(typeTableReader< dataType >, 0) + +// Sometimes used externally +#define makeTableReadersTypeName(typeTableReader) \ + \ + makeTypeTableReadersTypeName(typeTableReader, scalar); \ + makeTypeTableReadersTypeName(typeTableReader, vector); \ + makeTypeTableReadersTypeName(typeTableReader, sphericalTensor); \ + makeTypeTableReadersTypeName(typeTableReader, symmTensor); \ + makeTypeTableReadersTypeName(typeTableReader, tensor) + +// Define type info for single dataType template instantiation (eg, vector) +#define makeTableReaderType(typeTableReader, dataType) \ + \ + defineNamedTemplateTypeNameAndDebug(typeTableReader< dataType >, 0); \ + addTemplatedToRunTimeSelectionTable \ + ( \ + tableReader, typeTableReader, dataType, dictionary \ + ) + + +// Define type info for scalar, vector etc. instantiations +#define makeTableReaders(typeTableReader) \ + \ + makeTableReaderType(typeTableReader, scalar); \ + makeTableReaderType(typeTableReader, vector); \ + makeTableReaderType(typeTableReader, sphericalTensor); \ + makeTableReaderType(typeTableReader, symmTensor); \ + makeTableReaderType(typeTableReader, tensor) + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/Make/files b/src/sampling/Make/files index c9b26376d09db5931b086a32e7f8e0c41e76f3f5..ddf46a17e8516eec55d0cf81d4818598bcecb039 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -24,6 +24,7 @@ $(setWriters)/jplot/jplotSetWriterRunTime.C $(setWriters)/raw/rawSetWriterRunTime.C $(setWriters)/vtk/vtkSetWriterRunTime.C $(setWriters)/xmgrace/xmgraceSetWriterRunTime.C +$(setWriters)/csv/csvSetWriterRunTime.C cuttingPlane/cuttingPlane.C diff --git a/src/sampling/sampledSet/writers/csv/csvSetWriter.C b/src/sampling/sampledSet/writers/csv/csvSetWriter.C new file mode 100644 index 0000000000000000000000000000000000000000..c0b0b694ed7d94a9788f9c71c366b176e461a319 --- /dev/null +++ b/src/sampling/sampledSet/writers/csv/csvSetWriter.C @@ -0,0 +1,202 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "csvSetWriter.H" +#include "coordSet.H" +#include "fileName.H" +#include "OFstream.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Type> +Foam::csvSetWriter<Type>::csvSetWriter() +: + writer<Type>() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template<class Type> +Foam::csvSetWriter<Type>::~csvSetWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +Foam::fileName Foam::csvSetWriter<Type>::getFileName +( + const coordSet& points, + const wordList& valueSetNames +) const +{ + return this->getBaseName(points, valueSetNames) + ".csv"; +} + + +template<class Type> +void Foam::csvSetWriter<Type>::write +( + const coordSet& points, + const wordList& valueSetNames, + const List<const Field<Type>*>& valueSets, + Ostream& os +) const +{ + writeHeader(points,valueSetNames,os); + + // Collect sets into columns + List<const List<Type>*> columns(valueSets.size()); + + forAll(valueSets, i) + { + columns[i] = valueSets[i]; + } + + writeTable(points, columns, os); +} + + +template<class Type> +void Foam::csvSetWriter<Type>::write +( + const bool writeTracks, + const PtrList<coordSet>& points, + const wordList& valueSetNames, + const List<List<Field<Type> > >& valueSets, + Ostream& os +) const +{ + writeHeader(points[0],valueSetNames,os); + + if (valueSets.size() != valueSetNames.size()) + { + FatalErrorIn("csvSetWriter<Type>::write(..)") + << "Number of variables:" << valueSetNames.size() << endl + << "Number of valueSets:" << valueSets.size() + << exit(FatalError); + } + + List<const List<Type>*> columns(valueSets.size()); + + forAll(points, trackI) + { + // Collect sets into columns + forAll(valueSets, i) + { + columns[i] = &valueSets[i][trackI]; + } + + writeTable(points[trackI], columns, os); + os << nl << nl; + } +} + + +template<class Type> +void Foam::csvSetWriter<Type>::writeSeparator(Ostream& os) const +{ + os << token::COMMA; +} + + +namespace Foam +{ + // otherwise compiler complains about specialization + template<> + void csvSetWriter<scalar>::writeHeader + ( + const coordSet& points, + const wordList& valueSetNames, + Ostream& os + ) const + { + writeCoordHeader(points, os); + + forAll(valueSetNames, i) + { + if (i > 0) + { + writeSeparator(os); + } + os << valueSetNames[i]; + } + + os << nl; + } +} // end namespace + + +template<class Type> +void Foam::csvSetWriter<Type>::writeHeader +( + const coordSet& points, + const wordList& valueSetNames, + Ostream& os +) const +{ + writeCoordHeader(points, os); + + forAll(valueSetNames, i) + { + for (label j=0; j<Type::nComponents; j++) + { + if (i>0 || j>0) + { + writeSeparator(os); + } + os << valueSetNames[i] << "_" << j; + } + } + + os << nl; +} + + +template<class Type> +void Foam::csvSetWriter<Type>::writeCoordHeader +( + const coordSet& points, + Ostream& os +) const +{ + if (points.hasVectorAxis()) + { + forAll(points, i) + { + os << points.axis()[i]; + writeSeparator(os); + } + } + else + { + os << points.axis(); + writeSeparator(os); + } +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/csv/csvSetWriter.H b/src/sampling/sampledSet/writers/csv/csvSetWriter.H new file mode 100644 index 0000000000000000000000000000000000000000..04987fea2a5ea24a85629937dd48be7e1cf89bf2 --- /dev/null +++ b/src/sampling/sampledSet/writers/csv/csvSetWriter.H @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::csvSetWriter + +Description + +SourceFiles + csvSetWriter.C + +\*---------------------------------------------------------------------------*/ + +#ifndef csvSetWriter_H +#define csvSetWriter_H + +#include "writer.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class csvSetWriter Declaration +\*---------------------------------------------------------------------------*/ + +template<class Type> +class csvSetWriter +: + public writer<Type> +{ + + // Private Member Functions + + void writeCoordHeader(const coordSet&, Ostream&) const; + + void writeHeader(const coordSet&, const wordList&, Ostream&) const; + +protected: + + virtual void writeSeparator(Ostream&) const; + +public: + + //- Runtime type information + TypeName("csv"); + + + // Constructors + + //- Construct null + csvSetWriter(); + + + //- Destructor + + virtual ~csvSetWriter(); + + + // Member Functions + + virtual fileName getFileName + ( + const coordSet&, + const wordList& + ) const; + + virtual void write + ( + const coordSet&, + const wordList&, + const List<const Field<Type>*>&, + Ostream& + ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList<coordSet>&, + const wordList& valueSetNames, + const List<List<Field<Type> > >&, + Ostream& + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "csvSetWriter.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/csv/csvSetWriterRunTime.C b/src/sampling/sampledSet/writers/csv/csvSetWriterRunTime.C new file mode 100644 index 0000000000000000000000000000000000000000..2c22b5f227b070c83f2628756c7bb21dab277ed1 --- /dev/null +++ b/src/sampling/sampledSet/writers/csv/csvSetWriterRunTime.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "csvSetWriter.H" +#include "writers.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeSetWriters(csvSetWriter); +} + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/writer.C b/src/sampling/sampledSet/writers/writer.C index 651e0c7be247c7293d3440154cdd91909ca775d1..b2286998b47719a8816e002c4c2a19528d2ee990 100644 --- a/src/sampling/sampledSet/writers/writer.C +++ b/src/sampling/sampledSet/writers/writer.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -105,8 +105,7 @@ void Foam::writer<Type>::writeTable forAll(points, pointI) { writeCoord(points, pointI, os); - - os << token::SPACE; + writeSeparator(os); write(values[pointI], os); os << nl; } @@ -127,7 +126,8 @@ void Foam::writer<Type>::writeTable forAll(valuesPtrList, i) { - os << token::SPACE; + writeSeparator(os); + const List<Type>& values = *valuesPtrList[i]; write(values[pointI], os); } @@ -173,17 +173,27 @@ Foam::Ostream& Foam::writer<Type>::writeVS { for (direction d=0; d<VSType::nComponents; d++) { - os << value.component(d); - - if (d <= VSType::nComponents-1) + if (d > 0) { - os << ' ' << token::TAB; + writeSeparator(os); } + + os << value.component(d); } return os; } +template<class Type> +void Foam::writer<Type>::writeSeparator +( + Ostream& os +) const +{ + os << token::SPACE << token::TAB; +} + + template<class Type> Foam::Ostream& Foam::writer<Type>::write ( diff --git a/src/sampling/sampledSet/writers/writer.H b/src/sampling/sampledSet/writers/writer.H index f5d9a73e532647b721f4bd7da39f557584b97aaa..6fb810dc1f4b72a1d03b5aae6e95c5f27b4e1d0a 100644 --- a/src/sampling/sampledSet/writers/writer.H +++ b/src/sampling/sampledSet/writers/writer.H @@ -107,6 +107,8 @@ protected: Ostream& os ) const; + //- Writes a separator. Used by write functions. + virtual void writeSeparator(Ostream& os) const; public: