2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2018-05-29 07:35:20 +00:00
|
|
|
\\ / O peration | Version: 4.1
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend 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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "writeFuns.H"
|
|
|
|
#include "vtkTopo.H"
|
|
|
|
|
|
|
|
#if defined(__mips) && !defined(__SICORTEX__)
|
|
|
|
#include <standards.h>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// MacOSX
|
|
|
|
#ifdef __DARWIN_BYTE_ORDER
|
|
|
|
#if __DARWIN_BYTE_ORDER==__DARWIN_BIG_ENDIAN
|
|
|
|
#undef LITTLE_ENDIAN
|
|
|
|
#else
|
|
|
|
#undef BIG_ENDIAN
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LITTLE_ENDIAN) \
|
|
|
|
|| defined(_LITTLE_ENDIAN) \
|
|
|
|
|| defined(__LITTLE_ENDIAN)
|
|
|
|
# define LITTLEENDIAN 1
|
|
|
|
#elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
|
|
|
|
# undef LITTLEENDIAN
|
|
|
|
#else
|
|
|
|
# error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
|
|
|
|
# error "Please add to compilation options"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
2019-01-05 01:14:17 +00:00
|
|
|
void Foam::writeFuns::swapWord(int32_t& word32)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
char* mem = reinterpret_cast<char*>(&word32);
|
|
|
|
|
|
|
|
char a = mem[0];
|
|
|
|
mem[0] = mem[3];
|
|
|
|
mem[3] = a;
|
|
|
|
|
|
|
|
a = mem[1];
|
|
|
|
mem[1] = mem[2];
|
|
|
|
mem[2] = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-05 01:14:17 +00:00
|
|
|
void Foam::writeFuns::swapWords(const label nWords, int32_t* words32)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
for (label i = 0; i < nWords; i++)
|
|
|
|
{
|
|
|
|
swapWord(words32[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::write
|
|
|
|
(
|
|
|
|
std::ostream& os,
|
|
|
|
const bool binary,
|
|
|
|
List<floatScalar>& fField
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (binary)
|
|
|
|
{
|
2019-01-05 01:14:17 +00:00
|
|
|
#ifdef LITTLEENDIAN
|
|
|
|
swapWords(fField.size(), reinterpret_cast<int32_t*>(fField.begin()));
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
os.write
|
|
|
|
(
|
|
|
|
reinterpret_cast<char*>(fField.begin()),
|
|
|
|
fField.size()*sizeof(float)
|
|
|
|
);
|
|
|
|
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forAll(fField, i)
|
|
|
|
{
|
|
|
|
os << fField[i] << ' ';
|
|
|
|
|
|
|
|
if (i > 0 && (i % 10) == 0)
|
|
|
|
{
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::write
|
|
|
|
(
|
|
|
|
std::ostream& os,
|
|
|
|
const bool binary,
|
|
|
|
DynamicList<floatScalar>& fField
|
|
|
|
)
|
|
|
|
{
|
|
|
|
List<floatScalar>& fld = fField.shrink();
|
|
|
|
|
|
|
|
write(os, binary, fld);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::write
|
|
|
|
(
|
|
|
|
std::ostream& os,
|
|
|
|
const bool binary,
|
|
|
|
labelList& elems
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (binary)
|
|
|
|
{
|
2019-01-05 01:14:17 +00:00
|
|
|
#ifdef LITTLEENDIAN
|
|
|
|
swapWords
|
|
|
|
(
|
|
|
|
(sizeof(label)/4)*elems.size(),
|
|
|
|
reinterpret_cast<int32_t*>(elems.begin())
|
|
|
|
);
|
|
|
|
#endif
|
2010-05-12 13:27:55 +00:00
|
|
|
os.write
|
|
|
|
(
|
|
|
|
reinterpret_cast<char*>(elems.begin()),
|
|
|
|
elems.size()*sizeof(label)
|
|
|
|
);
|
|
|
|
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forAll(elems, i)
|
|
|
|
{
|
|
|
|
os << elems[i] << ' ';
|
|
|
|
|
|
|
|
if (i > 0 && (i % 10) == 0)
|
|
|
|
{
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::write
|
|
|
|
(
|
|
|
|
std::ostream& os,
|
|
|
|
const bool binary,
|
2019-02-01 12:36:12 +00:00
|
|
|
dynamicLabelList& elems
|
2010-05-12 13:27:55 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
labelList& fld = elems.shrink();
|
|
|
|
|
|
|
|
write(os, binary, fld);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::writeHeader
|
|
|
|
(
|
|
|
|
std::ostream& os,
|
|
|
|
const bool binary,
|
|
|
|
const string& name
|
|
|
|
)
|
|
|
|
{
|
|
|
|
os << "# vtk DataFile Version 2.0" << std::endl
|
|
|
|
<< name << std::endl;
|
|
|
|
|
|
|
|
if (binary)
|
|
|
|
{
|
|
|
|
os << "BINARY" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
os << "ASCII" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::writeCellDataHeader
|
|
|
|
(
|
|
|
|
std::ostream& os,
|
|
|
|
const label nCells,
|
|
|
|
const label nFields
|
|
|
|
)
|
|
|
|
{
|
|
|
|
os << "CELL_DATA " << nCells << std::endl
|
|
|
|
<< "FIELD attributes " << nFields << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::writePointDataHeader
|
|
|
|
(
|
|
|
|
std::ostream& os,
|
|
|
|
const label nPoints,
|
|
|
|
const label nFields
|
|
|
|
)
|
|
|
|
{
|
|
|
|
os << "POINT_DATA " << nPoints << std::endl
|
|
|
|
<< "FIELD attributes " << nFields << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::insert(const scalar& pt, DynamicList<floatScalar>& dest)
|
|
|
|
{
|
|
|
|
dest.append(float(pt));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::insert(const vector& pt, DynamicList<floatScalar>& dest)
|
|
|
|
{
|
|
|
|
for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++)
|
|
|
|
{
|
|
|
|
dest.append(float(pt[cmpt]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::insert
|
|
|
|
(
|
|
|
|
const sphericalTensor& pt,
|
|
|
|
DynamicList<floatScalar>& dest
|
|
|
|
)
|
|
|
|
{
|
|
|
|
for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; cmpt++)
|
|
|
|
{
|
|
|
|
dest.append(float(pt[cmpt]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::insert
|
|
|
|
(
|
|
|
|
const symmTensor& pt,
|
|
|
|
DynamicList<floatScalar>& dest
|
|
|
|
)
|
|
|
|
{
|
|
|
|
for (direction cmpt = 0; cmpt < symmTensor::nComponents; cmpt++)
|
|
|
|
{
|
|
|
|
dest.append(float(pt[cmpt]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::writeFuns::insert(const tensor& pt, DynamicList<floatScalar>& dest)
|
|
|
|
{
|
|
|
|
for (direction cmpt = 0; cmpt < tensor::nComponents; cmpt++)
|
|
|
|
{
|
|
|
|
dest.append(float(pt[cmpt]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-01 12:36:12 +00:00
|
|
|
void Foam::writeFuns::insert(const labelList& source, dynamicLabelList& dest)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
forAll(source, i)
|
|
|
|
{
|
|
|
|
dest.append(source[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|