Function1::TableReader: Added EmbeddedTableReader so that TableFile can read embedded table data

This commit is contained in:
Henry Weller
2020-11-16 21:01:41 +00:00
parent ba823900eb
commit 37ebdfe36e
23 changed files with 617 additions and 219 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -162,7 +162,8 @@ int main(int argc, char *argv[])
nfft -= pRef;
fileName baseFileName(pData.fName().lessExt());
fileName pDateFileName(dict.subDict("pressureData").lookup("file"));
fileName baseFileName(pDateFileName.lessExt());
graph Pf(nfft.RMSmeanPf(N, min(nfft.size()/N, nw)));
Info<< " Creating graph for " << Pf.title() << endl;

View File

@ -228,7 +228,15 @@ public:
defineNamedTemplateTypeNameAndDebug(Function1s::SS<Type>, 0); \
\
Function1<Type>::adddictionaryConstructorToTable<Function1s::SS<Type>> \
addFunction1##SS##Type##ConstructorToTable_;
addFunction1##SS##Type##ConstructorToTable_;
#define makeNamedFunction1Type(SS, Type, Name) \
\
defineNamedTemplateTypeNameAndDebug(Function1s::SS<Type>, 0); \
\
Function1<Type>::adddictionaryConstructorToTable<Function1s::SS<Type>> \
addFunction1##SS##Type##ConstructorToTable_(#Name);
#define makeScalarFunction1(SS) \

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -94,11 +94,13 @@ Foam::Function1s::Table<Type>::~Table()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1s::Table<Type>::writeEntries(Ostream& os) const
void Foam::Function1s::Table<Type>::writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const
{
TableBase<Type, Table<Type>>::writeEntries(os);
os << indent << "values" << this->table_
os << indent << "values" << table
<< token::END_STATEMENT << endl;
}

View File

@ -97,7 +97,11 @@ public:
// Member Functions
//- Write entries only in dictionary format
virtual void writeEntries(Ostream& os) const;
virtual void writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
// Member Operators

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "TableBase.H"
#include "Time.H"
#include "linearInterpolationWeights.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -300,11 +299,17 @@ Foam::Function1s::TableBase<Type, Function1Type>::y() const
template<class Type, class Function1Type>
void Foam::Function1s::TableBase<Type, Function1Type>::writeEntries
void Foam::Function1s::TableBase<Type, Function1Type>::writeData
(
Ostream& os
) const
{
Function1<Type>::writeData(os);
os << token::END_STATEMENT << nl;
os << indent << word(this->name() + "Coeffs") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
writeEntryIfDifferent
(
os,
@ -320,21 +325,9 @@ void Foam::Function1s::TableBase<Type, Function1Type>::writeEntries
linearInterpolationWeights::typeName,
interpolationScheme_
);
}
writeEntries(os, table_);
template<class Type, class Function1Type>
void Foam::Function1s::TableBase<Type, Function1Type>::writeData
(
Ostream& os
) const
{
Function1<Type>::writeData(os);
os << token::END_STATEMENT << nl;
os << indent << word(this->name() + "Coeffs") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
writeEntries(os);
os << decrIndent << indent << token::END_BLOCK << endl;
}

View File

@ -37,7 +37,6 @@ SourceFiles
#include "tableBase.H"
#include "Function1.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -141,7 +140,11 @@ public:
virtual tmp<Field<Type>> y() const;
//- Write entries only in dictionary format
virtual void writeEntries(Ostream& os) const;
virtual void writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const = 0;
//- Write all table data in dictionary format
virtual void writeData(Ostream& os) const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -30,27 +30,13 @@ License
template<class Type>
Foam::Function1s::TableFile<Type>::TableFile
(
const word& entryName,
const word& name,
const dictionary& dict
)
:
TableBase<Type, TableFile<Type>>(entryName, dict),
fName_(dict.lookup("file")),
reader_
(
TableReader<Type>::New
(
dict.lookupOrDefault<word>
(
"format",
TableReaders::Foam<Type>::typeName
),
dict
)
)
TableBase<Type, TableFile<Type>>(name, dict),
reader_(TableReader<Type>::New(name, dict, this->table_))
{
reader_()(fName_, this->table_);
TableBase<Type, TableFile<Type>>::check();
}
@ -59,7 +45,6 @@ template<class Type>
Foam::Function1s::TableFile<Type>::TableFile(const TableFile<Type>& tbl)
:
TableBase<Type, TableFile<Type>>(tbl),
fName_(tbl.fName_),
reader_(tbl.reader_, false)
{}
@ -74,13 +59,13 @@ Foam::Function1s::TableFile<Type>::~TableFile()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1s::TableFile<Type>::writeEntries(Ostream& os) const
void Foam::Function1s::TableFile<Type>::writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const
{
TableBase<Type, TableFile<Type>>::writeEntries(os);
writeEntry(os, "file", fName_);
writeEntry(os, "format", reader_->type());
reader_->write(os);
reader_->write(os, table);
}

