From e9e9dcbd085d83abc1a7030cd090690f1d0c2e49 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 22 Nov 2011 13:14:48 +0000 Subject: [PATCH] ENH: Refactored DataEntry table-types to make use of new table base class --- .../primitives/functions/DataEntry/CSV/CSV.C | 127 ++---------------- .../primitives/functions/DataEntry/CSV/CSV.H | 35 +++-- .../functions/DataEntry/CSV/CSVIO.C | 5 - .../functions/DataEntry/Table/Table.C | 105 +-------------- .../functions/DataEntry/Table/Table.H | 21 +-- .../functions/DataEntry/Table/TableBase.H | 4 +- .../functions/DataEntry/Table/TableIO.C | 19 +-- 7 files changed, 54 insertions(+), 262 deletions(-) diff --git a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C index ea992c10f6..3fe17d24a0 100644 --- a/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C +++ b/src/OpenFOAM/primitives/functions/DataEntry/CSV/CSV.C @@ -121,7 +121,7 @@ void Foam::CSV::read() values.append(Tuple2(x, value)); } - table_.transfer(values); + this->table_.transfer(values); } @@ -131,36 +131,25 @@ template Foam::CSV::CSV(const word& entryName, const dictionary& dict) : DataEntry(entryName), - headerLine_(false), - refColumn_(0), - componentColumns_(), - separator_(string(",")[0]), - fName_("none"), - table_() + TableBase(entryName, dict.subDict(type() + "Coeffs")), + coeffs_(dict.subDict(type() + "Coeffs")), + headerLine_(readBool(coeffs_.lookup("hasHeaderLine"))), + refColumn_(readLabel(coeffs_.lookup("refColumn"))), + componentColumns_(coeffs_.lookup("componentColumns")), + separator_(coeffs_.lookupOrDefault("separator", string(","))[0]), + fName_(coeffs_.lookup("fileName")) { - const dictionary coeffs(dict.subDict(type() + "Coeffs")); - coeffs.lookup("hasHeaderLine") >> headerLine_; - coeffs.lookup("refColumn") >> refColumn_; - coeffs.lookup("componentColumns") >> componentColumns_; - coeffs.readIfPresent("separator", string(separator_)[0]); - coeffs.lookup("fileName") >> fName_; - if (componentColumns_.size() != pTraits::nComponents) { FatalErrorIn("Foam::CSV::CSV(const word&, Istream&)") - << componentColumns_ << " does not have the expected length " + << componentColumns_ << " does not have the expected length of " << pTraits::nComponents << endl << exit(FatalError); } read(); - if (!table_.size()) - { - FatalErrorIn("Foam::CSV::CSV(const Istream&)") - << "CSV for entry " << this->name_ << " is invalid (empty)" - << nl << exit(FatalError); - } + TableBase::check(); } @@ -168,12 +157,12 @@ template Foam::CSV::CSV(const CSV& tbl) : DataEntry(tbl), + TableBase(tbl), headerLine_(tbl.headerLine_), refColumn_(tbl.refColumn_), componentColumns_(tbl.componentColumns_), separator_(tbl.separator_), - fName_(tbl.fName_), - table_(tbl.table_) + fName_(tbl.fName_) {} @@ -184,98 +173,6 @@ Foam::CSV::~CSV() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -Type Foam::CSV::value(const scalar x) const -{ - // Return zero if out of bounds - if (x < table_[0].first() || x > table_.last().first()) - { - return pTraits::zero; - } - - // Find i such that x(i) < x < x(i+1) - label i = 0; - while ((table_[i+1].first() < x) && (i+1 < table_.size())) - { - i++; - } - - // Linear interpolation to find value. Note constructor needed for - // CSV