1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "writeFuns.H"
29 #if defined(__mips) && !defined(__SICORTEX__)
30 #include <standards.h>
31 #include <sys/endian.h>
35 #ifdef __DARWIN_BYTE_ORDER
36 #if __DARWIN_BYTE_ORDER==__DARWIN_BIG_ENDIAN
43 #if defined(LITTLE_ENDIAN) \
44 || defined(_LITTLE_ENDIAN) \
45 || defined(__LITTLE_ENDIAN)
46 # define LITTLEENDIAN 1
47 #elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
50 # error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
51 # error "Please add to compilation options"
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 void Foam::writeFuns::swapWord(label& word32)
58 char* mem = reinterpret_cast<char*>(&word32);
70 void Foam::writeFuns::swapWords(const label nWords, label* words32)
72 for (label i = 0; i < nWords; i++)
79 void Foam::writeFuns::write
83 List<floatScalar>& fField
89 swapWords(fField.size(), reinterpret_cast<label*>(fField.begin()));
93 reinterpret_cast<char*>(fField.begin()),
94 fField.size()*sizeof(float)
105 if (i > 0 && (i % 10) == 0)
119 void Foam::writeFuns::write
123 DynamicList<floatScalar>& fField
126 List<floatScalar>& fld = fField.shrink();
128 write(os, binary, fld);
132 void Foam::writeFuns::write
142 swapWords(elems.size(), reinterpret_cast<label*>(elems.begin()));
146 reinterpret_cast<char*>(elems.begin()),
147 elems.size()*sizeof(label)
158 if (i > 0 && (i % 10) == 0)
172 void Foam::writeFuns::write
176 DynamicList<label>& elems
179 labelList& fld = elems.shrink();
181 write(os, binary, fld);
185 void Foam::writeFuns::writeHeader
189 const std::string& title
192 os << "# vtk DataFile Version 2.0" << std::endl
193 << title << std::endl;
197 os << "BINARY" << std::endl;
201 os << "ASCII" << std::endl;
206 void Foam::writeFuns::writeCellDataHeader
213 os << "CELL_DATA " << nCells << std::endl
214 << "FIELD attributes " << nFields << std::endl;
218 void Foam::writeFuns::writePointDataHeader
225 os << "POINT_DATA " << nPoints << std::endl
226 << "FIELD attributes " << nFields << std::endl;
230 void Foam::writeFuns::insert(const scalar src, DynamicList<floatScalar>& dest)
232 dest.append(float(src));
236 void Foam::writeFuns::insert(const vector& src, DynamicList<floatScalar>& dest)
238 for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
240 dest.append(float(src[cmpt]));
245 void Foam::writeFuns::insert
247 const sphericalTensor& src,
248 DynamicList<floatScalar>& dest
251 for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; ++cmpt)
253 dest.append(float(src[cmpt]));
258 void Foam::writeFuns::insert
260 const symmTensor& src,
261 DynamicList<floatScalar>& dest
264 dest.append(float(src.xx()));
265 dest.append(float(src.yy()));
266 dest.append(float(src.zz()));
267 dest.append(float(src.xy()));
268 dest.append(float(src.yz()));
269 dest.append(float(src.xz()));
273 void Foam::writeFuns::insert(const tensor& src, DynamicList<floatScalar>& dest)
275 for (direction cmpt = 0; cmpt < tensor::nComponents; ++cmpt)
277 dest.append(float(src[cmpt]));
282 void Foam::writeFuns::insert(const labelList& src, DynamicList<label>& dest)
288 // ************************************************************************* //