View File

@ -75,9 +75,6 @@ class TableFile
{
// Private Data
//- File name for table
const fileName fName_;
//- Table reader
const autoPtr<TableReader<Type>> reader_;
@ -101,19 +98,14 @@ public:
virtual ~TableFile();
// Access
//- Return the file name
inline const fileName& fName() const
{
return fName_;
}
// I/O
//- Write entries only in dictionary format
virtual void writeEntries(Ostream& os) const;
virtual void writeEntries
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
// Member Operators

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -198,23 +198,17 @@ void Foam::TableReaders::Csv<Type>::read
}
template<class Type>
void Foam::TableReaders::Csv<Type>::read
(
ISstream&,
List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>& data
) const
{
NotImplemented;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::TableReaders::Csv<Type>::Csv(const dictionary& dict)
Foam::TableReaders::Csv<Type>::Csv
(
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
)
:
TableReader<Type>(dict),
TableFileReader<Type>(dict),
nHeaderLine_(dict.lookup<label>("nHeaderLine")),
refColumn_(dict.lookup<label>("refColumn")),
componentColumns_(dict.lookup("componentColumns")),
@ -228,6 +222,8 @@ Foam::TableReaders::Csv<Type>::Csv(const dictionary& dict)
<< pTraits<Type>::nComponents << endl
<< exit(FatalError);
}
TableFileReader<Type>::read(dict, table);
}
@ -238,10 +234,16 @@ Foam::TableReaders::Csv<Type>::~Csv()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::TableReaders::Csv<Type>::write(Ostream& os) const
void Foam::TableReaders::Csv<Type>::write
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const
{
TableReader<Type>::write(os);
TableFileReader<Type>::write(os);
writeEntry(os, "nHeaderLine", nHeaderLine_);
writeEntry(os, "refColumn", refColumn_);

View File

@ -48,7 +48,7 @@ SourceFiles
#ifndef CsvTableReader_H
#define CsvTableReader_H
#include "TableReader.H"
#include "TableFileReader.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -65,7 +65,7 @@ namespace TableReaders
template<class Type>
class Csv
:
public TableReader<Type>
public TableFileReader<Type>
{
// Private Data
@ -93,13 +93,6 @@ class Csv
//- Read a 1D table
virtual void read(ISstream&, List<Tuple2<scalar, Type>>&) const;
//- Read a 2D table
virtual void read
(
ISstream&,
List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>&
) const;
public:
@ -110,7 +103,12 @@ public:
// Constructors
//- Construct from dictionary
Csv(const dictionary& dict);
Csv
(
const word& name,
const dictionary &dict,
List<Tuple2<scalar, Type>>& table
);
//- Construct and return a copy
virtual autoPtr<TableReader<Type>> clone() const
@ -125,8 +123,12 @@ public:
// Member Functions
//- Write the remaining parameters
virtual void write(Ostream& os) const;
//- Write the CSV parameters
virtual void write
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
};

View File

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\/ 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 "EmbeddedTableReader.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::TableReaders::Embedded<Type>::Embedded
(
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
)
:
TableReader<Type>(dict)
{
if (!dict.found(name))
{
dict.lookup("values") >> table;
}
else
{
Istream& is(dict.lookup(name));
word entryType(is);
if (is.eof())
{
dict.lookup("values") >> table;
}
else
{
is >> table;
}
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::TableReaders::Embedded<Type>::~Embedded()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::TableReaders::Embedded<Type>::write
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const
{
os << indent << "values" << table
<< token::END_STATEMENT << endl;
}
// ************************************************************************* //

View File

@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\/ 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::TableReaders::Embedded
Description
Reads an interpolation table from the \c values entry in OpenFOAM-format.
This is a list of Tuple2's where the first (x) column is scalar, and the
second (y) column is the type to be interpolated.
Usage:
\verbatim
values
(
(0.0 (1 2 3))
(1.0 (4 5 6))
);
\endverbatim
SourceFiles
Embedded.C
\*---------------------------------------------------------------------------*/
#ifndef EmbeddedTableReader_H
#define EmbeddedTableReader_H
#include "TableReader.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace TableReaders
{
/*---------------------------------------------------------------------------*\
Class Foam Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Embedded
:
public TableReader<Type>
{
public:
//- Runtime type information
TypeName("embedded");
// Constructors
//- Construct from dictionary
Embedded
(
const word& name,
const dictionary &dict,
List<Tuple2<scalar, Type>>& table
);
//- Construct and return a copy
virtual autoPtr<TableReader<Type>> clone() const
{
return autoPtr<TableReader<Type>>(new Embedded<Type>(*this));
}
//- Destructor
virtual ~Embedded();
// Member Functions
//- Write the table values
virtual void write
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace TableReaders
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "EmbeddedTableReader.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -38,24 +38,20 @@ void Foam::TableReaders::Foam<Type>::read
}
template<class Type>
void Foam::TableReaders::Foam<Type>::read
(
ISstream& is,
List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>& data
) const
{
is >> data;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::TableReaders::Foam<Type>::Foam(const dictionary& dict)
Foam::TableReaders::Foam<Type>::Foam
(
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
)
:
TableReader<Type>(dict)
{}
TableFileReader<Type>(dict)
{
TableFileReader<Type>::read(dict, table);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

View File

@ -45,7 +45,7 @@ SourceFiles
#ifndef FoamTableReader_H
#define FoamTableReader_H
#include "TableReader.H"
#include "TableFileReader.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -61,19 +61,13 @@ namespace TableReaders
template<class Type>
class Foam
:
public TableReader<Type>
public TableFileReader<Type>
{
// Private Member Functions
//- Read a 1D table
virtual void read(ISstream&, List<Tuple2<scalar, Type>> &) const;
//- Read a 2D table
virtual void read
(
ISstream&,
List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>&
) const;
public:
@ -84,7 +78,12 @@ public:
// Constructors
//- Construct from dictionary
Foam(const dictionary &dict);
Foam
(
const word& name,
const dictionary &dict,
List<Tuple2<scalar, Type>>& table
);
//- Construct and return a copy
virtual autoPtr<TableReader<Type>> clone() const

View File

@ -0,0 +1,95 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ 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 "TableFileReader.H"
#include "fileOperation.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<class Type>
void Foam::TableFileReader<Type>::read
(
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
) const
{
// Expand the file
fileName fNameExpanded(fName_);
fNameExpanded.expand();
// Open a stream and check it
autoPtr<ISstream> isPtr(fileHandler().NewIFstream(fNameExpanded));
ISstream& is = isPtr();
if (!is.good())
{
FatalIOErrorInFunction(is)
<< "Cannot open file" << fName_ << nl
<< exit(FatalIOError);
}
// Read data from the stream
read(is, table);
// Check something was read
if (table.empty())
{
FatalIOErrorInFunction(is)
<< "Table read from " << fName_ << " is empty" << nl
<< exit(FatalIOError);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::TableFileReader<Type>::TableFileReader
(
const dictionary& dict
)
:
TableReader<Type>(dict),
fName_(dict.lookup("file"))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::TableFileReader<Type>::~TableFileReader()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::TableFileReader<Type>::write(Ostream& os) const
{
writeEntry(os, "format", this->type());
writeEntry(os, "file", fName_);
}
// ************************************************************************* //

View File

@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\/ 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::TableFileReader
Description
Base class to read table data for tables
SourceFiles
TableFileReader.C
\*---------------------------------------------------------------------------*/
#ifndef TableFileReader_H
#define TableFileReader_H
#include "TableReader.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class TableFileReader Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class TableFileReader
:
public TableReader<Type>
{
// Private Data
//- File name for table
const fileName fName_;
// Private Member Functions
//- Read a 1D table
virtual void read(ISstream&, List<Tuple2<scalar, Type>>&) const = 0;
protected:
//- Read a 1D table
void read(const dictionary& dict, List<Tuple2<scalar, Type>>&) const;
public:
// Constructors
//- Construct from dictionary
TableFileReader(const dictionary& dict);
//- Destructor
virtual ~TableFileReader();
// Member Functions
//- Write additional information
virtual void write(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "TableFileReader.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,38 +24,11 @@ License
\*---------------------------------------------------------------------------*/
#include "TableReader.H"
#include "fileOperation.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New
(
const word& readerType,
const dictionary& dict
)
{
typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(readerType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown reader type " << readerType
<< nl << nl
<< "Valid reader types : " << nl
<< dictionaryConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<TableReader<Type>>(cstrIter()(dict));
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::TableReader<Type>::TableReader(const dictionary&)
Foam::TableReader<Type>::TableReader(const dictionary& dict)
{}
@ -69,45 +42,12 @@ Foam::TableReader<Type>::~TableReader()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::TableReader<Type>::write(Ostream& os) const
void Foam::TableReader<Type>::write
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
template<class TableType>
void Foam::TableReader<Type>::operator()
(
const fileName& fName,
TableType& data
) const
{
// Expand the file
fileName fNameExpanded(fName);
fNameExpanded.expand();
// Open a stream and check it
autoPtr<ISstream> isPtr(fileHandler().NewIFstream(fNameExpanded));
ISstream& is = isPtr();
if (!is.good())
{
FatalIOErrorInFunction(is)
<< "Cannot open file" << fName << nl
<< exit(FatalIOError);
}
// Read data from the stream
read(is, data);
// Check something was read
if (data.empty())
{
FatalIOErrorInFunction(is)
<< "Table read from " << fName << " is empty" << nl
<< exit(FatalIOError);
}
}
// ************************************************************************* //

View File

@ -36,9 +36,6 @@ SourceFiles
#define TableReader_H
#include "dictionary.H"
#include "fieldTypes.H"
#include "runTimeSelectionTables.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -52,30 +49,13 @@ namespace Foam
template<class Type>
class TableReader
{
private:
// Private Member Functions
//- Read a 1D table
virtual void read
(
ISstream&,
List<Tuple2<scalar, Type>>&
) const = 0;
//- Read a 2D table
virtual void read
(
ISstream&,
List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>&
) const = 0;
public:
//- Runtime type information
TypeName("TableReader");
// Declare run-time constructor selection table
declareRunTimeSelectionTable
@ -83,8 +63,12 @@ public:
autoPtr,
TableReader,
dictionary,
(const dictionary& dict),
(dict)
(
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
),
(name, dict, table)
);
@ -100,8 +84,9 @@ public:
// Selector
static autoPtr<TableReader<Type>> New
(
const word& readerType,
const dictionary& dict
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
);
@ -111,12 +96,12 @@ public:
// Member Functions
//- Read a table
template<class TableType>
void operator()(const fileName&, TableType&) const;
//- Write additional information
virtual void write(Ostream& os) const;
virtual void write
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
};
@ -142,6 +127,7 @@ public:
#define makeTableReaders(Type) \
defineTableReader(Type); \
makeTableReader(Embedded, Type); \
makeTableReader(Foam, Type); \
makeTableReader(Csv, Type)
@ -150,7 +136,7 @@ public:
#ifdef NoRepository
#include "TableReader.C"
#include "FoamTableReader.H"
#include "TableReaderNew.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,78 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\/ 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 "EmbeddedTableReader.H"
#include "FoamTableReader.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::TableReader<Type>> Foam::TableReader<Type>::New
(
const word& name,
const dictionary& dict,
List<Tuple2<scalar, Type>>& table
)
{
if (dict.found("format"))
{
const word readerType(dict.lookup("format"));
typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(readerType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown reader type " << readerType
<< nl << nl
<< "Valid reader types : " << nl
<< dictionaryConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<TableReader<Type>>(cstrIter()(name, dict, table));
}
else
{
if (dict.found("file"))
{
return autoPtr<TableReader<Type>>
(
new TableReaders::Foam<Type>(name, dict, table)
);
}
else
{
return autoPtr<TableReader<Type>>
(
new TableReaders::Embedded<Type>(name, dict, table)
);
}
}
}
// ************************************************************************* //

View File

@ -23,10 +23,10 @@ License
\*---------------------------------------------------------------------------*/
#include "TableReader.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "CsvTableReader.H"
#include "fieldTypes.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -57,6 +57,7 @@ namespace solidBodyMotionFunctions
#include "Square.H"
#include "Table.H"
#include "TableFile.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "Scale.H"
#include "CodedFunction1.H"
@ -102,6 +103,7 @@ namespace Foam
makeFunction1s(trvType);
defineTableReader(trvType);
makeTableReader(Embedded, trvType);
makeTableReader(Foam, trvType);
}

View File

@ -56,6 +56,7 @@ namespace fv
#include "Square.H"
#include "Table.H"
#include "TableFile.H"
#include "EmbeddedTableReader.H"
#include "FoamTableReader.H"
#include "Scale.H"
#include "CodedFunction1.H"
@ -98,6 +99,7 @@ namespace Foam
makeFunction1s(avType);
defineTableReader(avType);
makeTableReader(Embedded, avType);
makeTableReader(Foam, avType);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -212,7 +212,7 @@ void Foam::sixDoFRigidBodyMotionRestraints::tabulatedAxialAngularSpring::write
writeEntry(os, "axis", axis_);
moment_->writeEntries(os);
moment_->writeData(os);
writeKeyword(os, "angleFormat");