ENH: csv reading for interpolationTable and writing for sampledSet

This commit is contained in:
mattijs
2011-04-26 19:25:00 +01:00
parent 0b6949098c
commit 6217691b4d
19 changed files with 1313 additions and 19 deletions

View File

@ -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

View File

@ -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);
}
}
// ************************************************************************* //

View File

@ -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
// ************************************************************************* //

View File

@ -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);
}
// ************************************************************************* //

View File

@ -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
(

View File

@ -107,6 +107,8 @@ protected:
Ostream& os
) const;
//- Writes a separator. Used by write functions.
virtual void writeSeparator(Ostream& os) const;
public: